简体   繁体   English

SQL Server全文搜索以查找包含字符

[英]SQL Server Full Text Search to find containing characters

I have a table with a column Document that is FullText Index. 我有一个表,其中有一个Document为全文索引的列。 Let say I have this in this table: 可以说我在这张桌子上有这个:

| ID | Document                    |
| 1  | WINTER  SUMMER SPRING OTHER |

My requirement is to find rows that contains 'ER'. 我的要求是找到包含“ ER”的行。

For this I am querying like this: 为此,我这样查询:

SELECT TOP 100 
    [FullTextSearch].[Document], [FullTextSearch].[ID]
FROM 
    [FullTextSearch] 
WHERE  
    CONTAINS(Document, '"*ER*"')

But this is not working. 但这是行不通的。

Please suggest what should be best way to do this using FullTextSearch. 请提出使用FullTextSearch的最佳方法。

I am expecting id 1 should be returned. 我希望应该返回ID 1。

You can user LIKE operator to find the value. 您可以使用LIKE运算符来查找值。

The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. 在WHERE子句中使用LIKE运算符在列中搜索指定的模式。

There are two wildcards used in conjunction with the LIKE operator: LIKE运算符与两个通配符一起使用:

% - The percent sign represents zero, one, or multiple characters _ - The underscore represents a single character %-百分号表示零个,一个或多个字符_-下划线表示单个字符

Syntax, 句法,

SELECT column1, column2, ... FROM table_name WHERE columnN LIKE pattern; SELECT column1,column2,... FROM table_name WHERE columnN LIKE模式;

This query can help to find the result. 该查询可以帮助找到结果。

SELECT Document,ID FROM FullTextSearch WHERE Document LIKE '%ER%'; 从FullTextSearch中选择文档,ID,其中文档类似于'%ER%';

It's a wildcard query...This should work. 这是一个通配符查询...这应该工作。

 SELECT TOP 100 
[FullTextSearch].[Document], [FullTextSearch].[ID]
FROM 
[FullTextSearch] 
WHERE  
Document like '%ER%'

========OR============= ======== OR =============

   SELECT TOP 100 
        [FullTextSearch].[Document], [FullTextSearch].[ID]
    FROM 
    [FullTextSearch] 
    WHERE  
    CONTAINS(Document, '%ER%')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM