문제

현재 검색 프로세스의 일부로 아이러니를 사용하고 있습니다 (내 선택이 아님)은 다음과 같습니다 : P) 문자의 조합을 사용하는 문제는 "또는 공간과 다른 단어가 뒤 따른다., 즉 "궤도 껌"이라는 "궤도"또는 단순히 "또는"단순히 "또는"긍정적으로 잘 작동하는 것처럼 보입니다.

발생하는 오류는

입니다.
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')
.

도움이 되었습니까?

해결책

RegEx의 간단한 비트 비트를 사용 하여이 솔루션을 발견 했으므로 인용 부호를 문자열의 시작과 끝에 단순히 추가 할 수 있으며 오류를 던지는 것을 중지합니다.

 fTextSearch = Regex.Replace(fTextSearch, ".*(or|and|etc).*", "\"$&\"");
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top