Hi Pascal, i'm in a situation like yours.
I've a nested set for the category model, which has a structure like
yours:
world -> europe -> italy -> tuscany etc
I've saved all the ids of the categories in a column of each article
row (like "1, 5, 47, 102")
And then indexed them with
has all_categories, :type => :multi, :as => :all_categories, :facet
=> true
Actually i'm using the column instead of get them directly during the
indexing with a query like "lft <= #{category.lft} and rgt >=
{category.rgt}" because after 2 days i've found any solution on how do
that query, with an association in the category model like
has_many :all_categories, :class_name => 'Category', :finder_sql =>
'SELECT * FROM categories c WHERE c.lft <= #{lft} and c.rgt >= #{rgt}
ORDER BY c.lft ASC'
it doesn't work with sphinx, though it works using the console :
( (if you have any hint about this it would be greatly
appreciated ;) )
btw..
when i search with Article.facets :with => {:all_categories => 12345}
i get the result with all the data, like "1, 456, 678, 12345, 423545".
Actually i'm thinking to use that string to get the children
categories, with something like:
all_categories = Article.facets(:with => {:all_categories =>
12345}, :facets => :all_categories)[:all_categories]
index = all_categories.first[0].split(' , ').index('12345')+1
and then use the index on the all_categories, with
ids = {}
all_categories.each do |a|
ids[a[0].split(' , ')[index]] = a[1]
end
And finally get all the categories using the ids.keys ( Category.find
(:all, :conditions => {:id => ids.keys}) ) and in the view show the
name with near how many articles has that category and subcategories.
My big worry is that it would be quite cpu consuming all this
calculations done for each request. But for now i've found anything
else to solve this problem.
I hope that this could help you, and eventually find a better solution
together ;)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---