全文搜索功能允许搜索某一列中相互邻近的多个术语。这称为邻近搜索。要执行邻近搜索,应指定关键字 NEAR 或代字号 (~) 在其中间的两个术语。
对于 NEAR 关键字,可以指定一个整型变量来定义最大距离。例如,term1 NEAR[5]
term2 查找位于 term2 的五个术语范围内的 term1 的实例。术语的顺序并不重要;'term1 NEAR term2'
等效于 'term2 NEAR term1'
。
如果不指定距离,数据库服务器将使用 10 作为缺省距离。
还可以指定代字号 (~) 取代 NEAR 关键字。例如,'term1 ~ term2'
。但是,在使用代字号格式时无法指定距离;此时应用十个术语的缺省值。
不能将短语指定为邻近搜索中的参数。
在邻近搜索中,如果指定前缀术语作为参数,则邻近搜索转换为 AND 表达式。例如,对于 3 元语法词文本索引,搜索 ['red NEAR[1] appl*'
] 相当于搜索 ['red AND "app ppl"'
]。由于这不再是邻近搜索,所以在 CONTAINS 子句中指定了多列的情况下搜索不再限于单一列。
假定要在 MarketingInformation.Description 中搜索含有术语 skin 的 10 个术语中的术语 fabric。此时可以执行以下语句。
SELECT ID, "contains".score, Description FROM MarketingInformation CONTAINS ( Description, 'fabric ~ skin' ); |
ID | score | Description |
---|---|---|
902 | 1.5572371866083279 | <html><head><meta http-equiv=Content-Type content="text/html; charset=windows-1252"><title>Tee Shirt</title></head><body lang=EN-US><p><span
style='font-size:10.0pt;font-family:Arial'>This simple, sleek, and lightweight technical shirt is designed for high-intensity
workouts in hot and humid weather. The recycled polyester fabric is gentle on the earth and soft against your skin.</span></p></body></html> |
由于缺省距离即为 10 个术语,因此不必指定距离。但如果将距离增加一个术语,将返回另一行:
SELECT ID, "contains".score, Description FROM MarketingInformation CONTAINS ( Description, 'fabric NEAR[11] skin' ); |
ID | score | Description |
---|---|---|
903 | 1.5787803210404958 | <html><head><meta http-equiv=Content-Type content="text/html; charset=windows-1252"><title>Tee Shirt</title></head><body lang=EN-US><p><span
style='font-size:10.0pt;font-family:Arial'>A sporty, casual shirt made of recycled water bottles. It will serve you equally
well on trails or around town. The fabric has a wicking finish to pull perspiration away from your skin.</span></p></body></html> |
902 | 2.163125855043747 | <html><head><meta http-equiv=Content-Type content="text/html; charset=windows-1252"><title>Tee Shirt</title></head><body lang=EN-US><p><span
style='font-size:10.0pt;font-family:Arial'>This simple, sleek, and lightweight technical shirt is designed for high-intensity
workouts in hot and humid weather. The recycled polyester fabric is gentle on the earth and soft against your skin.</span></p></body></html> |
ID 903 的分数较高,因为其术语间的距离较近。
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |