views:

24

answers:

1

Lets say I do not want to get the VPS or Dedicated Server required to run constant indexing like with Thinking_Sphinx plugin or many of the other full text search plugins for ruby on rails.

I have a bunch of listings in the database with a Name field and category field (among other things).

It it possible search for a name in a certain category without having a fulltext search plugin that requires constant indexing? and how would I go about doing this?

Thank you. I hope I have been clear enough.

A: 

If you just want to search a specific column (or two), you could certainly take advantage of the LIKE SQL operator.

For example, using a named_scope in rails

class MyModel < ActiveRecord::Base
  named_scope :search, lambda { |query|
    { :conditions => ["category like ?", "%#{query}%"] }
  }
end

Then, in your controllers, you could do something like

@search_results = MyModel.search(params[:query])

There are a few drawbacks to this approach:

  1. You're only searching a single column. You can take advantage of the dynamic nature of Ruby to expand this to more columns, but you're definitely not getting the advantage of an index like you would with sphinx
  2. This will work fine for smallish sets of data. After you get a few thousand rows, you're going to start needing some decent indexing strategies to keep this fast, otherwise searching this way is going to slow down dramatically.

Hopefully that helps. If I misunderstood the question, let me know.

jerhinesmith
thanks jerhine. You answered what I was looking for. I understand what you are saying and thank you for the drawbacks. I did happen to find a railscasts episode on advanced searches that also helped me. http://railscasts.com/episodes/111-advanced-search-form
bob