I would recommend taking the following approach:

* Change the attribute to use the category ids instead of names.
* In non-Ad classes, add the following attribute:

  has '0', :as => :category_ids, :facet => true, :type => :multi

* And then in your search calls, match on both the category id you're after, 
and 0:

  category = Category.find_by_name('auto')
  ThinkingSphinx.search 'red car',
    :with    => {:category_ids => [0, category.id]},
    :classes => [Ad, User]

That should do the trick.

Cheers

-- 
Pat

On 29/11/2012, at 4:47 AM, Well Done Steak wrote:

> Hi,
> 
> I have about 9 models (more coming soon) which currently have both common & 
> unique sphinx attributes in each - these attributes are used as filters & 
> don't need to be searchable. 
> 
> Here is an example of some of my models which illustrates the problem:
> 
> class Ad
>   belongs_to :categories
>   
>   define_index('ad') do
>     has categories.name, :as => :category_name_tags, :facet => true, :type => 
> :string
>   end
> end
> 
> class User
>   belongs_to :region
>   define_index('ad') do
>     #psudocode below 
>     has "(SELECT name from categories)", :as => :category_name_tags, :facet 
> => true, :type => :string
>   end
> end
> 
> So that I can search like this: 
> 
> results = ThinkingSphinx.search "red car", :with => { :category_name_tags => 
> "autos" }, :classes => [Ad, User]
> 
> All my non-Ad models need to have an "category_name_tags" attribute defined 
> which will match any "category_name_tags" filters the user specifies when 
> searching - in other-words  these are dummy attributes that should always 
> match all certain filters - they are passive for most models, I want to do 
> this because if these attributes do not exist in my model, then no results 
> from that model will be returned.
> 
> Note: I cannot modify the data model used by the client.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/thinking-sphinx/-/irULT959k9AJ.
> 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