0
votes

Is there anyway of defining facet on an associated model's column which is of type int?Does sphinx convert all fields defined as facets to strings if they are of an associated models columns?

I am trying to define a column of my child table as an facet.After rebuilding when I do Model1.facets i get this error.

class Model1 < ActiveRecord::Base
  ....

  has_many :communities, :through => :model2

  ...

  define indexes

     ...

     indexes model2.community_id, :as => :community_id, :facet => :true

     ...

  end

end

model 1 - Current model model 2 - join model using :through

Model1.facets

NoMethodError: undefined method `to_crc32' for 9:Fixnum
        from D:/Current/TechAssistTest/vendor/plugins/thinking-sphinx/
lib/thinking_sphinx/facet.rb:99:in `translate'
        from (irb):3:in `detect'
        from D:/Current/TechAssistTest/vendor/plugins/thinking-sphinx/
lib/thinking_sphinx/facet.rb:98:in `each'
        from D:/Current/TechAssistTest/vendor/plugins/thinking-sphinx/
lib/thinking_sphinx/facet.rb:98:in `detect'
        from D:/Current/TechAssistTest/vendor/plugins/thinking-sphinx/
lib/thinking_sphinx/facet.rb:98:in `translate'
        from D:/Current/TechAssistTest/vendor/plugins/thinking-sphinx/
lib/thinking_sphinx/facet.rb:75:in `value'
        from D:/Current/TechAssistTest/vendor/plugins/thinking-sphinx/
lib/thinking_sphinx/facet_search.rb:114:in `add_from_results'
        from D:/Current/TechAssistTest/vendor/plugins/thinking-sphinx/
lib/thinking_sphinx/search.rb:219:in `each_with_groupby_and_count'
        from (irb):3:in `each_with_index'
        from D:/Current/TechAssistTest/vendor/plugins/thinking-sphinx/
lib/thinking_sphinx/search.rb:218:in `each'
        from D:/Current/TechAssistTest/vendor/plugins/thinking-sphinx/
lib/thinking_sphinx/search.rb:218:in `each_with_index'
        from D:/Current/TechAssistTest/vendor/plugins/thinking-sphinx/
lib/thinking_sphinx/search.rb:218:in `each_with_groupby_and_count'
        from D:/Current/TechAssistTest/vendor/plugins/thinking-sphinx/
lib/thinking_sphinx/facet_search.rb:113:in `add_from_results'
        from D:/Current/TechAssistTest/vendor/plugins/thinking-sphinx/
lib/thinking_sphinx/facet_search.rb:49:in `populate'
        from D:/Current/TechAssistTest/vendor/plugins/thinking-sphinx/
lib/thinking_sphinx/facet_search.rb:47:in `each'
        from D:/Current/TechAssistTest/vendor/plugins/thinking-sphinx/
lib/thinking_sphinx/facet_search.rb:47:in `populate'
        from D:/Current/TechAssistTest/vendor/plugins/thinking-sphinx/
lib/thinking_sphinx/facet_search.rb:13:in `initialize'
        from D:/Current/TechAssistTest/vendor/plugins/thinking-sphinx/
lib/thinking_sphinx/search_methods.rb:422:in `new'
        from D:/Current/TechAssistTest/vendor/plugins/thinking-sphinx/
lib/thinking_sphinx/search_methods.rb:422:in `facets'
        from (irb):3>>
1

1 Answers

2
votes

If you're using integers for facets, then they should be defined as attributes:

has model2.community_id, :as => :community_id, :facet => :true

The indexes method is for fields - which are the textual data you want people to be able to search for. I'm guessing the people who use your site won't be entering in the community id into the search field. Leave a comment if that's not the case, and I'll expand on how you can have the community_id as both a field and an attribute.