Module: ElasticRecord::PercolatorModel::ClassMethods
- Defined in:
- lib/elastic_record/percolator_model.rb
Instance Method Summary collapse
Instance Method Details
#doctype ⇒ Object
22 23 24 |
# File 'lib/elastic_record/percolator_model.rb', line 22 def doctype @doctype ||= Doctype.percolator_doctype end |
#elastic_index ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/elastic_record/percolator_model.rb', line 13 def elastic_index @elastic_index ||= begin index = ElasticRecord::Index.new([self, percolates_model]) index.partial_updates = false index end end |
#percolate(document) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/elastic_record/percolator_model.rb', line 26 def percolate(document) query = { "query" => { "percolate" => { "field" => "query", "document_type" => percolates_model.doctype.name, "document" => document } }, "size" => 1000 } hits = elastic_index.search(query)['hits']['hits'] ids = hits.map { |hits| hits['_id'] } where(id: ids) end |