我假設你想和兩個搜索結合在一起。例如,查找所有包含文本「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-29 14:37:58
我不存儲兩次相同的數據是一種可接受的方式,基本上使數據庫中每個文檔的大小翻倍 – Gazeth 2010-10-05 21:59:29
+1 - 無論OP是否實現,這都是一個現實的解決方案。 – JNK 2011-08-08 20:48:07