I have a simple rails 3 application that lists restaurants as a training exercise. I want to be able to search name and description using one textfield on the restaurant index page.
Given the query pizza. The matches should be
- name: Tony’s, description: … is a pizzeria that has been around since the 1950’s …
- name: Domino’s Pizza, description: …
- name: The Hall, description: … pizzas, pastas and steaks …
Because:
- the word pizza is a fuzzy match to ” pizz eri a ” using similar logic as TextMate’s Cmd-T. (the spaces in the word pizzeria are only used to get the mini-Markdown to work)
- pizza is a lowercase match to Pizza
- pizza is a substring of pizzas (should work with ends-with begins-with and includes)
How would I go about doing this in rails 3? Do I use thinking_sphinx, tire, sunspot-rails or just a custom query for my application.
I found a very simple solution that serves my needs.
This creates a string that looks like this
Then I use it in a LIKE query and I get the expected results. Now all that remains is to solve the non-trivial problem of determining the order of relevance 🙂
UPDATE:
Found a quick and dirty way of determining order of relevance base on the assumption that a shorter string will most likely be a closer match than a longer one.