I have a table articles(: Rails Model, but I think the problem is more with SQL), which has a column name permalink. For example, some of my permalinks:
title-of-article
great-article
great-article-about-obama
obama-stuff-about-him
I want to combine a query like great-article-about-obama-random-stuffwith great-article-about-obama. Can this be done while avoiding killing?
Thanks everyone
ps: We use Rails 3 and Postgresql (or Sqlite has not yet decided for production)
EDIT
We can do something similar, but the main drawback is that we have to extract all the permalinks from table articles:
permalinks = ['title-of-article','great-article','great-article-about-obama','obama-stuff-about-him']
string_to_match = 'great-article-about-obama-random-stuf'
result = permalinks.inject('') do |matched,permalink|
matched = (string_to_match.include? permalink and permalink.size > matched.size) ? permalink : matched
end
result => 'great-article-about-obama'
I would love to find a way to do this right in SQLthe obvious reason of performance.
source
share