在SQL Server中使用字符串的大数据进行搜索的最佳做法是什么 [英] What is the best practice to search in SQL server with large data for a string

查看:70
本文介绍了在SQL Server中使用字符串的大数据进行搜索的最佳做法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我想知道在sql server中搜索关键词或句子的最佳做法。



假设我有一张表说产品名称,描述和关键字。我的网站上有一个搜索功能,用户可以输入任何内容(句子或单个单词)。

我使用like子句查询产品表列,并将列表列入包含搜索条件的行。

如果产品中的数据量减少响应时间表很大,我添加了10的分页查询。

以上说明的场景是一个好习惯吗?



提前谢谢



我尝试过:



我当前的查询



select * from(选择srno作为productid,名称+''+说明+''+关键词作为搜索

来自ProductDetails)PD

其中PD.search LIKE'%bed%'或PD.search LIKE'%sheet%'



这里我把三列合并为名称,描述和关键词我在产品目录中搜索床单



桌子结构



ProductDetails例子

srno |名称|描述|关键字

1 |碎花床单| ..some文字.. |床单

2 |方形枕套| ..一些文字.. |枕套方形



是否合适将关键字放在单独的列中,或者我应该为关键字创建新表。

如果我必须为关键字创建新表,如何修改上述查询?

Hi everyone

I wanted to know that what may be the best practice to search for keywords or sentence in sql server.

Suppose I have a table say products with name, description and keywords. I have a search function in my website where the user may type in anything (sentence or single word).
I query the product table columns using like clause and shortlist the list to rows containing the search criteria.
To reduce the response time in case if the volume of data in product table is large, I add a pagination query of 10.
Is the above explained scenario a good practice?

Thanks in advance

What I have tried:

My current query

select * from (select srno as productid, name +' '+ descriptions +' '+ keywords as search
from ProductDetails) PD
where PD.search LIKE '%bed%' OR PD.search LIKE '%sheets%'

Here I have combined the three columns namely name,descriptions and keywords and I am searching for "bed sheets" in my product table

Table Structure

ProductDetails example
srno|Name|Description|keywords
1|Floral Bed Sheets|..some text..|bed sheets
2|Square Pillow Covers|.. some text..|pillow covers square

Is it proper to place keywords in a separate column or should I create a new table for keywords.
If I have to create a new table for keywords, how to modify the above query?

推荐答案

我使用你的第二个解决方案来解决类似问题。

你可以在包含搜索词的字段中添加一个索引并执行以下操作:



选择srno作为productid,名称+''+说明+''+关键字作为搜索

从ProductDetails作为PD

其中PD。搜索LIKE'%bed%'或PD.search LIKE'%sheet%'



但我建议你是否可以像这样使用



选择srno作为productid,名称+''+说明+''+关键字作为搜索

来自ProductDetails

PD.search喜欢'bed%'或PD.search LIKE's heets%'



以这种方式你没有丢失你的索引
I used your second solution for a similar problems.
You can add a index to the fields containing the word searched and do this :

select srno as productid, name +' '+ descriptions +' '+ keywords as search
from ProductDetails as PD
where PD.search LIKE '%bed%' OR PD.search LIKE '%sheets%'

but I suggest you if it is possible to use only like in this way

select srno as productid, name +' '+ descriptions +' '+ keywords as search
from ProductDetails
where PD.search LIKE 'bed%' OR PD.search LIKE 'sheets%'

in this way you don't lost your index


我觉得你显示去全文索引。



阅读更多来自了解SQL Server中的全文索引 - 简单对话 [ ^ ]。



上面你可以实现模糊搜索算法的近似字符串匹配。
I feel you show go for full text indexing.

Read more from Understanding Full-Text Indexing in SQL Server - Simple Talk[^].

Above to that you can implement fuzzy search algorithm for approximate string matching.


这篇关于在SQL Server中使用字符串的大数据进行搜索的最佳做法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆