So, I'm building quick and dirty search functionality in my first rails app. I'm doing a query and returning a list of objects. e.g.
@articles = Article.find_by_sql("select * from article where title like "%test%" or title like "%foobar%")
So, the articles collection will return a lot of data, some of it matching my search terms better than others. I want to sort the array so that the items that match are presented first.
Here's the conceptual pseudo code I'm trying to implement.
for each article in @articles
calculate the article score based on how many times the search terms appear
sort the array of articles based on the score
("score" is not part of the article object.)
Any ideas on how this can be sorted?