Module: Tire::Model::Percolate::ClassMethods
- Included in:
- Search::ClassMethodsProxy
- Defined in:
- lib/tire/model/percolate.rb
Instance Method Summary collapse
-
#on_percolate(pattern = true, &block) ⇒ Object
A callback method for intercepting percolator matches.
-
#percolate!(pattern = true) ⇒ Object
Set up the percolation when documents are being added to the index.
-
#percolator ⇒ Object
Returns the status or pattern of percolator for this class.
Instance Method Details
#on_percolate(pattern = true, &block) ⇒ Object
A callback method for intercepting percolator matches.
Usage:
class Article
# ...
on_percolate do
puts "Article title “#{title}” matches queries: #{matches.inspect}" unless matches.empty?
end
end
Based on the response received in matches
, you may choose to fire notifications,
increment counters, send out e-mail alerts, etc.
52 53 54 55 |
# File 'lib/tire/model/percolate.rb', line 52 def on_percolate(pattern=true,&block) percolate!(pattern) klass.after_update_elasticsearch_index(block) end |
#percolate!(pattern = true) ⇒ Object
Set up the percolation when documents are being added to the index.
Usage:
class Article
# ...
percolate!
end
First, you have to register a percolator query:
Article.index.register_percolator_query('fail') { |query| query.string 'fail' }
Then, when you update the index, matching queries are returned in the matches
property:
p Article.create(:title => 'This is a FAIL!').matches
You may pass a pattern to filter which percolator queries will be executed.
See http://www.elasticsearch.org/guide/reference/api/index_.html for more information.
33 34 35 36 |
# File 'lib/tire/model/percolate.rb', line 33 def percolate!(pattern=true) @_percolator = pattern self end |
#percolator ⇒ Object
Returns the status or pattern of percolator for this class.
59 60 61 |
# File 'lib/tire/model/percolate.rb', line 59 def percolator @_percolator end |