Creating a "Search"


#1

Hello all.

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.

Cheers,

  • Josh

#2

Josh,

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.

Jay

Josh G. wrote:

Hello all.

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.

Cheers,

  • Josh

#3

Jay wrote:

Josh,

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.

Jay

Josh G. wrote:

Hello all.

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.

Cheers,

  • Josh

Hello Jay,

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.

Cheers,
Josh


#4

Josh G. wrote:

Jay wrote:

Josh,

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.

Jay

Josh G. wrote:

Hello all.

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.

Cheers,

  • Josh

Hello Jay,

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.

Cheers,
Josh

Josh,

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:

– Jay


#5

Hi Josh,

you really should give a lucene inspired solution a try. This would be
either ferret or solr. A main difference between these solutions is that
you
would need a java server like tomcat or jetty running the solr instance.
You’ll be able to run ferret without this requirement as it is a
superfast c
implementation of a fulltext index inspired by lucene indexes and has
great
ruby and rails bindings. Check out the already cited project site of
acts_as_ferret. If you are already running a java server or are familiar
with setting up one and maybe want to use your fulltext index from legal
java proggies as well solr would be a perfect fit.

Cheers,
Jan

On 2/3/07, Josh G. removed_email_address@domain.invalid wrote:

acts_as_ferret (http://projects.jkraemer.net/acts_as_ferret) rails

Hello all.
point out how to create a search? Thanks very much.
make a suggestion as to what might be the best solution in my position?


––––––––––––––––––––––––––––––
http://www.inviado.de - Internetseiten für RAe
http://www.xing.com/profile/Jan_Prill


#6

Josh G. wrote:

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:

article.rb:

acts_as_solr :fields => [:title, :content]

articles_controller.rb:

def search
@articles = Article.find_by_solr(params[:query])
end

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:

Search

<%= start_form_tag "/articles/search" %>
<%= text_field_tag :query, params[:desc], :class => "styled" %> <%= submit_tag "", :class => "button" %>
<%= end_form_tag %>

Thanks.

Cheers,
Josh

Josh,

The acts_as_solr provides a very nice and simple video-tutorial on their
website. It’s really worth checking it out.

  • Jay

#7

Jay wrote:

Josh G. wrote:

Jay wrote:

Josh,

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.

Jay

Josh G. wrote:

Hello all.

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.

Cheers,

  • Josh

Hello Jay,

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.

Cheers,
Josh

Josh,

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:

– Jay

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:

article.rb:

acts_as_solr :fields => [:title, :content]

articles_controller.rb:

def search
@articles = Article.find_by_solr(params[:query])
end

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:

Search

<%= start_form_tag "/articles/search" %>
<%= text_field_tag :query, params[:desc], :class => "styled" %> <%= submit_tag "", :class => "button" %>
<%= end_form_tag %>

Thanks.

Cheers,
Josh


#8

Yes, I saw the video that they offered, and I did watch it. I’m still
not getting any results from my obvious searches and I’m not sure why.
I’m still very new to Rails so I’m sure it’s something obvious it’s just
a matter of finding it.

Cheers,
Josh


#9

Jay wrote:

Josh G. wrote:

Yes, I saw the video that they offered, and I did watch it. I’m still
not getting any results from my obvious searches and I’m not sure why.
I’m still very new to Rails so I’m sure it’s something obvious it’s just
a matter of finding it.

Cheers,
Josh

This is obvious, but, have you fallowed all the steps on the video and
inserted data to the Solr index? It’s really awesome but it won’t do
magic for you. Try inserting a new entry and searching for it. I was
able to get it up and running the first time I tried.

Also, I suggest installing the plugin with script/plugin install instead
of unzipping the file because I noticed the zip files aren’t realy
up-to-date.

– Jay

Yes I installed using script/plugin and it went fine. The video kind of
lost me though especially when they started running things like
start.jar. I understood everything else except that part. When I try to
run start.jar on my computer I get a thread exception and it crashes.


#10

Josh G. wrote:

Yes, I saw the video that they offered, and I did watch it. I’m still
not getting any results from my obvious searches and I’m not sure why.
I’m still very new to Rails so I’m sure it’s something obvious it’s just
a matter of finding it.

Cheers,
Josh

This is obvious, but, have you fallowed all the steps on the video and
inserted data to the Solr index? It’s really awesome but it won’t do
magic for you. Try inserting a new entry and searching for it. I was
able to get it up and running the first time I tried.

Also, I suggest installing the plugin with script/plugin install instead
of unzipping the file because I noticed the zip files aren’t realy
up-to-date.

– Jay


#11

Well, there’s not much I can say, just keep watching the video until you
get it :wink:

– Jay

I think I’ll just find another way, since I can’t seem to get this
start.jar file to work, it keeps running into exceptions and crashing.

Does anyone have any other suggestions?


#12

Josh G. wrote:

Jay wrote:

Josh G. wrote:

Yes, I saw the video that they offered, and I did watch it. I’m still
not getting any results from my obvious searches and I’m not sure why.
I’m still very new to Rails so I’m sure it’s something obvious it’s just
a matter of finding it.

Cheers,
Josh

This is obvious, but, have you fallowed all the steps on the video and
inserted data to the Solr index? It’s really awesome but it won’t do
magic for you. Try inserting a new entry and searching for it. I was
able to get it up and running the first time I tried.

Also, I suggest installing the plugin with script/plugin install instead
of unzipping the file because I noticed the zip files aren’t realy
up-to-date.

– Jay

Yes I installed using script/plugin and it went fine. The video kind of
lost me though especially when they started running things like
start.jar. I understood everything else except that part. When I try to
run start.jar on my computer I get a thread exception and it crashes.

Well, there’s not much I can say, just keep watching the video until you
get it :wink:

– Jay


#13

Hey josh,

do you have a jetty install of solr downloaded (or does this come with
acts_as_solr - can’t believe this)? Have you got java in your path? What
is
“java -version” on the command line giving you?

First we need to know if you match the prerequisites. Especially java
and
solr up and running. Do things step by step! Get information on the solr
site (google:solr) and maybe run their example before you integrate solr
into ruby and rails by using acts_as_solr. I’ve tried it some time ago
and
had no problems either. But I’m coming from java land and ymmv.

Cheers,
Jan


http://www.inviado.de - Internetseiten für RAe
http://www.xing.com/profile/Jan_Prill


#14

On Sun, Feb 04, 2007 at 12:32:58AM +0100, Josh G. wrote:

Well, there’s not much I can say, just keep watching the video until you
get it :wink:

– Jay

I think I’ll just find another way, since I can’t seem to get this
start.jar file to work, it keeps running into exceptions and crashing.

Does anyone have any other suggestions?

Just give acts_as_ferret a try. You won’t need a video to get going,
promised :wink:

However it’s correct that there are known locking problems and index
corruptions occuring when accessing the index with multiple processes
under high load.

To solve these problems, aaf now comes with a DRb-based server that will
be the only process accessing the index - quite similar to solr’s
approach. Plus you’ll only have to set this server up in your production
environment, for development mode the usual direct index access is
enough.

To get started, have a look at
http://projects.jkraemer.net/acts_as_ferret

In case of problems, don’t hesitate to ask on the ferret mailing list
(removed_email_address@domain.invalid or http://www.ruby-forum.com/forum/5)

cheers,
Jens


Jens Krämer
removed_email_address@domain.invalid


#15

Hi!
On Sun, Feb 04, 2007 at 06:31:20PM +0100, Josh G. wrote:
[…]

I seem to be having problems with this as well. When including the file
I get a premade page that says:

We’re sorry, but something went wrong.

We’ve been notified about this issue and we’ll take a look at it
shortly.

that’s the standard Rails http/500 page. look in log/development.log for
the real error.

All I did was add the line:
require ‘acts_as_ferret’
that is only needed in environment.rb if you installed acts_as_ferret
as a gem (gem install acts_as_ferret).

And I recieved that error. I followed the quick start guide perfectly
and downloaded from
svn://projects.jkraemer.net/acts_as_ferret/trunk/plugin/acts_as_ferret

I suppose you did this via script/plugin install … ?
If this is the case, remove the above require from wherever you put it
and just use acts_as_ferret in your model:

class YourModel
acts_as_ferret
end

Jens


Jens Krämer
removed_email_address@domain.invalid


#16

Jens K. wrote:

On Sun, Feb 04, 2007 at 12:32:58AM +0100, Josh G. wrote:

Well, there’s not much I can say, just keep watching the video until you
get it :wink:

– Jay

I think I’ll just find another way, since I can’t seem to get this
start.jar file to work, it keeps running into exceptions and crashing.

Does anyone have any other suggestions?

Just give acts_as_ferret a try. You won’t need a video to get going,
promised :wink:

However it’s correct that there are known locking problems and index
corruptions occuring when accessing the index with multiple processes
under high load.

To solve these problems, aaf now comes with a DRb-based server that will
be the only process accessing the index - quite similar to solr’s
approach. Plus you’ll only have to set this server up in your production
environment, for development mode the usual direct index access is
enough.

To get started, have a look at
http://projects.jkraemer.net/acts_as_ferret

In case of problems, don’t hesitate to ask on the ferret mailing list
(removed_email_address@domain.invalid or http://www.ruby-forum.com/forum/5)

cheers,
Jens


Jens Kr�mer
removed_email_address@domain.invalid

I seem to be having problems with this as well. When including the file
I get a premade page that says:

We’re sorry, but something went wrong.

We’ve been notified about this issue and we’ll take a look at it
shortly.

All I did was add the line:

require ‘acts_as_ferret’

And I recieved that error. I followed the quick start guide perfectly
and downloaded from
svn://projects.jkraemer.net/acts_as_ferret/trunk/plugin/acts_as_ferret
and installed all the libraries.


#17

Jens K. wrote:

Hi!
On Sun, Feb 04, 2007 at 06:31:20PM +0100, Josh G. wrote:
[…]

I seem to be having problems with this as well. When including the file
I get a premade page that says:

We’re sorry, but something went wrong.

We’ve been notified about this issue and we’ll take a look at it
shortly.

that’s the standard Rails http/500 page. look in log/development.log for
the real error.

All I did was add the line:
require ‘acts_as_ferret’
that is only needed in environment.rb if you installed acts_as_ferret
as a gem (gem install acts_as_ferret).

And I recieved that error. I followed the quick start guide perfectly
and downloaded from
svn://projects.jkraemer.net/acts_as_ferret/trunk/plugin/acts_as_ferret

I suppose you did this via script/plugin install … ?
If this is the case, remove the above require from wherever you put it
and just use acts_as_ferret in your model:

class YourModel
acts_as_ferret
end

Jens


Jens Kr�mer
removed_email_address@domain.invalid

Yes I downloaded off the svn and copied over all the libraries into my
/lib folder and when I don’t use the require I get:

undefined local variable or method `acts_as_ferret’ for Article:Class

For some reason I am cursed when it comes with getting plugins to work
:stuck_out_tongue:


#18

On Mon, Feb 05, 2007 at 04:16:39AM +0100, Josh G. wrote:
[…]

Yes I downloaded off the svn and copied over all the libraries into my
/lib folder and when I don’t use the require I get:

undefined local variable or method `acts_as_ferret’ for Article:Class

For some reason I am cursed when it comes with getting plugins to work

maybe that is because you don’t install them the right way - why don’t
you just use script/plugin install … ?

Or, if you manually checkout the source, then do it inside
RAILS_ROOT/vendor/plugins

Rails will only pick the plugins up automatically if they’re in that
place.

Jens


Jens Krämer
removed_email_address@domain.invalid