简体   繁体   中英

Issue with Match Against in search query

I have a situation with a website who lists products.

I'm using a fulltext index with a Match Against search

There is a field named "itemcode" that field is in varchar type

turns out one of the codes for instance, goes like

"WTC-153-U"

And when i type on the textbox "WTC-153" i get no results, i guess it's based on the hyphen and numbers, is there any workaround or a better method for this?

I cannot seem to find a solution at the moment without having to modify that much code

The query goes like this

SELECT field FROM table WHERE MATCH(itemcode) AGAINST ('WTC-153')

Thanks

- counts as a word separator, so 'WTC-153-U' counts as three words, 'WTC' , '153' and 'U' .

With MyISAM, the default lower word length limit for full text searches is four characters and with InnoDB it is 3 (these can be changed).

If you are using InnoDB, you could get around the issue by searching for both 'WTC' and '153' in the text.. obviously, this will return a result even if these words are not together or in the right order.

Otherwise you could search with LIKE '%WTC-153%' but that wouldn't be able to use the index. LIKE 'WTC-153%' will be able to use the index, but will only return the row if the field starts with 'WTC-153' .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM