我正在使用 SQL Server FreeTextTable 在项目中进行一些相关性搜索。它对于大多数标准搜索都非常有效,例如:
- 沙发椅 - 搜索一个/和或两个
- “沙发椅” - 搜索短语“沙发椅” '
我也想添加一些布尔搜索功能,例如:
- sofa and chair - 搜索沙发和椅子
- sofa -chair - 搜索适用于沙发,但不适用于椅子
- “绿色沙发” 或 “红色椅子” 来搜索“绿色沙发”或“红色椅子”
我需要在搜索中执行 LIKE/NOT LIKE 短语,然后执行 FreeTextTable为了排名?还有其他方法吗?
I'm using SQL Server FreeTextTable to do some relevance searching in a project. It works really nice for most standard searches, such as:
- sofa chair - to search for one/and or both
- "sofa chair" - to search for the phrase 'sofa chair'
I'd like to add some boolean search capabilities, too, such as:
- sofa and chair - to search for both sofa as well as chair
- sofa -chair - to search for sofa but not chair
- "green sofa" or "red chair" to search for either 'green sofa' or 'red chair'
Will I need to do a LIKE/NOT LIKE phrase in the search and then do a FreeTextTable for ranking? Is there some other way to do it?
发布评论
评论(1)
我认为喜欢/不喜欢是最简单的方法。获取您为搜索而解析的字符串(例如“OR”和“AND”),并动态构建您的查询。同样,如果遇到“-”,则构建 NOT 语句。我认为这不会太困难。
如果您想查看一些可用于 SQL 搜索的高级选项,我知道 MySQL 支持正则表达式字符串,您可以在这里阅读所有相关信息:
http://dev.mysql.com/doc/refman/5.1/en /regexp.html
I think LIKE/NOT LIKE is the easiest way to do it. Take the string you're parsing for the search, like for "OR"'s and "AND"'s, and build your query dynamically. Similarly, if you encounter a '-' build a NOT statement. I don't think it will be too difficult.
If you want to check out some of the advanced options available for SQL searches, I know MySQL supports regex strings, you can read all about it here:
http://dev.mysql.com/doc/refman/5.1/en/regexp.html