1

我正在尝试使用具有最大距离的近邻术语编写全文搜索。

据我所知的语法...

    <custom_proximity_term> ::= 
  NEAR ( 
     {
        { <simple_term> | <prefix_term> } [ ,…n ]
     |
        ( { <simple_term> | <prefix_term> } [ ,…n ] ) 
      [, <maximum_distance> [, <match_order> ] ]
     }
       ) 

      <maximum_distance> ::= { integer | MAX }
      <match_order> ::= { TRUE | FALSE } 

...我应该可以这样使用NEAR

'NEAR(term1,term2,5)'

或者

'NEAR((term1,term2),5)'

但是总是抛出语法错误。

Syntax error near '(' in the full-text search condition 'NEAR((term1, term2), 4, TRUE)'.

即使我尝试从微软示例复制确切的搜索,它也会引发错误:

USE AdventureWorks2012
GO

SELECT DocumentNode, Title, DocumentSummary
FROM Production.Document AS DocTable 
INNER JOIN CONTAINSTABLE(Production.Document, Document,
  'NEAR(bracket, reflector)' ) /* doesn't like this */ AS KEY_TBL
  ON DocTable.DocumentNode = KEY_TBL.[KEY]
WHERE KEY_TBL.RANK > 50
ORDER BY KEY_TBL.RANK DESC
GO

Syntax error near '(' in the full-text search condition 'NEAR(bracket, reflector)'.
4

1 回答 1

3

对于 SQL 2012(Denali) - 语法可能有点混乱,但如果您仔细查看语法,当使用 maximum_distance 或 match_order 时,术语(简单/前缀)必须用额外的括号括起来。

因此,要进行简单的 NEAR 搜索,您将使用 -

SELECT * FROM CONTAINSTABLE(Production.Document, Document, 'NEAR(bracket, reflector)')

并限制您将使用的距离和/或匹配顺序 -

SELECT * FROM CONTAINSTABLE(Production.Document, Document, 'NEAR((bracket, reflector), 1, TRUE)')

刚刚注意到SQL2008 标记。'NEAR'在该版本中的处理方式不同。您可能想要使用的是“term1 NEAR term2”。

于 2012-09-27T21:58:07.537 回答