如何使用数值的 TSQL FreeText 搜索进行广泛匹配搜索?
我正在尝试对“索尼型号 np-fx110”或“索尼 sz-vgn770N 便携包”或“华硕笔记本电脑型号 g60v”等术语进行免费文本搜索。
我知道自由文本将数字视为噪音,因此我想我应该从噪音 SQL Server 2008noiseENU.txt 文件中编辑掉数字,但我无法在我的服务器上找到任何噪音文件。
FTData 目录仅包含一堆 2kb 的 xml 文件和一个空的 FilterData 文件夹。
我有一个 split 函数,它将返回给定字符串中带有空格分割字符的所有单词。我需要一个 CTE,它将连接 SPLIT() 函数返回的每个单词的 AND 文本。
> SELECT * FROM MyTable WHERE
> Description LIKE '%asus%' AND
> Description LIKE '%laptop%' AND
> Description LIKE '%model%' AND
> Description LIKE '%g60v%'
本质上,型号可以位于描述字段中的任何位置。我可以轻松地执行“LIKE [型号]”操作,但是我希望将其与描述中包含的其他单词相匹配。
这似乎不是最佳方法,但可行。任何有关如何解决此问题的其他建议将不胜感激。
谢谢。
更新
这是运行“exec sp_help_fulltext_catalogs”的结果
> ftcatid:5 NAME: CTIMytemDataCatalog
> PATH: NULL
> STATUS: 0
> NUMBER_FULLTEXT_TABLES: 1
更新
当型号只是一个数字时,例如“iphone 4”中的“4”,就会出现问题。
我已经动态构建一个 CONTAINS 查询,在每个术语之间插入 AND。然而,这里有一些问题:
> **WHERE CONTAINS(*, 'iphone AND 4 AND battery')** - returns 0 results
> **WHERE FREETEXT(*, 'iphone 4 battery')** - is matching for iphone
> OR battery which is sub-optimal
> **WHERE CONTAINS(*, '"iphone 4" AND "battery"')** - returns the most
> accurate result set
鉴于这些发现,我认为我应该在表中维护这些“特殊情况”的列表,并基于此动态生成我的 CONTAINS 查询。
关于这种方法有什么建议吗?
I am trying to do a free text search on terms like "sony model number np-fx110" or "carrying case for sony sz-vgn770N" or "asus laptop model g60v".
I know that freetext treats numbers like noise, so I figured I would edit out numbers from the noise SQL Server 2008 noiseENU.txt file but I'm unable to locate any noise files on my server.
The FTData directory only contains a bunch of 2kb xml files and an empty FilterData folder.
I've got a split Function that will return all words in a given string with a split character of a space. I need a CTE that will concatenate the AND text for each word in returned from the SPLIT() function.
> SELECT * FROM MyTable WHERE
> Description LIKE '%asus%' AND
> Description LIKE '%laptop%' AND
> Description LIKE '%model%' AND
> Description LIKE '%g60v%'
Essentially the model number can be anywhere in the description field. I can easily do a LIKE [model number], however I would want to match that up with other words contained in the description.
This doesn't seem like an optimal approach, but workable. Any other suggestions on how to tackle this would be appreciated.
Thanks.
UPDATE
Here is the result of running "exec sp_help_fulltext_catalogs"
> ftcatid:5 NAME: CTIMytemDataCatalog
> PATH: NULL
> STATUS: 0
> NUMBER_FULLTEXT_TABLES: 1
UPDATE
A problem arises when the model number is simply a number, such as "4" in "iphone 4".
I am already dynamically building a CONTAINS query, inserting AND in between each term. However, here are some issues:
> **WHERE CONTAINS(*, 'iphone AND 4 AND battery')** - returns 0 results
> **WHERE FREETEXT(*, 'iphone 4 battery')** - is matching for iphone
> OR battery which is sub-optimal
> **WHERE CONTAINS(*, '"iphone 4" AND "battery"')** - returns the most
> accurate result set
Given these findings I'm thinking that I should maintain a list of these "special cases" in a table, and generate my CONTAINS query dynamically based on this.
Any suggestions about this approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用全文索引?
你是正确的,SQL默认将“1”或“2”视为噪音(你可以更改它)......但它应该发现“g60v”或“sz-vgn770N”没有问题。我以类似的方式使用 FTS 搜索 ISBN 的图书目录,效果很好。
最后,我在这一点上可能是错的......但我认为在您实际构建/使用 FTS 之前不会创建噪声文件。
另请注意,搜索 FTS 与使用 like 语句不同。 阅读使用联机图书搜索 FTS 的不同方法(如果您)不熟悉语法。
像这样的查询应该可以满足您的需求:(我如何在图书目录搜索中使用 FTS)
在此处阅读有关自由文本查询的更多信息:http://msdn.microsoft.com/en-us/library/ms176078.aspx
Have you tried using a full text index?
You are correct that SQL treats "1" or "2" as noise by default (you can change this)... but it should find "g60v" or "sz-vgn770N" no problem. I have used FTS in similar fashion searching a catalog of books by ISBN and it worked fine.
Lastly, I may be wrong on this one... but I don't think the noise file gets created until you actually build/use FTS.
Also note that searching FTS isn't similar to using a like statement. Read up on the different methods for searching FTS with Books Online if you're not familiar with the syntax.
A query like this should work for your needs: (how I use FTS with my book catalog search)
Read more about freetext queries here: http://msdn.microsoft.com/en-us/library/ms176078.aspx