Hi
I'm creating a system which requires a slug system. For example, the URL for a blog post entitled "The Blog Title: Here" would be:
YYYY/MM/DD/the-blog-title-here
I have the system pretty well set up, where if your URL matches more than one entry it displays summaries of all matched entries, and if it only matches one entry it displays the full entry and so on. The only trouble I'm running into is with the "unslugging" of the title. Currently, I only take the first word into account: my SQL query ends like this:
'AND subject LIKE '.$this->db->escape(substr($title,0,strpos($title,'-')).'%')
The trouble is, if two posts posted on the same day begin with the same word, the single entry can never be matched. Furthermore, if one post begins with the word 'A' and another post posted on the same day begins with the letter A, the former post can never be matched alone.
My initial thought was to try to match every word in the slug with a LIKE %word%
, and while this is better it seems hackish and still isn't perfect ("A slug: troublesome!" and "A troublesome slug" would conflict). Is there an elegant solution to this problem?