0

希望(并且实际上认为:))有人已经遇到了类似的问题并解决了它..

短期内的基本问题..由于使用“wordsearch”功能和相关数据将在不久的将来迅速增长,我们(在这种情况下是指我)需要改为使用全文搜索..

所以它现在所有设置..但我无法使查询语法工作(下面的简化版本)

declare @searchTerm varchar(256)
set @searchTerm = 'test'

declare @searchValues table (code varchar(900), searchterm varchar(256))
-- this is just for testing, usually the table is prefilled with different codes and values
if(@searchTerm is not null) 
insert into @searchValues
    select code, @searchTerm from dbo.base_question where question_type_id = 'text'

select distinct(a.item_id) 
from dbo.answer_text as a with (nolock)
join dbo.base_question as bqt with (nolock) on bqt.id = a.base_question_id
join @searchValues as st on bqt.code = st.code
where a.value is not null
and not LTRIM(RTRIM(a.value)) = ''
and CONTAINS(a.value, st.searchterm)

where 子句是一个更大的子句的一部分.. 只是猜测我会认为“包含”子句需要一种“静态”搜索词输入,并且不能处理与行相关的值..

在 msdn 和这里都找不到任何东西..

主要问题之一是'base_questions'不是固定的并且可能会改变,并且搜索条件(哪个问题要搜索什么术语)是完全动态的..所以没有switch-case或类似的东西..我认为动态 sql 也不是一个真正的选择(出于不同的原因,但这将远远超出这个问题的范围 :) ..)

但是,对该数据库的所有搜索都是通过带有标量和表值参数(如 @searchValues )的存储过程完成的。如果可能的话,我想保持这种状态

所以任何提示,提示和建议都值得赞赏

和简化数据库结构的仅供参考和完整性的简短版本:

答案( id bigint (PK), item_id uniqueidentifier (FK), base_question_id uniqueidentifier (FK), value nvarchar(max))

base_question ( id uniqueidentifier (PK), code varchar(900), question_type_id (FK), .. descriptive content .. )

item ( id uniqueidentifier (PK), .. 描述性内容 .. )

.. 甚至可以更改数据库结构以使搜索具有一定的性能并再次工作;)..(现在我们有大约 120k item_ids 和大约 2.5 个 mio 答案,但这很容易增加 10 倍甚至更多)

4

0 回答 0