MySQL Boolean Partial Search
I've searched a lot and I previously have had something similar working but I can't quite work out why this isn't producing the results I expect.
Say I have 'test6' within name, manufacturer, model or description, I wish to search for 'tes', but using开发者_运维技巧 the below query it doesn't return as I expect.
I have also tried 'test' with "AGAINST('test'+ IN BOOLEAN MODE etc.. any help would be appreciated thanks.
ALTER TABLE productinfo ADD FULLTEXT(name, manufacturer, model, description);
SELECT id, name,category_id, price, manufacturer, model, shortdescription,
description,stockqty,shippingbase,shippingcost, buyitnow,auctionitem,
MATCH (name, manufacturer, model, description)
AGAINST('tes'* IN BOOLEAN MODE) as score
FROM productinfo
WHERE MATCH (name, manufacturer, model, description)
AGAINST('tes'* IN BOOLEAN MODE) ORDER BY score DESC
Resolved, Note: after some research it was an asterisk that needed to be after the search term (in this case 'tes') so AGAINST('tes'* IN BOOLEAN MODE);
There are two problems you are running into with this query.
- Fulltext searches require a minimum word length of 4 (see the manual)
- Fulltext searches look for whole words only. To match a partial word you need to put the asterisk inside of the quotes
AGAINST('test*' IN BOOLEAN MODE)
or you can use a regex orlocate()
精彩评论