5

In my web application there will be several users. and they have their own contents uploaded to my webapp. For each content they upload it has a title, description and tags(keywords). I can write a search script to search for content or user name. but they keywords when they have given with a spelling mistake it doesn't return any result. For example if there is a user named "Michael" in the database and the search query was "Micheal" i should get "Did you mean to search for 'Michael'" which is none other than a search suggestion.

Also this suggestion should be for the contents uploaded by the user. An user may keep their content's title as "Michael's activities May 2011" and suggestions should be generated for individual words.

4

3 に答える 3

9

SOUNDEXを使用して、次のような類似した名前を検索できます。

SELECT * FROM users WHERE SOUNDEX(name) = SOUNDEX(:input)

またはそのような

SELECT * FROM users WHERE name SOUNDS_LIKE :input

(これは完全に同等です)

編集:Martin Hohenbergが提案したように、Soundex以外のアルゴリズムを使用する必要がある場合は、たとえば、sound_equivalentという名前の列をテーブルに追加する必要があります。(これは、この列にインデックスを付けることができるため、実際にはより効率的なソリューションです)。その場合、リクエストは次のようになります。

SELECT * FROM users WHERE sound_equivalent = :input_sound_equivalent

次に、sound_equivalent列のコンテンツをPHPアルゴリズムで生成し、残りのユーザーパラメーターとともにテーブルに挿入できます。

于 2011-08-27T11:28:46.843 に答える
2

検索結果がない場合は、phpライブラリのpspellを使用して提案を取得することもできます。

于 2011-08-27T11:31:35.447 に答える
0

たぶん、最も一般的な単語のデータベースを作成します (犬、家、都市、数字、水、インターネットなど)。大きくする必要はありません (<10000 ワード)。次に、検索用語を爆発させたら、「単語」データベースで検索用語に似た単語をチェックします。次に、提案をエコーアウトします。

于 2011-08-27T11:23:06.693 に答える