I recently set up a relevance search plugin for Ruby on Rails. If you want it, you can follow this link to check out the plugin. If you want to know about the plugin’s algorithm and limitations, read on.
First, I’ve currently only tested this on MySQL. I’m establishing and using ActiveRecord connections, so the only possible hiccup is SQL syntax.
Second, it searches all columns on the table. I’m currently working on configuration. But still, if you want a comprehensive search across the entire table, this will work.
Finally, here’s the algorithm:
- Establish a new connection to the database.
- Create a temporary table in the database. Because temporary tables can only be seen by the connection that created them, it keeps each search unique.
- For each column in the table, find all rows (records) that where that column contains the search term.
- Select the unique ids from the table ordered by the number of times the id occurs in the table
- Find each record by its id and add it to the an array in order and return it to the user.
If you have any recommendations, feel free to comment here or branch the code on github.







No Comments »
No comments yet.
Leave a comment