2012-07-27 2 views
0

현재 아이러니를 검색 프로세스의 일부로 사용하고 있습니다 (선택 사항이 아니며 말 : P가 없음). 문자 조합을 사용하는 데 문제가 있습니다 "또는"뒤에 공백과 다른 단어, IE "궤도 잇몸"그러나 "궤도"또는 단순히 "또는"같은 것들을 자체적으로 검색하면 긍정적으로 잘 작동하는 것 같습니다. 이"or"를 문자열에 포함 할 때 구문 오류가 발생했습니다.

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

까지 I시피 문제를 일으키는 실제 쿼리 이쪽된다

발생 오류

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

인 코드는이 부분을 생성하기 위해 사용되는 줄 :

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

는 http://stackoverflow.com/questions/9435119/syntax-error-near-of-in-the-full-text-search-condition-control- ([아마 당신은 큰 따옴표로 필요] of) – V4Vendetta

+0

오 세상에. 왜 당신은 12 개의'AppendLine' 절 대신 하나의 문자열에 쿼리를 넣지 않습니까? – CodesInChaos

+0

"일반"sql 쿼리에서 나는 마지막 행에서'AND nt.text LIKE '% orbit gum %''를 사용합니다. – Alex

답변

0

나는이 솔루션을 간단한 Regex 비트를 사용하여 찾았습니다. 문자열의 시작과 끝 부분에 따옴표를 간단히 추가 할 수 있으며 오류가 발생하는 것을 막을 수 있습니다.

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