Question

I am currently using Irony as part of my search process(not my choice and I don't have a say :P) and there is an issue with using the combination of letters "or" followed by a space and another word, I.E "Orbit Gum" however if you search things like "orbit" or simply "or" on its own it seems to work positively fine.

The error that occurs is

Syntax error near 'gum' in the full-text search condition 'orbit gum'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Syntax error near 'gum' in the full-text search condition 'orbit gum'.

The code being used to generate this part of it is

        //Union with the full text search
        if (!string.IsNullOrEmpty(fTextSearch))
            {
                sql.AppendLine("UNION");
                sql.AppendLine(commonClause);
                sql.AppendLine(string.Format("AND CONTAINS(nt.text, '{0}', LANGUAGE 'English')", fTextSearch));
            }

The actual query that is causing the issue as far as I can see is this line:

AND CONTAINS(nt.text, 'orbit gum', LANGUAGE 'English')
Was it helpful?

Solution

I have found the solution to this myself using a simple bit of Regex, it turns out that you are able to simply add quotation marks onto the beginning and end of the string and it stops it throwing the error.

 fTextSearch = Regex.Replace(fTextSearch, ".*(or|and|etc).*", "\"$&\"");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top