问题
I'm attempting to do a keyword search which requires all conditions to be met for a result to be shown. I've created a method of making a custom table from a string which stores all of the keywords which are currently required for this search.
I've been able to get it to happen for 'or' using the following
dbo.MultipleTextSearchValuesOR - Is used to make the table of keywords
select Title from vwIncidentSearchView inner join dbo.MultipleTextSearchValuesOR('Testing|Check') on Title Like id
This works great but can't seem to work it out for 'and' (e.g. result must have 'Testing' and 'Check').
Any help would be appreciated
回答1:
I've figured it out. The way it had to be done was using a cross apply with a function splitting the string into a table.
Then the entries must be grouped by all the fields. Finally they must be checked to see if it meets all the required keywords.
I do realise this is quite a messy method along with it not beingthe most optimized method so if anyone else has any suggestions to improving performance it would be appreciated
Example:
declare @where nvarchar(max)
declare @TitleLikeClause nvarchar(max)
declare @Title nvarchar(max)
set @Title = 'Down&Email'
SELECT
Referenceid,
Title
FROM vwIncidentSearchView
cross apply
(select
Data
from Split(@Title, '&') candidate
where
Title Like candidate.Data) t2o group by Referenceid, Title having count(*) = (select max(ID) from Split(@Title, '&'))
来源:https://stackoverflow.com/questions/65110404/select-entries-that-fulfil-requirements-laid-out-by-dynamic-table