Sorry for the slow response... there's a couple of issues with your approach.

Firstly, using strings for attributes - though there's ways around this.
http://freelancing-god.github.com/ts/en/common_issues.html#string_filters

Secondly, you're expecting Sphinx to have some sense of key/value pairs, and it 
doesn't. EN and FR get put together, and the descriptions get merged together. 
This is a far more complex issue if you want to keep search on the Post, but if 
you switch to Description (and pull in post info via an association), then 
normal string filtering issue becomes the thing to deal with again. This is the 
approach I'd take, but obviously I don't have my head around your app :)

Cheers

-- 
Pat

On 14/04/2010, at 8:04 PM, minhnghivn wrote:

> Sorry if this is already posted elsewhere in the group but I've
> searched the mail group and found no solution to my situation with
> has_many association in Thinking Sphinx.
> 
> Suppose a Post has many descriptions in many languages. I create two
> table posts and descriptions
> 
> posts (id, title)
> descriptions(post_id, lang, description)
> 
> posts table:
> post_id   |    title
> -----------------------------------
> 1            |   Post One
> 
> descriptions table
> 
> post_id |  lang  |   description
> -------------------------------------------
> 1          | "EN"  |   this is the first line - in English
> 1          | "FR"  |   this is the second line - in French
> 
> I want to search for "any post whose EN description contains "first"
> ". So
> I perform a query like this:
> 
> Post.search "first", :with => {:language_ids => "EN"}  # this works,
> returned the Post One
> 
> but, amazingly, if I do:
> 
> Post.search "first", :with => {:language_ids => "FR"}
> 
> Again, it returns the Post One while I have thought it should return
> nothing!!!
> 
> Any one can explain why?
> 
> class Post < ActiveRecord::Base
>  has_many :descriptions
> 
>  define_index do
>    indexes post_id, title
>    indexes descriptions.language_id, :as => :language_ids
>  end
> end
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/thinking-sphinx?hl=en.
> 

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

Reply via email to