Skip to content

Instantly share code, notes, and snippets.

@wbzyl
Created January 12, 2012 14:12
Show Gist options
  • Save wbzyl/1600728 to your computer and use it in GitHub Desktop.
Save wbzyl/1600728 to your computer and use it in GitHub Desktop.
Tire: percolate bug
# -*- coding: utf-8 -*-
require 'tire'
# Let's define a class to hold our data in *ElasticSearch*.
class Status
include Tire::Model::Persistence
property :text
on_percolate do
puts "'#{text}' matches queries: #{matches.inspect}" unless matches.empty?
end
end
# First, let's define the *query_string* queries.
q = {}
q[:newspeak] = 'wow omg lol wtf fuu*'
q[:memes] = '"why u no" "all your base" "i can has"'
# Second, let's register the queries for percolation.
Status.index.register_percolator_query('newspeak') { |query| query.string q[:newspeak] }
Status.index.register_percolator_query('memes') { |query| query.string q[:memes] }
status1 = Status.new :text => 'OMG i can has'
puts "'#{status1.text}' matches queries #{status1.percolate.inspect}"
status1.save
puts "'#{status1.text}' matches queries #{status1.percolate.inspect}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment