Search code examples
sqlfreetext

Tweaking my free-text search to return the correct results - Ranking seems off at the moment


I am using free-text on my website to get better search results but am getting something I don't understand.

If I use this as my free-text search (with containtstable())

isabout("*redflower*" weight (.3), "*red*" weight (.2), flower weight (.1))

I get Red Mason Bee Box with a rank or 172 and also get Wildflower Seeds - Red Campion with a rank of 172. This description is the only field being searched on. I would have thought that the Wildflower Seeds - Red Campion should rank higher because it contains BOTH terms not just one.

Could someone explain what is happening and maybe provide some examples of how to tweak it so it ranks higher for descriptions with all the words present?

EDIT: I have also tried:

isabout("*redflower*", "*red*" weight (.2), "*flower*" weight (.1))

which changed the results to Red Mason Bee Box with a rank of 21 and Wildflower Seeds - Red Campion with a rank of 21. I don't understand why that would happen because the second has both words in, not just one.


Solution

  • I am going to alter the way I search to use the NEAR operator before doing this weighted search. This should then bring back the most relevant results first.

    i.e 'flower NEAR red' - This won't actually work in my example as you can't have leading wild cards but I am going to create reverse index's of all my fields and do "rewolf*" NEAR der' which will translate to Wildflower NEAR red