2009-06-02 24 views
4

データベース内の一連の名前の全文検索を使用しようとしています。これは全文検索を使用する私の最初の試みです。現在、入力された検索文字列を取り、各用語の間にNEAR条件を入れます(「Kings of Leon」の入力フレーズは「Kings NEAR of NEAR Leon」になります)。Sql Server 2005のノイズワードフルテキスト検索

残念なことに、この用語が偽の検索結果になることが判明しました。なぜなら、単語 "of"はノイズワードであるためインデックスを作成するときにSQL Serverによって削除されるためです。したがって、 "Kings Leon"は正しく一致しますが、 "Kings of Leon"は一致しません。

私の同僚は、MSSQL \ FTData \ noiseENG.txtに定義されているすべてのノイズワードを取得し、それらを.Netコードに入れて、フルテキスト検索を実行する前にノイズワードを取り除くことを推奨します。

これが最適なソリューションですか?私のためにこれを行うためにSQLサーバーで変更できる自動マジック設定はありませんか?それとも、ハッキーな気分にならない優れたソリューションですか?

+0

以前のプロジェクトでは、SQL Serverのフルテキスト検索を使用し、ノイズワードをc#で削除しました。 – Kane

答えて

4

フルテキストは、あなたがそれを提供する検索条件で機能しません。ファイルからノイズワードを削除することはできますが、それを行うことでインデックスサイズを大きくする危険性があります。ロバート・カインはこのについて自身のブログ上で良い情報をたくさん持っている:

http://arcanecode.com/2008/05/29/creating-and-customizing-noise-words-in-sql-server-2005-full-text-search/

あなたは、このメソッドはそれらを削除する方法を見て、コードや単語をコピーすることができますいくつかの時間を節約するために:

 public string PrepSearchString(string sOriginalQuery) 
    { 
     string strNoiseWords = @" 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | $ | ! | @ | # | $ | % |^| & | * | (|) | - | _ | + | = | [ | ] | { | } | about | after | all | also | an | and | another | any | are | as | at | be | because | been | before | being | between | both | but | by | came | can | come | could | did | do | does | each | else | for | from | get | got | has | had | he | have | her | here | him | himself | his | how | if | in | into | is | it | its | just | like | make | many | me | might | more | most | much | must | my | never | now | of | on | only | or | other | our | out | over | re | said | same | see | should | since | so | some | still | such | take | than | that | the | their | them | then | there | these | they | this | those | through | to | too | under | up | use | very | want | was | way | we | well | were | what | when | where | which | while | who | will | with | would | you | your | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z "; 

     string[] arrNoiseWord = strNoiseWords.Split("|".ToCharArray()); 

     foreach (string noiseword in arrNoiseWord) 
     { 
      sOriginalQuery = sOriginalQuery.Replace(noiseword, " "); 
     } 
     sOriginalQuery = sOriginalQuery.Replace(" ", " "); 
     return sOriginalQuery.Trim(); 
    } 

しかし、私はおそらくRegex.Replaceと一緒に行くだろうが、これはループよりもはるかに速くなければならない。私はちょうど良い例を投稿する必要はありません。

+1

メソッドの先頭に次の行を追加すると、正しく動作します。sOriginalQuery = "" + sOriginalQuery + ""; これは、検索フレーズの最初または最後の単語である雑音単語の一致を許可するために必要です。 –

0

ここには機能があります。ファイルnoiseENU.txtは、そのまま\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\FTDataからコピーされます。

Public Function StripNoiseWords(ByVal s As String) As String 
     Dim NoiseWords As String = ReadFile("/Standard/Core/Config/noiseENU.txt").Trim 
     Dim NoiseWordsRegex As String = Regex.Replace(NoiseWords, "\s+", "|") ' about|after|all|also etc. 
     NoiseWordsRegex = String.Format("\s?\b(?:{0})\b\s?", NoiseWordsRegex) 
     Dim Result As String = Regex.Replace(s, NoiseWordsRegex, " ", RegexOptions.IgnoreCase) ' replace each noise word with a space 
     Result = Regex.Replace(Result, "\s+", " ") ' eliminate any multiple spaces 
     Return Result 
    End Function