Hi Tom

When searching across many models, Thinking Sphinx ignores model-specific 
settings like field_weights, because merging them opens the door for unclear 
behaviour (what if you had two fields with the same name but different 
weights?).

You can specify the weights as part of the search though - I know this isn't as 
elegant, but it's the only way it'll work with current releases:

  ThinkingSphinx.search('dogs', :field_weights => {:title => 100, :head => 100})

Cheers

-- 
Pat

On 30/05/2013, at 9:21 AM, Tom Collier wrote:

> I'm trying to search across multiple models in my Rails 3.2 app 
> (thinking-sphinx gem version 2.0.12), which has models like:
> 
> class Story < ActiveRecord::Base
>   define_index do
>     indexes title
>     set_property :field_weights => {
>       :title => 100,
>     }
>   end
> end
> 
> and
> 
> class Anthology < ActiveRecord::Base
>   define_index do
>     indexes head
>     set_property :field_weights => {
>       :head => 100,
>     }
>   end
> end
> 
> When I search using Story.search or Anthology.search, I get results with 
> weights of 100+, e.g.:
> 
> irb> Story.search("dogs").results[:matches].map { |m| m[:weight] }
> [111, 111, 111, 111, 101, 101, 101, 101, 101, 101, 101, 101, 100, 100, 100, 
> 100, 100, 100, 100, 100]
> irb> Anthology.search("dogs").results[:matches].map { |m| m[:weight] }
> [101, 101, 101, 1, 1, 1, 1, 1]
> 
> However, if I use ThinkingSphinx.search with the same query string, the 
> weights are much lower and the resulting order is is not what I would expect 
> given the weights from the Story and Anthology searches, e.g.:
> 
> irb> ThinkingSphinx.search("dogs").results[:matches].map { |m| m[:weight] }
> [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2]
> 
> It appears as though the field_weight definitions are ignored when I search 
> multiple models. Is there any way to use fields weights when searching this 
> way?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

 

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to