0

Currently in the middle of building a knowledge base app and am a bit unsure on the best way to store and index the document information.

The user uploads the document and when doing so selects a number of options from dropdown lists (such as category,topic,area..., note these are not all mandatory) they also enter some keywords and a description of the document. At the moment the category (and others) selected is stored as foreign key in the documents table using the id from the categories table. What we want to be able to do is do a FREETEXTTABLE or CONTAINSTABLE on not only the information within the varchar(max) column where the document is located but also on the category name, topic name and area name etc.

I looked at the option of creating an indexed view but this wasn't possible due to the LEFT JOIN against the category column. So I'm not sure how to go about being able to do this any ideas would be most appreciated.

4

2 回答 2

0

我假设您想将这两个搜索结合在一起。例如,在“汽车维修”类别中查找包含文本“foo”和的所有文档。

也许您不需要全文附加数据,只需使用 = 或喜欢?如果附加数据相当小,则可能不保证全文的复杂性。

但是,如果您想对两者都使用全文,请使用存储过程来为您将结果汇总在一起。这里的诀窍是暂存结果,而不是试图立即返回结果集。

这是一个粗略的起点。

-- 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-28T09:48:48.330 回答
0

您可以为全文索引创建一个新列,该列将包含原始文档以及作为元数据附加的类别。然后对该列的搜索可以同时搜索文档和类别。您需要发明一个标签系统,使它们在您的文档中保持唯一,但标签本身不太可能用作搜索短语。也许是这样的:

This is my regular document text. <FTCategory: Automotive Repair> <FTCategory: Transmissions>
于 2010-09-28T13:39:57.723 回答