Hello,
I-ve been trying to make Sphinx solve a problem for me: obtain a list
of Tags, ordered by usage (@count) but avoid having tags that combined
cause an empty result.
Given the models:
class Post < ActiveRecord::Base
define_index do
indexes :title, :description
indexes tags(:name)
end
end
class Tagging < ActiveRecord::Base
belongs_to :post
belongs_to :tag
delegate :name, :slug, :to => :tag
define_index do
indexes tag(:name)
has post(:id), :as => :post_id
end
end
I want to obtain a list of tags that only matches the ones used in the
posts, so if I do:
Post.search "foo"
I would like the tags be also limited to the list of posts and not other tags.
Right now, I do this by limiting taggings to a list of Post IDs:
total_posts = Post.search_count(keywords)
post_ids = Post.search_for_ids keywords, :limit => total_posts
taggings = Tagging.search keywords, :with => { :post_id => post_ids }
As you notice, this does not scale since post_ids can contain 10K records.
I can't think on a way to retrieve a list of tags that only apply to
the list of posts that are involved in the results, so when combined
keywords it does not end in a empty results scenario.
Think of this in a combinatory tag cloud or something like that :P
Perhaps (most likely) I'm doing it wrong, so will appreciate any
comments and suggestions that help me think out of the box.
Thank you.
--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry
--
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.