Josh G. wrote:
If you’re looking for MySQL search functionality in Rails, well, its
built-in and available to your models.
But if you’d like to use a third party solution that can do more than
MySQL there are a other great solutions, such as Ferret with the
acts_as_ferret (http://projects.jkraemer.net/acts_as_ferret) rails
plugin or Solr with the acts_as_solr
(http://acts-as-solr.rubyforge.org/) rails plugin.
It really comes down to one thing: see what your requirements are and
pick the best solution to fulfill it.
Josh G. wrote:
I would like to create a stable search for my database. The database
consists of several articles catergorized by title, date, author, and
subject. I would like to incoporate a search into my website that allows
a user to enter in some text and be able to shift through article titles
and contents and try to find suitable articles that match his or her
search text. How can this be done in Ruby? What is the best method for
doing it? Can anyone point out some good articles or tutorials that
point out how to create a search? Thanks very much.
I had no idea there was internal support for searching. I know there is
the find() function but that’s not nearly what I am looking for. I was
looking more on the lines of a MySQL FullText search, but if there are
better solutions than I am more then willing to try them out. Can you
make a suggestion as to what might be the best solution in my position?
I’m looking at probably more than a thousand or so articles to shift
through, so a fast search would be neccesary. Thanks.
People have different opinions about the third party search alternatives
and I hope I don’t create ‘enemies’ by expressing mine.
I’ve used Ferret with the acts_as_ferret plugin for about 6 months in
the past and I loved it. At the beginning it was all working great but
once I started having lots and lots of content activity - that being
people searching and creating new ones at the same time - it started
throwing “lock errors”, so I started looking for new alternatives until
I came across Solr and the acts_as_solr plugin.
I tried it out and was amazed by how fast it was, not to mention the
easiness of doing things with it. And the most important of all for me:
no more errors. It can do reads/writes simultaneously like a breeze.
Both Solr and the acts_as_solr are pretty new projects, but I do believe
it will be adopted by lots of users in its course.
So if interested here are the url’s:
Thank you for the links, but I seem to be a little confused on how
exactly the plugin works. Do you simply supply the search text to the
find_by_solr? I’m using it like so:
acts_as_solr :fields => [:title, :content]
@articles = Article.find_by_solr(params[:query])
I am getting a nil value for @articles, is this because I am using it
wrong or because it’s not returning any results? params[:query] is the
search text that I provided via a form that looks like:
<%= start_form_tag "/articles/search" %>
<%= text_field_tag :query, params[:desc], :class => "styled" %>
<%= submit_tag "", :class => "button" %>
<%= end_form_tag %>