使用全文搜索查找精确匹配
使用 Sql Server 2008,如何使用全文搜索来实际找到精确的字符串匹配。我对此感到非常困难,而且我在网上找不到令人满意的解决方案。
例如,如果我正在搜索字符串“Bojan Skrchevski”,我希望第一个结果正是如此。
到目前为止,我已经尝试格式化字符串,如:“Bojan* NEAR Skrchevski*”并调用 CONTAINSTABLE 来获取结果,但该字符串的格式设置为返回更多结果,如 Bojana 和 Bojananana 等。我也尝试按排名排序,但仍然没有成功。
此外,在我的字符串中,我有一个数字序列,例如:“3 1 7”,但使用当前格式,它还会返回“7 1 3”等。
示例:
DECLARE @var varchar(4000);
SET @var = '"Oxford*" NEAR 24 NEAR 7 NEAR 5 NEAR "London*"'
SELECT [Key] FROM CONTAINSTABLE(dbo.[MyTable], [MyField], @var);
我希望能够获得确切的顺序。不会得到“Oxford 7 24 5 London”的结果。
如何格式化字符串才能正确完成此操作?
Using the Sql Server 2008 how can you actually find an exact string match using full-text search. I'm having a real hard time with this and I just couldn't find a satisfactory solution anywhere online.
For example, if I'm searching for the string "Bojan Skrchevski" I want the first result to be exactly that.
So far I've tried formatting the string like: "Bojan* NEAR Skrchevski*" and call CONTAINSTABLE to get results, but this string is formatted to return more results as Bojana and Bojananana etc. I also tried to ORDER BY RANK, but still no success.
Furthermore, in my string I have a number sequence like: "3 1 7", but with the current formatting it also returns "7 1 3" etc.
Example:
DECLARE @var varchar(4000);
SET @var = '"Oxford*" NEAR 24 NEAR 7 NEAR 5 NEAR "London*"'
SELECT [Key] FROM CONTAINSTABLE(dbo.[MyTable], [MyField], @var);
I want to be able to get the exact ordering. Not to get "Oxford 7 24 5 London" as a result.
How do I format the string to accomplish this correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有 2 个选项
1)
这将获得名称中包含 Mountain 的所有项目
2)
这将获得文档中包含这 3 个字符串的所有项目,无论顺序如何
这取决于您真正想要的,但我无法完全理解。
如果我没有抓住重点,请发布一个示例以及结果应该是什么。
·克尔
克里斯托夫
There's 2 options
1)
This will get all items which have Mountain in their name
2)
This will get all items which have these 3 strings in Document no matter what order
It depends on what you really want but I couldn't understand completely.
If I'm missing the point please post a sample and what the result should be.
kr,
Kristof
也许一种方法是通过全文搜索选择多个结果,然后从这些结果中
SELECT
特定的结果。但也许可以有更好的解决方案。我尝试了这个方法并且确实有效。它的工作速度也比仅
SELECT
值要快得多。Perhaps one approach could be to select several results with the full-text search and then
SELECT
the specific one from those results. But maybe there could be a better solution to this.I tried this approach and it actually worked. It also works a lot faster then to just
SELECT
the value.