View Single Post
Old 06-04-2010, 04:44 PM   #5 (permalink)
Village Idiot
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by CΛSTΞX View Post
Hmm, thank you. How about this >

PHP Code:
SELECT *, ((CASE WHEN `descriptionLIKE '%brown%' THEN 1 ELSE 0 END) + (CASE WHEN `descriptionLIKE '%fox%' THEN 1 ELSE 0 END) + (CASE WHEN `descriptionLIKE '%lazy%' THEN 1 ELSE 0 END) + (CASE WHEN `descriptionLIKE '%dog%' THEN 1 ELSE 0 END)) AS relevance
FROM 
`items`
WHERE `description`LIKE '%quick%' AND (
  `
description`LIKE '%brown%'
  
OR `descriptionLIKE '%fox%'
  
OR `descriptionLIKE '%lazy%'
  
OR `descriptionLIKE '%dog%'
)
ORDER BY relevance DESC
LIMIT 0 
30
Do you think that works properly ? Or what money you want to do the best script for that ?
The first part looks good, but the second part doesn't make sense. From what it looks like, the description would have to have the word quick in it to be included. Change the and to or and you have have something here. The only issue I see is ordering passed the number of similar words, the last two examples from what you gave would not necessarily be in that order.

For me to do it in SQL would take me about an hour to write, debug and prefect, so $50. You can see my portfolio at http://www.qsdconsulting.com At the moment you seem to be on to something, so lets see how that goes first. I'm happy to help you as long as you are giving it your effort.
__________________

Village Idiot is offline  
Reply With Quote