【发布时间】:2011-06-11 16:52:59
【问题描述】:
我正在尝试将基于关键字分析器的 Lucene.NET 索引替换为基于 SQL Server 2008 R2 的索引。
我有一个表,其中包含我需要查询的自定义索引字段。索引列的值(见下文)是来自一系列 .NET 类型的自定义索引字段的名称/值对的组合 - 实际值是在运行时从属性中提取的,因为结构是未知的。
我需要能够使用 AND 和 OR 搜索集合名称和值对并返回查询匹配的行。
Id Index
====================================================================
1 [Descriptor.Type]=[5][Descriptor.Url]=[/]
2 [Descriptor.Type]=[23][Descriptor.Url]=[/test]
3 [Descriptor.Type]=[25][Descriptor.Alternative]=[hello]
4 [Descriptor.Type]=[26][Descriptor.Alternative]=[hello][Descriptor.FriendlyName]=[this is a test]
一个简单的查询如下所示:
select * from Indices where contains ([Index], '[Descriptor.Url]=[/]');
该查询将导致以下错误:
Msg 7630, Level 15, State 2, Line 1
Syntax error near '[' in the full-text search condition '[Descriptor.Url]=[/]'.
考虑到这一点,我将Index 列中的数据更改为使用| 而不是[ 和]:
select * from Indices where contains ([Index], '|Descriptor.Url|=|/|');
现在,虽然该查询现在有效,但当我运行它时,将返回所有包含 Descriptor.Url 并以 / 开头的行,而不是完全匹配的记录(在这种情况下正好是一条)。
我的问题是,我怎样才能逃避查询以解释 [ 和 ] 并确保只返回 exact 匹配行?
一个更复杂的查询看起来有点像这样:
select * from Indices where contains ([Index], '[Descriptor.Type]=[12] AND ([Descriptor.Url]=[/] OR [Descriptor.Url]=[/test])');
谢谢,
基隆
【问题讨论】:
标签: sql-server indexing lucene.net sql-server-2008-r2 full-text-indexing