0

我目前正在使用 Irony 作为我的搜索过程的一部分(不是我的选择,我没有发言权:P),并且使用字母“或”后跟空格和另一个单词 IE 的组合存在问题Orbit Gum”但是,如果您单独搜索“orbit”或仅“或”之类的东西,它似乎可以正常工作。

发生的错误是

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'.

用于生成这部分的代码是

        //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));
            }

据我所知,导致问题的实际查询是这一行:

AND CONTAINS(nt.text, 'orbit gum', LANGUAGE 'English')
4

1 回答 1

0

我自己使用一些简单的正则表达式找到了解决方案,事实证明您可以简单地在字符串的开头和结尾添加引号,它会阻止它抛出错误。

 fTextSearch = Regex.Replace(fTextSearch, ".*(or|and|etc).*", "\"$&\"");
于 2012-07-27T14:11:30.167 回答