2010-09-28 110 views
0

當前處於構建知識庫應用程序的中間階段,對於存儲和索引文檔信息的最佳方式有點不確定。關於文檔和相關數據的全文搜索mssql

用戶上傳文件,當這樣做時從下拉列表中選擇多個選項(例如類別,主題,區域...,注意這些並不都是強制性的),他們還輸入一些關鍵字和描述文件。目前選擇的類別(和其他)使用類別表中的ID作爲外鍵存儲在文檔表格中。 我們希望能夠做的是不僅對文檔所在的varchar(max)列內的信息,而且對類別名稱,主題名稱和區域名稱等進行FREETEXTTABLE或CONTAINSTABLE。

我查看了創建索引視圖的選項,但由於LEFT JOIN針對類別列而無法實現。所以我不知道如何去做到這一點,任何想法都將得到最多的讚賞。

回答

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 
0

您可以爲全文索引創建一個新列,其中包含原始文檔以及作爲元數據追加的類別。然後,對該列的搜索可以同時搜索文檔和類別。您需要創建一個標籤系統,使其在文檔中保持唯一性,但標籤本身不可能用作搜索詞組。也許像這樣:

This is my regular document text. <FTCategory: Automotive Repair> <FTCategory: Transmissions> 
+0

一如既往,如果我錯了,我不介意投票。但是,我不喜歡匿名的投票,沒有任何解釋。你能解釋你的反對意見嗎? – 2010-09-29 14:37:58

+0

我不存儲兩次相同的數據是一種可接受的方式,基本上使數據庫中每個文檔的大小翻倍 – Gazeth 2010-10-05 21:59:29

+0

+1 - 無論OP是否實現,這都是一個現實的解決方案。 – JNK 2011-08-08 20:48:07