FullText search with CONTAINS on multiple columns and predicate - AND

前端 未结 1 898
囚心锁ツ
囚心锁ツ 2020-12-28 16:35

I have a search table with, say, 4 columns of text data to search.

I do something like this:

SELECT * FROM dbo.SearchTable
WHERE CONTAINS((co1, col2,         


        
相关标签:
1条回答
  • 2020-12-28 17:16

    This should work:

    SELECT * FROM dbo.SearchTable
    WHERE CONTAINS((co1, col2, col3, col4), 'term1')
    AND CONTAINS((co1, col2, col3, col4), 'term2');
    

    Alternatively, you could add a new computed column with a full text index on it. Add a column like this:

    computedCol AS col1 + ' ' + col2 + ' ' + col3 + ' ' + col4
    

    And create the full text index:

    CREATE FULLTEXT INDEX ON SearchTable (computedCol LANGUAGE 1033)
    KEY INDEX pk_SearchTable_yourPrimaryKeyName
    

    Then you can do this:

    SELECT * FROM dbo.SearchTable
    WHERE CONTAINS(*, 'term1 AND term2')
    
    0 讨论(0)
提交回复
热议问题