转换用户输入的搜索查询的WHERE子句中使用SQL Server中的全文搜索 [英] Converting user-entered search query to where clause for use in SQL Server full-text search

查看:203
本文介绍了转换用户输入的搜索查询的WHERE子句中使用SQL Server中的全文搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是转换用户输入搜索词,转换成在where子句中使用全文搜索查询表,并取回相关结果查询的最佳方法是什么?例如,下面的查询用户输入:

What's the best way to convert search terms entered by a user, into a query that can be used in a where clause for full-text searching to query a table and get back relevant results? For example, the following query entered by the user:

+"e-mail" +attachment -"word document" -"e-learning"

应该翻译成这样的:

SELECT * FROM MyTable WHERE (CONTAINS(*, '"e-mail"')) AND (CONTAINS(*, '"attachment"')) AND (NOT CONTAINS(*, '"word document"')) AND (NOT CONTAINS(*, '"e-learning"'))

我目前使用的一个查询分析器类,该分析用户输入到查询使用令牌的正则表达式,然后构造从令牌where子句。

I'm using a query parser class at the moment, which parses the query entered by users into tokens using a regular expression, and then constructs the where clause from the tokens.

不过,由于这可能是由很多系统使用全文的共同要求搜索,我很好奇,其他开发人员如何接触过这个问题,是否有做事情的一个更好的方式。

However, given that this is probably a common requirement by a lot of systems using full-text search, I'm curious as to how other developers have approached this problem, and whether there's a better way of doing things.

推荐答案

这可能不是你在寻找什么,但它可能会为您提供一些进一步的想法。

This may not be exactly what you are looking for but it may offer you some further ideas.

HTTP:// WWW .sqlservercentral.com /用品/全文搜索+ +(2008)/ 64248 /

这篇关于转换用户输入的搜索查询的WHERE子句中使用SQL Server中的全文搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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