0

I'm exploring various options for a search engine for our rails-app/data. I was able to make sunspot/solr work and am currently exploring ElasticSearch as an alternative but couldn't get the same thing(scoping/filtering) to work under ES.

I would like to filter/scope objects as described in the "Scoping" section in 'https://github.com/sunspot/sunspot'.

I have an active record class 'Product'.

class Product < ActiveRecord::Base
...

  include Tire::Model::Search
  include Tire::Model::Callbacks

  tire.mapping do
    indexes :name, :type => :string
    indexes :categories do
      indexes :id, :type => :integer
    end
  end
end

Once I imported products into ES,

the following query works and gives results

Product.tire.search { query { string '*', default_operator: "AND", default_field: "name" } }.results

How do I get products of a particular category given a category id ?

Product.tire.search { query { string '*', default_operator: "AND", default_field: "name" }; filter(:term, 'categories.id' => 38) }.results

I'm basically looking for the tire equivalent for the following sunspot call:

Product.search do
  with(:category_ids, 38)
end

with the following in the Product class

searchable :auto_index => true, :auto_remove => true do
  text :name

  integer :category_ids, :multiple => true do
     self.categories.map &:id
  end

end
letronje
  • 9,002
  • 9
  • 45
  • 53
  • I can't speak authoritatively to Tire's syntax, but the `with` operator in Sunspot is a filter query. I would think your `filter` on the Tire query comes close. Let us know if some experimentation gets you to the right answer. – Nick Zadrozny Jan 30 '13 at 17:52
  • The sunspot dsl makes it easy to flatten associations. The tire examples I've seen so far use a dotted notation for filtering ('categories.id') by association attributes. – letronje Jan 31 '13 at 03:54
  • Did you ever find a clear answer for this? – lebreeze May 26 '13 at 09:56
  • nope. we flattened association attributes and indexed them instead. – letronje May 27 '13 at 16:01

0 Answers0