OK, I settled for my previous solution until I had time to have a re-think / wait for it to become a problem.
The old method is now taking too long to execute forcing me to find an alternative solution.
After some playing the best solution I have found (in terms of length of execution time) is to cursor it....
I therefore set up a cursor for the phrase I want to search the text for and blitz through it populating a temp table with the phrase IDs which match as I go.
Key thing to use FAST_FORWARD and FORWARD_ONLY settings to maximize performance.
Once done, I simply join my temp table back to my db tables to return whatever details of the phrases I need.
Example code below:
DECLARE @PageText nvarchar(max) -- parameter of page text
CREATE TABLE #Matches (PhraseID int)
DECLARE @PhraseID int
DECLARE @PhraseText nvarchar(100)
DECLARE curMatchingPhrases CURSOR FAST_FORWARD FORWARD_ONLY FOR
SELECT p.PhraseID,
p.PhraseText
FROM Phrases p
OPEN curMatchingPhrases
FETCH NEXT FROM curMatchingPhrases INTO @PhraseID, @PhraseText
WHILE @@FETCH_STATUS = 0
BEGIN
IF EXISTS (SELECT 'match' WHERE @PageText LIKE '% ' + @PhraseText + ' %')
BEGIN
INSERT #Matches SELECT @PhraseID
WHERE @PhraseID NOT IN (SELECT PhraseID FROM #Matches)
END
FETCH NEXT FROM curMatchingPhrases INTO @PhraseID, @PhraseText
END
CLOSE curMatchingPhrases
DEALLOCATE curMatchingPhrases
SELECT * FROM #Matches
DROP TABLE #Matches
I'm sure others on here will be able to find more elegant solutions, but the cursor has reduced a 6+sec SP down to 0 - 1sec for me, so I'm happy for now.
Mojo