I'd create two different associations in the model, with the  
conditions set there. Something like the following (tho I may be  
getting the options wrong):

  has_many :low_proficiency_languages,  :class_name =>  
'Language', :conditions => 'proficiency = 1'
  has_many :high_proficiency_languages, :class_name =>  
'Language', :conditions => 'proficiency = 2'

And then:

  has low_proficiency_languages(:id), :as => :low_proficiency

-- 
Pat

On 07/08/2009, at 2:54 AM, Andrew wrote:

>
> By the way Pat, if you were to use that approach, what would your
> indexes look like?
>
> On Aug 6, 11:47 pm, Pat Allan <[email protected]> wrote:
>> Hi Andrew
>>
>> This is a tricky problem in Sphinx, and I'm not sure there's going to
>> be a solution that works for you.
>>
>> In your simple situation, you could have two MVA attributes,
>> low_proficiency and high_proficiency, with arrays of language  
>> integers
>> for the languages that fall into each category. Then you could search
>> like:
>>   User.search :with => {
>>     :low_proficiency => 9999,
>>     :high_proficiency => 4444
>>   }
>>
>> However, this obviously doesn't scale, if you've got half a dozen or
>> more proficiency levels. That's where a real solution doesn't appear,
>> because Sphinx doesn't have the concept of key-value pairs within
>> attributes, so I'm not really sure what you can do to get around  
>> that,
>> unfortunately.
>>
>> --
>> Pat
>>
>> On 06/08/2009, at 1:53 PM, Andrew wrote:
>>
>>
>>
>>> Sorry if this already exists on many threads... I don't really even
>>> know how phrase the question well.
>>
>>> Let's say I have a user model that has one profile, which itself has
>>> many "spoken_languages". Each language has a "proficiency" level.  
>>> For
>>> simplicity's sake, let's say that a proficiency can either be 1 or  
>>> 2.
>>> I would like to be able to filter a user search for users with
>>> different languages at different levels.
>>
>>> To put it in language "find users that speak language X at level 1,
>>> and language Y at level 2".
>>
>>> To put it in code terms, it would be something like:
>>
>>> User.search(:with => ['language_id = 9999 AND proficiency = 1',
>>> 'language_id = 4444 AND proficiency = 2'])
>>
>>> Now, keeping in mind that I'm sure that search syntax is completely
>>> wrong, how could I set up my indexes for this kind of search and
>>> perform it?
>>
>>> Any help is much appreciated!
>>
>>> Thanks
> >


--~--~---------~--~----~------------~-------~--~----~
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