I'm creating a 'smart' search engine that will look into database by relevancy. My system calculate how many words in your sentence correspond to the database field 'tag_clean' that contains text, and try to get the proper result (one per research).
For example you get 'search youpla boom' in a tag_clean field, and another entry like 'search youpla bim' if you tape 'search bim' it will show the second entry.
My system set one point per word and get the most relevant as result. Everything works but my big problem is, it ignores completely the words order !
If you have 'google image test' and 'google test' and you search 'google test image' with my system, the most relevant will be the first one, but it's the second one that's right.
I'd like a system that understand the importance of word orders, but i've no idea how to do it in SQL.
A sample of my SQL request (important part is CASE WHEN at the end):
SELECT *
FROM keywords
WHERE tag_clean LIKE 'google%'
AND (static = 0)
AND
(
tag_clean LIKE '%google%'
OR tag_clean LIKE '%test%'
OR tag_clean LIKE '%image%'
)
OR
(
tag_clean = 'google test image'
AND static = 1
)
ORDER BY
((CASE WHEN tag_clean LIKE '%google%' THEN 1 ELSE 0 END)
+ (CASE WHEN tag_clean LIKE '%test%' THEN 1 ELSE 0 END)
+ (CASE WHEN tag_clean LIKE '%image%' THEN 1 ELSE 0 END))
DESC LIMIT 0, 1;
Thank you people :)