0
我使用下面的查詢的SQL Server全文searh。ASP.NET/sql全文搜索
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
請在這個建議我多列,我現在嘗試與一列。一旦我接下來我會嘗試多列。