全文検索に最も近い一致
-
19-08-2019 - |
質問
単語を誤入力した場合にユーザーを正しい方向に向けることができるWebサイトの内部検索を実装しようとしています。 >
そのような検索をどのように行うことができるか、誰にもわかりませんか?ユーザーが検索することを意図した単語またはフレーズの関連性をどのように確立できますか?
- i asp.netとSQL Server 2005をFTS(fullTextSearch)で使用します
ありがとう
解決
文字列の類似性を判断するアルゴリズムを使用して、検索インデックスから特定の差まで他の文字列を提案できます。
これらのアルゴリズムの1つは、レーベンシュタイン距離です。
ただし、既存のソリューションの検索を忘れないでください。例えば Lucene には、類似の文字列を検索する機能があります。
ところで、このトピックに関する関連記事は次のとおりです。方法Google <!>#8220;という意味ですか?<!>#8221;アルゴリズムは動作しますか
他のヒント
これは、フレーズに一致する最も近いキーワードを正規表現を使用して照会します。
こちらは、役に立つかもしれない素晴らしい記事です。
T-SQLを使用すると、 SOUNDEX
を使用できます。音声的に単語を比較する関数。
ユーザーの入力を受け取り、それをデータベース内の他の単語とsoundexコードで比較すると、「どういう意味ですか?」のリストを作成できるはずです。言葉。
E.g。
select SOUNDEX('andrew')
select SOUNDEX('androo')
両方とも同じ出力(A536)を生成します。
最近、より良いアルゴリズムがありますが、soundexはSQLサーバーに組み込まれています。
考えられる最も簡単なアプローチは、2つの単語間の不一致の程度を返す関数を作成し、すべての単語をループして最適なものを見つけることです。
これは、分岐限定メソッドで実行しました。コードを掘り下げてみましょう:
bool matchWithinBound(char* a, char* b, int bound){
// skip over matching characters
while(*a && *b && *a == *b){a++; b++;}
if (*a==0 && *b==0) return true;
// if bound too low, quit
if (bound <= 0) return false;
// try assuming a has an extra character
if (*a && matchWithinBound(a+1, b, bound-1)) return true;
// try assuming a had a letter deleted
if (*b && matchWithinBound(a, b+1, bound-1)) return true;
// try assuming a had a letter replaced
if (*a && *b && matchWithinBound(a+1, b+1, bound-1)) return true;
// try assuming a had two adjacent letters swapped
if (a[0] && a[1]){
char temp;
int success;
temp = a[0]; a[0] = a[1]; a[1] = temp;
success = matchWithinBounds(a, b, bound-1);
temp = a[0]; a[0] = a[1]; a[1] = temp;
if (success) return true;
}
// can try other modifications
return false;
}
int DistanceBetweenWords(char* a, char* b){
int bound = 0;
for (bound = 0; bound < 10; bound++){
if (matchWithinBounds(a, b, bound)) return bound;
}
return 1000;
}
Googleのパワーを使用しないのはなぜですか。提案サービスを利用できます
ここはc#
の例です