0

私は現在、検索プロセスの一部としてIronyを使用しています(私の選択ではなく、:Pとは言えません)。文字「または」の後にスペースと別の単語「IE」を組み合わせて使用​​すると問題が発生します。ただし、「Orbit Gum」を検索すると、「orbit」や単に「or」などを検索すると、問題なく機能するようです。

発生するエラーは

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 に答える