Archive for August, 2007

Been away…

Monday, August 27th, 2007

Been away for a while. Between working on my new company, Inquisix, and a much needed vacation, I haven’t had a chance to write anything in a while. Waking up every day to see the view below really does cause one to simply relax instead of working much.

The View

This is Newport Beach, CA, and my family and I stayed right on the boardwalk — walk out the front door, cross the boardwalk, and you’re on the beach. What a great way to relax!

Anyone have a chance to try a Segway? The Segway shop in Newport beach sells more Segways than anywhere else in the world. As a marketing ploy, they will take you on a tour. It is amazing how intuitive this machine is. Within a couple minutes, you are off exploring like an expert. Now, if I could just get myself one of these, I would be all set. Then again, I usually prefer to walk when I golf.

I will have lots more to say about Inquisix and other technology issues in the coming weeks.

It’s good to be back!

Ruby Text Search

Thursday, August 2nd, 2007

Part of my current project screamed for some basic searching. In typical Ruby development fashion, the first thing I think of is “someone else must have done this already.” Sure enough, there were several, but the one the fit the best for me was the query version found here. It looked perfect, but there were a few problems.

  1. The Wiki messed up a lot of characters, making it difficult to get the code.
  2. A few things didn’t work quite right

Time to fix the problems. First, I needed to get the code onto my disk without spending hours finding all the places where the Wiki messed things up. A quick Google search for “search apply_demorgans” located what I was looking for. Now I had something that basically worked. Unfortunately, a few items did not work as advertised.

The first problem I found was that if you added a searches_on to your model object, you could not override the searchable fields. A quick update to self.searchable_fields solved that problem. The second problem was that if you included another table in your search, the searchable fields were not automatically pulled in as advertised. In addition, searchable fields did not include the table name so any searches with an include didn’t always work (need unique column names). Finally, I updated the search routine to also return a count so you can more easily paginate the results.

That’s it for now. The remaining issue I have is that include only works if the association variable name is the same as the table name. However, if you have an association with a different name or finder_sql, it doesn’t work. I don’t have a huge need for this right now, so I haven’t fixed it yet.

Anyone out there care to chime in?

Here is my final code: search.rb

DND: Edited to include link to file instead of code in the post. It looks like even Wordpress was playing some games with the file. If you download the file, remove the .txt extension.