Module: Elasticrepo::Indexer

Defined in:
lib/elasticrepo/indexer.rb

Constant Summary collapse

INDEX =
'repositories'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.starred(owner) ⇒ Object

given a user, extract his starred repositories, then index the list with Tire

GET /users/:user/starred developer.github.com/v3/repos/#list-user-repositories



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/elasticrepo/indexer.rb', line 10

def self.starred(owner)
  repos = Elasticrepo::Extractor.repos(owner)
  # index the extraction
  #
  Tire::Index.new(INDEX) do
    # Import documents
    #
    import repos
    # Refresh the index for immediate searching
    #
    refresh
  end 
end

Instance Method Details

#deleteObject



57
58
59
60
61
# File 'lib/elasticrepo/indexer.rb', line 57

def delete
  # delete 'repositories' index
  #
  Tire::Index.new(INDEX).delete
end

#updateObject

create :mappings => {

    :question => {
      :properties => {
        :id => { :type => 'integer', :analyzer => 'keyword' },
        :owner => { :type => 'string', :analyzer => 'keyword' },
        :name => { :type => 'string', :analyzer => 'keyword' },
        #:full_name => { :type => 'string', :analyzer => 'keyword' },
        :url => { :type => 'string', :analyzer => 'snowball' },
        :description => { :type => 'string', :analyzer => 'snowball' },
        :organization => { :type => 'string', :analyzer => 'keyword' },
        :language => { :type => 'string', :analyzer => 'keyword' },
        :created_at => { :type => 'date', :analyzer => 'keyword' },
        :pushed_at => { :type => 'date', :analyzer => 'keyword' },
        :updated_at => { :type => 'date', :analyzer => 'keyword' }
      }
    }
  }  
  import repos
  refresh
end

end # end import



51
52
53
54
55
# File 'lib/elasticrepo/indexer.rb', line 51

def update
  # Just refresh the index as is 
  #
  Tire::Index.new(INDEX).refresh
end