0

我正在尝试进行全文搜索,但在实施时遇到了问题。我有一个可以有多个“标题”的对象。我有一个存储过程,它采用语言和国家,并根据本地化返回具有最佳“标题”的规范化结果。我想要做的是对“标题”表执行全文搜索,该表将搜索所有行,但只返回规范化的默认标题。

为了得到标准化的结果,我有类似的东西

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 链接到的对象,但已使用上述语句进行了规范化。IE 搜索“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
)
4

1 回答 1

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
于 2013-05-30T17:42:58.083 回答