can anyone help to implement the search with misspellins:
There are three instances of people misspelling items. Here is how we should deal with them:
a) One letter anywhere in the word is missing. (in each word, not the whole sentence)
Proper Keyword: "alabama math"
User searches for: "alabam math", "albama math".
In this case a screen will appear where user can click on words "alabama math" he will be taken to the proper search results
Proper Keyword: "french new york"
User searches for: "frnch new york", "frenc new york"
Same logic as "(a)"
b.) There is one or two extra letters. (in each word, not the whole sentence)
Proper keyword: "california guitar"
User searches for: "califroniaa guitar" or "california guittar" of "caalifronia guitarr"
Same logic as "(b)"
c.) One letter word does not match (in each word, not the whole sentence)
Proper keyword: "texas spanish"
User searches for "texis spanish" or "texas spanisj" orf "kexas jpanish"
the table structure is:
tutor_id(primary key)
discipline_option_id(foreing key)
city
state(foreign key)
country(foreign key)
search with misspellings
Moderator: General Moderators
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
You could process the words via pspell to get possible alternatives. The only question is what possible "suggestion" does the user really want.
how to use pspell
please explain how to use pspell
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Follow the link pspell to take you to the manual about how to set it up.
You then need something like(not tested and only to give you an impression)
Key commands are :
pspell_config_create,
pspell_config_mode,
pspell_new_config,
pspell_check and
pspell_suggest.
Hope that gives you are starting point.
You then need something like(not tested and only to give you an impression)
Code: Select all
$pspell_config = pspell_config_create("en");
pspell_config_mode($pspell_config, PSPELL_FAST);
$pspell_link = pspell_new_config($pspell_config);
// break search string up into separate components
preg_match_all("/\b\w+\b/",$search_str,$words);
// step through words and check each one
foreach ($words[0] as $val) {
// if you have numbers in word don't check (only y preference)
if (!preg_match('/[0-9]/',$val)) {
if (!pspell_check($pspell_link, $val)) {
$suggestions = pspell_suggest($pspell_link, $val);
if (count($suggestions)) {
/*
* Need to take each suggestion and do something with it (add it to search whatever)
* Exactly what you want to depends on if you only want the first suggestion or
* multiple and also the method of searching your database whatever.
*/
}
}
}
}pspell_config_create,
pspell_config_mode,
pspell_new_config,
pspell_check and
pspell_suggest.
Hope that gives you are starting point.
1. Get a dictionary of "valid" terms (i.e. download from the web, generate from the existing articles, etc)
2. Split user query into words
3. Check each word against the dictionary
4. For each misspelled word get a replacement
5. (optional but useful) - keep a cache of misspelled words and their corresponding replacements
For 4. see levenshtein() and the related functions.
2. Split user query into words
3. Check each word against the dictionary
4. For each misspelled word get a replacement
5. (optional but useful) - keep a cache of misspelled words and their corresponding replacements
For 4. see levenshtein() and the related functions.