【问题标题】:ASP.NET/sql full text searchASP.NET/sql 全文搜索
【发布时间】:2013-08-19 19:54:47
【问题描述】:

我正在使用以下查询来进行 sql server 的全文搜索。

    DECLARE @MyTable TABLE (Id int identity(1,1), Searched varchar(200))
DECLARE @Keys    TABLE (Word varchar(200), WordId int identity(1,1))

INSERT INTO @MyTable VALUES ('Mother Father Daughter Son')
INSERT INTO @MyTable VALUES ('Mother Daughter Son')
INSERT INTO @MyTable VALUES ('Mother Son')
INSERT INTO @MyTable VALUES ('Daughter Son')
INSERT INTO @MyTable VALUES ('Mother Father Son')
INSERT INTO @MyTable VALUES ('Son Daughter Father')
INSERT INTO @MyTable VALUES ('Mother bun')
INSERT INTO @MyTable VALUES ('Other Word')


INSERT INTO @Keys VALUES ('Mother')
INSERT INTO @Keys VALUES ('Father')
INSERT INTO @Keys VALUES ('Son')
INSERT INTO @Keys VALUES ('Daughter')

DECLARE @nAllWords int
SELECT @nAllWords = COUNT(*) FROM @Keys

SELECT MyTable.*
FROM @MyTable MyTable
INNER JOIN (SELECT MyTable.Id
                   FROM @MyTable MyTable
            INNER JOIN @Keys KeyWords ON ' ' + MyTable.Searched + ' ' LIKE '% ' + KeyWords.Word  + ' %'
            GROUP BY MyTable.Id
            HAVING COUNT(Distinct(KeyWords.Word)) = @nAllWords) Tbl1 ON MyTable.Id = Tbl1.Id

但是上面的代码只返回一个以下的单个记录。

Mother Father Daughter Son

我需要完整的 4 个单词(母亲父亲女儿儿子),下一个任何 3 个单词(母亲女儿儿子),下一个任何 2 和下一个 1 所以我的结果像

Mother Father Daughter Son
Mother Daughter Son
Mother Father Son
      :
      :

Mother bun

请就多列向我提出建议,我现在正在尝试一列。一旦我得到这个,接下来我将尝试多列。

【问题讨论】:

    标签: asp.net sql-server linq


    【解决方案1】:

    如果您从查询中删除以下代码,它将给出所需的结果!

    HAVING COUNT(Distinct(KeyWords.Word)) = @nAllWords
    

    【讨论】:

      猜你喜欢
      • 2010-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-03
      • 2011-12-06
      • 1970-01-01
      • 2023-03-18
      • 2011-06-10
      相关资源
      最近更新 更多