So I have been reading the below:
How can I manipulate MySQL fulltext search relevance to make one field more 'valuable' than another?
I was interested in the below response and tried to implement this with success.
SELECT url, keywords, title,
MATCH (keywords) AGAINST ('green watermelon') AS rel1,
MATCH (title) AGAINST ('green watermelon') AS rel2
FROM straight
WHERE MATCH (keywords,title) AGAINST ('green watermelon')
ORDER BY (rel1)+(rel2*1.5)
My only problem is the following.
If a user is to search for say "Green watermelon" which matches 3 rows in a table with 2 columns as below:
+------------+------------+ | Keyword | Title | +------------+------------+ | Green | Green | | Green | Watermelon | | Watermelon | Watermelon | +------------+------------+
I would like the second record to be "ranking" first as it is most relevant, but they all have the same relevancy for the search term "Green Watermelon" due to "Green" being used twice within Keyword and Title.
The best way I think this can be solved is if it finds the word green once it increases the relevancy by say 1 and any other times it sees the word green it increases it by 0 then if it sees watermelon it does the same. This would give the second result a relevancy score of 2 and the other 2 rows a relevancy of 1. Therefore making it more relevant as it should be. This will then work for longer search terms when searching in a larger database.
EDIT:
If possible I could create another column that has both the title and the keywords in, so say the column is called "mashup" the table will now look more like:
+------------+------------+-----------------------+ | Keyword | Title | Mashup | +------------+------------+-----------------------+ | Green | Green | Green Green | | Green | Watermelon | Green Watermelon | | Watermelon | Watermelon | Watermelon Watermelon | +------------+------------+-----------------------+
Then "if possible" we would need to de dupe the fields so they end up like:
+------------+------------+-----------------------+ | Keyword | Title | Mashup | +------------+------------+-----------------------+ | Green | Green | Green | | Green | Watermelon | Green Watermelon | | Watermelon | Watermelon | Watermelon | +------------+------------+-----------------------+
Then the search will work as intended with perfect relevancy scores.
Thanks in advance