What is Full Text Search vs LIKE

后端 未结 6 1141
南旧
南旧 2020-11-30 17:08

I just read a post mentioning \"full text search\" in SQL.

I was just wondering what the difference between FTS and LIKE are. I did read a couple of articles but

6条回答
  •  情话喂你
    2020-11-30 17:36

    MySQL creates an index from the words of the enabled full-text search column and performs searches on this index. MySQL uses a sophisticated algorithm to determine the rows matched against the search query.

    Also, from this SO answer:

    There's a few advantages to full text searching.

    Indexing:

    Something like:

    WHERE Foo LIKE '%Bar';
    

    Cannot take advantage of an index. It has to look at every single row, and see if it matches. A fulltext index, however, can. In fact, fulltext indexes can offer a lot more flexibility in terms of the order of matching words, how close those words are together, etc.

    Stemming:

    A fulltext search can stem words. If you search for run, you can get results for "ran" or "running". Most fulltext engines have stem dictionaries in a variety of languages.

    Weighted Results:

    A fulltext index can encompass multiple columns. For example, you can search for "peach pie", and the index can include a title, keywords, and a body. Results that match the title can be weighted higher, as more relevant, and can be sorted to show near the top.

    Disadvantages:

    A fulltext index can potentially be huge, many times larger than a standard B-TREE index. For this reason, many hosted providers who offer database instances disable this feature, or at least charge extra for it. For example, last I checked, Windows Azure did not support fulltext queries.

    Fulltext indexes can also be slower to update. If the data changes a lot, there might be some lag updating indexes compared to standard indexes.

提交回复
热议问题