简体   繁体   中英

MySQL fulltext/regexp/levenshtein search optimization

I have a database of 100+ million records (and rapidly growing) and I would like to implement a search feature that sorts by the closest results. I did some research and found that fulltext searches are only prefixes, which isn't really what I want.

I got results that are close enough to call it good, but the problem is the query is very slow.

The levenshtein function is from here: http://www.artfulsoftware.com/infotree/qrytip.php?id=552

Here's the query:

SELECT `id`, 
       `word`, 
        MATCH (`word`) AGAINST ('+*search*') IN BOOLEAN MODE) AS `match` 
FROM `words` 
WHERE `word` REGEXP '^.*[search].*$' 
  AND levenshtein(`word`, 'search') <= 2 
ORDER BY levenshtein(`word`, 'search'), `match` ASC 
LIMIT 10;

So, overall the results are pretty close, but it takes minutes to actually complete the search, which is really not what I want since each time a key is pressed I send a jquery AJAX request.

Any help would be appreciated.

I wound up using sphinxsearch as @RobGudgeon suggested. Though not MySQL (and another database on its own) it's actually very quick on both updating from MySQL and searching within its own database. Recommended for fulltext searches on big databases since MySQL's native support is currently lacking.

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