SQL全文本搜索vs“LIKE”

编程入门 行业动态 更新时间:2024-10-15 18:28:33
本文介绍了SQL全文本搜索vs“LIKE”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假设我有一个相当简单的应用程序,它允许用户在他们自己的DVD上存储信息(标题,演员,年份,描述等),我想允许用户通过这些字段(例如

Let's say I have a fairly simple app that lets users store information on DVDs they own (title, actors, year, description, etc.) and I want to allow users to search their collection by any of these fields (e.g. "Keanu Reeves" or "The Matrix" would be valid search queries).

使用SQL全文搜索的优点是只需用空格分隔查询,然后执行SQL语句中的几个LIKE子句?

What's the advantage of going with SQL full text search vs simply splitting the query up by spaces and doing a few "LIKE" clauses in the SQL statement? Does it simply perform better or will it actually return results that are more accurate?

推荐答案

全文搜索可能会更快,因为它将受益于它将用于查找记录的单词索引,而使用LIKE将需要全表扫描。

Full text search is likely to be quicker since it will benefit from an index of words that it will use to look up the records, whereas using LIKE is going to need to full table scan.

在某些情况下,LIKE会更准确,因为LIKE%%AND LIKE%Matrix将选择矩阵而不是矩阵重新加载,而全文搜索将忽略The并返回两者。这说明两者可能是一个更好的结果。

In some cases LIKE will more accurate since LIKE "%The%" AND LIKE "%Matrix" will pick out "The Matrix" but not "Matrix Reloaded" whereas full text search will ignore "The" and return both. That said both would likely have been a better result.

更多推荐

SQL全文本搜索vs“LIKE”

本文发布于:2023-10-15 08:52:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1493817.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!