0

One of our senior developers uses "+" while performing a freetext search. I am not able to understand the use of it.

I have tried to remove the condition where he used "+" keyword but here was no change in result.

declare @SearchText varchar(100) = 'jack banks'
set @SearchText = REPLACE(LTRIM(RTRIM(@SearchText)), ' ', ' and ')
DECLARE @sText  VARCHAR(50) = (CASE WHEN @searchText <> '' THEN '"' + @searchText + '*"' ELSE @searchText END)
DECLARE @FreeText VARCHAR(50) = (CASE WHEN @searchText <> '' THEN '"'+ @searchText +'\+"' ELSE @searchText END)
select @SearchText,@sText,@FreeText
select * from ServiceProvider as sp where 

Contains(*, @searchText) 
                OR 
                CONTAINS(SP.FirstName,@SText) 
                OR CONTAINS(SP.FirstName,@FreeText)
                OR CONTAINS(SP.LastName,@SText) OR CONTAINS(SP.LastName,@FreeText)

Before removing the condition trying to understand the reason why to use "/+" keyword.

iminiki
  • 2,549
  • 12
  • 35
  • 45
  • where is the '+'? – Ed Bangga Oct 02 '19 at 07:50
  • `\+` isn't a keyword in that SQL, it's `'"\+"'` and *it* is a literal string. Just like `''jack banks'` at the start of your SQL. – Thom A Oct 02 '19 at 07:57
  • check this https://learn.microsoft.com/en-us/sql/t-sql/queries/contains-transact-sql?view=sql-server-2017 – Ed Bangga Oct 02 '19 at 08:00
  • @ϻᴇᴛᴀʟ, I have checked the link you added for reference but I didn't find any query where use the query like I was trying to understand. If you checked the "FreeText" variable in the above-mentioned query. Maybe I overlooked but I didn't find my answer in that article. – AVINASH KUMAR Oct 02 '19 at 08:07
  • @Larnu, this piece of code is already in production so before making any change it will good to double-check. Like I have posted in my question I am finding this condition useful but this was present in most of the free text search queries in my project. – AVINASH KUMAR Oct 02 '19 at 08:11
  • @SMor he is not part of the current organization. Otherwise, I would have discussed it with him. – AVINASH KUMAR Oct 03 '19 at 10:07

0 Answers0