通过全文搜索实现存储过程的最佳方法
我想使用 MSSQL 全文引擎运行搜索,其中给出以下用户输入: “好莱坞广场”
我希望结果中同时包含好莱坞和广场。
我可以在 Web 服务器(C#、ASP.NET)上创建一个方法来动态生成如下所示的 sql 语句:
SELECT TITLE
FROM MOVIES
WHERE CONTAINS(TITLE,'"hollywood*"')
AND CONTAINS(TITLE, '"square*"')
很简单。 但是,我希望在存储过程中这样做,以提高速度优势和添加参数的安全性。
我可以一边吃蛋糕一边吃吗?
I would like to run a search with MSSQL Full text engine where given the following user input:
"Hollywood square"
I want the results to have both Hollywood and square[s] in them.
I can create a method on the web server (C#, ASP.NET) to dynamically produce a sql statement like this:
SELECT TITLE
FROM MOVIES
WHERE CONTAINS(TITLE,'"hollywood*"')
AND CONTAINS(TITLE, '"square*"')
Easy enough. HOWEVER, I would like this in a stored procedure for added speed benefit and security for adding parameters.
Can I have my cake and eat it too?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过在字符串中使用 AND 逻辑运算符? 我将一个原始字符串传递给我的存储过程,并在单词之间填充“AND”。
http://msdn.microsoft.com/en-us/library/ms187787。 ASPX
Have you tried using the AND logical operator in your string? I pass in a raw string to my sproc and stuff 'AND' between the words.
http://msdn.microsoft.com/en-us/library/ms187787.aspx
我同意上面的观点,查看 AND 子句
但是您不必分割输入句子,您可以
顺便 使用变量
搜索确切的术语(包含)
搜索短语中的任何术语(自由文本)
I agreed with above, look into AND clauses
However you shouldn't have to split the input sentences, you can use variable
by the way
search for the exact term (contains)
search for any term in the phrase (freetext)
上次我不得不这样做(使用 MSSQL Server 2005)时,我最终将整个搜索功能转移到了 Lucene(Java 版本,尽管我相信 Lucene.Net 现在已经存在)。 我对全文搜索寄予厚望,但这个具体问题让我非常恼火,我放弃了。
The last time I had to do this (with MSSQL Server 2005) I ended up moving the whole search functionality over to Lucene (the Java version, though Lucene.Net now exists I believe). I had high hopes of the full text search but this specific problem annoyed me so much I gave up.