我正在尝试进行全文搜索但是在实现它时遇到了问题。我有一个可以有多个“标题”的对象。我有一个存储过程,它采用语言和国家/地区,并根据本地化返回具有最佳“标题”的标准化结果。 我希望能够做的是在“标题”表上执行全文搜索,该表将搜索所有行,但只返回标准化的默认标题。
为了获得标准化结果,我有类似
的内容NORMALIZING STATEMENT
SELECT MainObject.*, Title.Name, Description.Name
FROM MainObject
OUTER APPLY
(
SELECT TOP 1 Title.Name
FROM Title
WHERE Title.MainObject_ID = MainObject.ID AND Title.Language = @language
ORDER BY Title.[Default] DESC
)
OUTER APPLY
(
SELECT TOP 1 Description.Name
FROM Description
WHERE Description.MainObject_ID = MainObject.ID AND Description.Language = @language
ORDER BY Description.[Default] DESC
)
假设一个对象有3个标题,Alpha,Bravo和Charlie,Alpha是默认标题。 我希望能够对Bravo进行全文搜索。找到Bravo链接到的对象,但使用上述语句进行标准化。 I.E搜索“Bravo”和“Alpha”作为Title.Name返回。
我能想到的唯一方法是首先执行搜索,例如
FULL-TEXT STATEMENT
SELECT Title.MainObject_ID, MAX(KEY_TBL.RANK)
FROM Title
INNER JOIN
FREETEXTTABLE(Title,Name,'Some Search') AS KEY_TBL
ON Title.ID = KEY_TBL.[KEY]
WHERE KEY_TBL.RANK >= 50
GROUP BY Title.MainObjectID, KEY_TBL.RANK
ORDER BY KEY_TBL.RANK DESC
返回MainObjects列表。然后我可以通过top语句来运行它们。有没有办法将两者结合在一个更优雅的庄园中,从而获得更好的表现?
更新: 我可以在全文语句中执行WHERE IN,但我不确定如何将RANK返回到主语句,这样我就可以通过降序RANK来排序最终输出。
NORMALIZING STATEMENT
WHERE MainObject.ID IN
(
FULL-TEXT STATEMENT
)
答案 0 :(得分:0)
我最终到达那里......我开始在“标题”表上进行全文搜索,然后将其连接到MainObject表并从那里继续。我必须按照我想要选择的所有内容进行分组。
SELECT MainObject.ID, MAX(KEY_TBL.RANK) AS IndexRank, MainObject.OtherColumns, Title.Name, Description.Name
FROM Title AS FT_TBL
INNER JOIN
FREETEXTTABLE(Title,Name,'Some Search') AS KEY_TBL
ON FT_TBL.ID = KEY_TBL.[KEY]
INNER JOIN
MainObject ON FT_TBL.MainObjectID = MainObject.ID
OUTER APPLY
(
SELECT TOP 1 Title.Name
FROM Title
WHERE Title.MainObject_ID = MainObject.ID AND Title.Language = @language
ORDER BY Title.[Default] DESC
)
OUTER APPLY
(
SELECT TOP 1 Description.Name
FROM Description
WHERE Description.MainObject_ID = MainObject.ID AND Description.Language = @language
ORDER BY Description.[Default] DESC
)
GROUP BY MainObject.ID, KEY_TBL.RANK, MainObject.OtherColumns, Title.Name, Description.Name
ORDER BY IndexRank desc