I want to allow users to specify keywords that they want searched in
specific fields. For example, a Story has a title, description, and
text. I want to allow the user to search "zombies" and decide whether
they search it in any combination of title, description, and text. How
would I do this? I tried Story.search :conditions => {:title =>
"zombie"....etc} but it didn't work out as planned.
If any of you watch Railscast, I've been trying to combine this with
the Advanced Search tutorial he did, so I'm actually making a hash.
Here's what it looks like:
class Search < ActiveRecord::Base
def stories
@stories ||= find_stories
end
def find_stories
Story.search :conditions => conditions
end
def conditions
cond ||= {}
cond[:title] = keywords if story_title?
cond[:author_name] = keywords if author_name?
cond[:chapter_title] = keywords if chapter_title?
cond[:story_description] = keywords if story_description?
cond[:chapter_text] = keywords if chapter_text?
cond
end
end
When creating a new search, the users can check the boxes that they
want the corresponding attribute to be searched. When no boxes are
checked it seems to return all results, and when all boxes are checked
it returns no results. Am I doing this right?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---