目前正在构建一个知识库应用程序,我对存储和索引文档信息的最佳方式有点不确定。
用户上传文档,当这样做时,从下拉列表中选择一些选项(如类别、主题、区域...,注意这些不都是必需的),他们还输入了一些关键字和文档的描述。此时,所选的类别(和其他类别)将使用categories表中的id作为外键存储在documents表中。我们希望能够做的是,不仅对文档所在的varchar(max)列中的信息执行FREETEXTTABLE或CONTAINSTABLE,而且还对类别名称、主题名称和区域名称等执行FREETEXTTABLE或CONTAINSTABLE。
我查看了创建索引视图的选项,但由于对category列的左连接,这是不可能的。因此,我不确定如何能够做到这一点,任何想法都会非常感谢。
发布于 2010-09-28 17:48:48
我假设你想和这两个搜索一起进行。例如,查找包含文本"foo“的所有文档,并在类别中查找"Automotive Repair”。
也许您不需要对附加数据进行全文输入,只需使用=或like?如果附加数据相当小,则可能无法保证全文的复杂性。
但是,如果要在这两种情况下使用全文,请使用可将结果汇总在一起的存储过程。这里的技巧是阶段性的结果,而不是试图立即返回结果集。
这是一个粗糙的起点。
-- a staging table variable for the document results
declare @documentResults table (
Id int,
Rank int
)
insert into @documentResults
select d.Id, results.[rank]
from containstable (documents, (text), '"foo*"') results
inner join documents d on results.[key] = d.Id
-- now you have all of the primary keys that match the search criteria
-- whittle this list down to only include keys that are in the correct categories
-- a staging table variable for each the metadata results
declare @categories table (
Id int
)
insert into @categories
select results.[KEY]
from containstable (Categories, (Category), '"Automotive Repair*"') results
declare @topics table (
Id int
)
insert into @topics
select results.[KEY]
from containstable (Topics, (Topic), '"Automotive Repair*"') results
declare @areas table (
Id int
)
insert into @areas
select results.[KEY]
from containstable (Areas, (Area), '"Automotive Repair*"') results
select d.text, c.category, t.topic, a.area
from @results r
inner join documents d on d.Id = r.Id
inner join @categories c on c.Id = d.CategoryId
inner join @topics t on t.Id = d.TopicId
inner join @areas a on a.Id = d.AreaId发布于 2010-09-28 21:39:58
您可以为全文索引创建一个新列,该列将包含原始文档以及作为元数据附加的类别。然后,对该列的搜索可以同时搜索文档和类别。您需要发明一种标记系统,使它们在文档中保持唯一性,但标记本身不太可能用作搜索短语。可能是这样的:
This is my regular document text. <FTCategory: Automotive Repair> <FTCategory: Transmissions>https://stackoverflow.com/questions/3811084
复制相似问题