简体   繁体   English

如何在SQL中实现搜索功能?

[英]How to implement search functionality in SQL?

除了SQLQuery,联接和条件查询外,我如何实现搜索功能?

The simpliest way is to use like condition: 最简单的方法是使用类似条件:

select * from Table where fieldName like '%searchword%'

But it's very slow, so it's better to use full-text indexing: in mysql , in sql server 但是它非常慢,因此最好使用全文本索引: 在mysql中在sql server中

Well, outside of SQL, you're left to the calling application to do searches. 好吧,在SQL之外,您留给调用应用程序进行搜索。 Definitely not the recommended choice if you can avoid it as you'll have to read all data first before searching it; 如果可以避免, 绝对不是推荐的选择,因为在搜索之前必须先读取所有数据。 indexing is a very powerful feature for databases. 索引是数据库的一项非常强大的功能。

If you want to display all data and then manipulate/sort/filter it, however, this method has its place. 但是,如果要显示所有数据, 然后对其进行操作/排序/过滤,则可以使用此方法。

Perhaps you wish to clarify your question as to what you're looking to accomplish? 也许您想澄清您要完成的工作的问题?

最好使用sphinxsolr之类的东西来实现一个真正的搜索引擎,而不是使用大多数数据库提供的东西,甚至是mysql的全文本搜索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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