आप इस के लिए एक stemmer साथ संयोजन के रूप में Doctrine Inflector वर्ग विचार कर सकते हैं के लिए लिखा जा सकता है।
यहाँ एक उच्च स्तर पर एल्गोरिथ्म
- रिक्त स्थान पर स्प्लिट खोज स्ट्रिंग, प्रक्रिया शब्द अलग-अलग
- छोटे खोज शब्द
- पट्टी विशेष वर्ण
- Singularize, वाइल्डकार्ड के साथ differing portion की जगह ('है % ')
- स्टेम, वाइल्डकार्ड ('% ')
012 के साथ अलग-अलग हिस्से को प्रतिस्थापित करें
यहाँ समारोह मैं कई परीक्षण तार
Input String: Mary's Hamburgers
SearchString: SELECT * FROM LIST2 WHERE LOWER(some_field) LIKE 'mary% hamburger%';
Input String: Office Supplies
SearchString: SELECT * FROM LIST2 WHERE LOWER(some_field) LIKE 'offic% suppl%';
Input String: Accounting department
SearchString: SELECT * FROM LIST2 WHERE LOWER(some_field) LIKE 'account% depart%';
शायद
सही नहीं के साथ एक साथ रखा
/**
* Use inflection and stemming to produce a good search string to match subtle
* differences in a MySQL table.
*
* @string $sInputString The string you want to base the search on
* @string $sSearchTable The table you want to search in
* @string $sSearchField The field you want to search
*/
function getMySqlSearchQuery($sInputString, $sSearchTable, $sSearchField)
{
$aInput = explode(' ', strtolower($sInputString));
$aSearch = [];
foreach($aInput as $sInput) {
$sInput = str_replace("'", '', $sInput);
//--------------------
// Inflect
//--------------------
$sInflected = Inflector::singularize($sInput);
// Otherwise replace the part of the inflected string where it differs from the input string
// with a % (wildcard) for the MySQL query
$iPosition = strspn($sInput^$sInflected, "\0");
if($iPosition !== null && $iPosition < strlen($sInput)) {
$sInput = substr($sInflected, 0, $iPosition) . '%';
} else {
$sInput = $sInput;
}
//--------------------
// Stem
//--------------------
$sStemmed = stem_english($sInput);
// Otherwise replace the part of the inflected string where it differs from the input string
// with a % (wildcard) for the MySQL query
$iPosition = strspn($sInput^$sStemmed, "\0");
if($iPosition !== null && $iPosition < strlen($sInput)) {
$aSearch[] = substr($sStemmed, 0, $iPosition) . '%';
} else {
$aSearch[] = $sInput;
}
}
$sSearch = implode(' ', $aSearch);
return "SELECT * FROM $sSearchTable WHERE LOWER($sSearchField) LIKE '$sSearch';";
}
कौन सा मैं भाग गया है, लेकिन यह एक अच्छी शुरुआत वैसे भी है! जहां यह गिरावट आती है वह तब होती है जब एकाधिक मिलान लौटाए जाते हैं। सर्वश्रेष्ठ मैच निर्धारित करने के लिए कोई तर्क नहीं है। यही वह जगह है जहां MySQL fulltext और Lucene जैसी चीजें आती हैं। इसके बारे में कुछ और सोचकर, आप इस दृष्टिकोण के साथ कई परिणामों को रैंक करने के लिए levenshtein का उपयोग करने में सक्षम हो सकते हैं!
मुझे पता है कि यह एक पुराना धागा है, लेकिन मैंने अभी एक जवाब जोड़ा है, अगर आपके पास एक मिनट है तो आप क्या सोचते हैं। पोर्टर स्टेमिंग रिसर्च पर मुझे शुरू करने के लिए – quickshiftin