سؤال فيما يخص تحسين البحث عن الداتا
- mohammed_alshobaki96
- 2019-01-27T11:47:22+00:00
لقد كنت في مقابلة عمل فيما يخص تطوير الويب، وسُئلت سؤالا لم اجب عليه بدقة وهو كالآتي :
اذا كان لدينا موقع لغته انجليزية بالكامل مع الداتا، وأتى شخص ادخل في حقل البحث كلمة عربية ك مثال 'إلكترون'، ولا يوجد في الداتابيس كلمة الكترون بالعربي لكن يوجد مرادف لها بالانجليزية 'electron'، ما هي الطريقة المناسبة لجعله يأتي بالنتائج التي تحتوي على كلمة elctron بالانجليزي والشخص بحثَ عن كلمة إلكترون بالعربي؟
اجابتي ربما كانت غير دقيقة، لكنها كانت كالاتي :
نعمل function يستقبل كلمة البحث، ونفحص اذا كانت الاحرف عربية باستخدام الاسكي كود، ونجعل كل حرف عربي مقابله شبيهه بالانجليزية مثلاً : ك -> k
وهكذا mapping، ربما ليست دقيقة بشكل كبير لكنها ستفي بالغرض.
سؤالي، هل يوجد طُرق اكثر كفاءة وتفي بالغرض بشكل سليم؟ :)
وشكرًا
إجابتي لهذا السؤال تختلف قليلا عن اجابتك ،مشكلة اجابتك انه فعّالة على الكلمات المعربة او الكلمات التي تتساوي باللغتين ، لكن لو كانت الكلمة عربي اصيلة مثل كلمة ( مكاتب ) حينها لن تنفع .
الحل في أنظمة البحث والفلترة بشكل عام شبه موحد ، يمكنك الإستفادة كالتالي :
لو كانت محتويات قاعدة البيانات عربي فقط :
وحّد المدخلات الى قاعدة البيانات عبر تحديد نمط معين للحروف الشائعه مثل توحيد شكل الهمزة على الألف (أ ، إ ، آ ) والتاء المربوطة ( ه ، ة ) وغيرها من الحروف
في حال كنت تستخدم كلمات مفتاحية tags في تسهيل البحث ، اذ لا يجب عليك تخزينها بصورتها الاساسية ، في الحقيقة هذا خطأ شائع ، لكي تستفيد من ال tags باقصى درجة يجب عليك تخزين جذر ال tag وليس نفسه ، مثلا لو كان الtag كلمة ( مكاتب ) ، عليك تخزينها كـ (كتب) ، وعند البحث تقوم بتجذير الكلمة ، حينها عند قيام المستخدم بالبحث عن اي كلمة من مشتقات الجذر ( كتب ) سيظهر له شيء يتعلق بها ، في الحقيقة هذا جزء اساسي من اساسيات استرجاع البيانات في محركات البحث
العمليه الإخرى هي القيام بإزاله الحركات اثناء البحث واثناء الاسترجاع
وغيرها .
في حالتك :
قم بإستخدام api للترجمه ومن خلالها يتم البحث
وسيقوم بإرجاع النتائج ، وبناء عليها استخدم ما سبق .
الموضوع دا شدني لما كنت ببحث في olx كنت بكتب لادا فبيظهري اللي مكتوب lada
المهم , فيه طريقتين الطريقة الأبسط زي مانته قولت , عن طريق mapping او اسمها نقحرة , تحويل الحروف العربي للاتيني وبعدين بإستخدام دالة زي soundex او metaphone بيحول النصوص لقيم
دي الفانكشن اللي كنت عاملها
بما أنهم لم يأتوا على ذكر سرعة البحث كشرط
خطر لي فكرة وهي تحويل الكلمة العربية إلى صوت من خلال أداة قاريء آلي عربي، والمخرج الصوتي يتم إدخاله إلى أداة تحويل الصوت إلى كلام أجنبي، فتحصل على المقابل الصوتي للكلمة وتبحث عنها.
ربما يعترض أحدهم أنها طريقة طويلة، لكن أنا ذكرتها بعد إغفال عامل السرعة، وأيضا نظرا للتطور الكبير في سرعة ودقة نتائج الأدوات الصوتية.
ابحث عن برنامج ابو الحروف :) قمت بها في عام 2007:)
اليك فنكشن دلفي / باسكال
function ArabicAlf( mytext : string ) : string;
var
MyArray : ArrOfStr;
i : Integer;
FinalString : string;
text : string;
begin
MyArray := explode( ' ', mytext );
conv2arabic.Memo2.Text := '';
for i := 0 to High( MyArray )do
begin
if IsInteger( MyArray[ i ] ) = 0 then
begin
text := trim(MyArray[ i ]);
text := ReplaceRegExpr( '[3al]+[uay]k[ou][mn]', text, 'عليكم', True );
text := ReplaceRegExpr( 'm[ar]+[h7ab]+a', text, 'مرحبا', True );
text := ReplaceRegExpr( 's[la]+m', text, 'سلام', True );
text := ReplaceRegExpr( '[ie]n[sc]h[aa]+[l]+[ah]+', text, 'إن شاء الله', True );
text := ReplaceRegExpr( 'a[ll]+ah', text, 'الله', True );
text := ReplaceRegExpr( '[2a][wo][al]l', text, 'أول', True );
text := ReplaceRegExpr( 'all', text, 'جميع', True );
text := ReplaceRegExpr( 'm[oh7]+[ma]+d', text, 'محمد', True );
text := ReplaceRegExpr( 'm[uosh]+[car]+[rkhaeh]+', text, 'مشاركه', True );
text := ReplaceRegExpr( '[kh|7'+chr(39)+']+[ae]+r', text, 'خير', True );
text := ReplaceStr( text, chr( 39 ) + '3', 'غ' );
text := ReplaceStr( text, '6' + chr( 39 ), 'ظ' );
text := ReplaceStr( text, '9' + chr( 39 ), 'ض' );
text := ReplaceStr( text, '9', 'ص' );
text := ReplaceStr( text, '7' + chr( 39 ), 'خ' );
text := ReplaceStr( text, '6', 'ط' );
text := ReplaceStr( text, '5', 'خ' );
text := ReplaceStr( text, '7', 'ح' );
text := ReplaceStr( text, '3', 'ع' );
text := ReplaceStr( text, '2', 'ئ' );
text := ReplaceRegExpr( 'e$', text, 'ي', True );
//---------------------------------------------------------------------
text := ReplaceRegExpr( '^e', text, 'إ', True );
text := ReplaceRegExpr( 'r', text, 'ر', True );
text := ReplaceRegExpr( 'ash', text, 'أش', True );
text := ReplaceRegExpr( 'wa', text, 'و', True );
text := ReplaceRegExpr( '\Bae\B', text, 'ي', True );
text := ReplaceRegExpr( 's[\' + chr( 39 ) + '.]', text, 'س', True );
text := ReplaceRegExpr( 'me', text, 'مي', True );
text := ReplaceRegExpr( '^au', text, 'ا', True );
text := ReplaceRegExpr( 'ma3', text, 'مع', True );
text := ReplaceRegExpr( '^a', text, 'ا', True );
text := ReplaceRegExpr( '^e', text, 'ا', True );
text := ReplaceRegExpr( '^i', text, 'ا', True );
text := ReplaceRegExpr( 'al2', text, 'الإ', True );
text := ReplaceRegExpr( '^mc', text, 'ماك', True );
text := ReplaceRegExpr( '^o', text, 'او', True );
text := ReplaceRegExpr( '^u', text, 'ا', True );
text := ReplaceRegExpr( '^wr', text, 'ر', True );
text := ReplaceRegExpr( 'ough$', text, 'ه', True );
text := ReplaceRegExpr( 'ough', text, 'او', True );
text := ReplaceRegExpr( 'al', text, 'ال', True );
text := ReplaceRegExpr( 'ois', text, 'وا', True );
text := ReplaceRegExpr( 'sch', text, 'ش', True );
text := ReplaceRegExpr( 'tio', text, 'ش', True );
text := ReplaceRegExpr( 'ai', text, 'اي', True );
text := ReplaceRegExpr( 'au', text, 'او', True );
text := ReplaceRegExpr( 'bb', text, 'ب', True );
text := ReplaceRegExpr( 'cc', text, 'ك', True );
text := ReplaceRegExpr( 'ce', text, 'س', True );
text := ReplaceRegExpr( 'ci', text, 'سي', True );
text := ReplaceRegExpr( 'cy', text, 'سي', True );
text := ReplaceRegExpr( 'ch', text, 'تش', True );
text := ReplaceRegExpr( 'ck', text, 'ك', True );
text := ReplaceRegExpr( 'dd', text, 'د', True );
text := ReplaceRegExpr( 'ea', text, 'يا', True );
text := ReplaceRegExpr( '\Be\B', text, 'ي', True );
text := ReplaceRegExpr( 'ee', text, 'ي', True );
text := ReplaceRegExpr( 'ey', text, 'اي', True );
text := ReplaceRegExpr( 'ff', text, 'ف', True );
text := ReplaceRegExpr( 'ge', text, 'ج', True );
text := ReplaceRegExpr( 'gi', text, 'جي', True );
text := ReplaceRegExpr( 'gg', text, 'غ', True );
text := ReplaceRegExpr( 'gh', text, 'غ', True );
text := ReplaceRegExpr( 'gn', text, 'جن', True );
text := ReplaceRegExpr( 'ie', text, 'ي', True );
text := ReplaceRegExpr( 'kk', text, 'ك', True );
text := ReplaceRegExpr( 'kh', text, 'خ', True );
text := ReplaceRegExpr( 'll', text, 'ل', True );
text := ReplaceRegExpr( 'mm', text, 'م', True );
text := ReplaceRegExpr( 'nn', text, 'ن', True );
text := ReplaceRegExpr( 'oo', text, 'و', True );
text := ReplaceRegExpr( 'ou', text, 'و', True );
text := ReplaceRegExpr( 'ph', text, 'ف', True );
text := ReplaceRegExpr( 'pp', text, 'ب', True );
text := ReplaceRegExpr( 'qu', text, 'كو', True );
text := ReplaceRegExpr( '[rr]', text, 'ر', True );
text := ReplaceRegExpr( 'sh', text, 'ش', True );
text := ReplaceRegExpr( 'ss', text, 'س', True );
text := ReplaceRegExpr( 'th', text, 'ث', True );
text := ReplaceRegExpr( 'tt', text, 'ت', True );
text := ReplaceRegExpr( 'ue$', text, 'ي', True );
text := ReplaceRegExpr( 'wr', text, 'ر', True );
//text := ReplaceRegExpr( 'a$' ,text, 'ه', True);
text := ReplaceRegExpr( 'a', text, 'ا', True );
text := ReplaceRegExpr( 'b', text, 'ب', True );
text := ReplaceRegExpr( 'c', text, 'ك', True );
text := ReplaceRegExpr( 'd', text, 'د', True );
text := ReplaceRegExpr( 'e', text, '', True );
text := ReplaceRegExpr( 'f', text, 'ف', True );
text := ReplaceRegExpr( 'g', text, 'غ', True );
text := ReplaceRegExpr( 'h', text, 'ه', True );
text := ReplaceRegExpr( 'i', text, 'ي', True );
text := ReplaceRegExpr( 'j', text, 'ج', True );
text := ReplaceRegExpr( 'k', text, 'ك', True );
text := ReplaceRegExpr( 'l', text, 'ل', True );
text := ReplaceRegExpr( 'm', text, 'م', True );
text := ReplaceRegExpr( 'n', text, 'ن', True );
text := ReplaceRegExpr( 'o', text, 'و', True );
text := ReplaceRegExpr( 'p', text, 'ب', True );
text := ReplaceRegExpr( 'q', text, 'ك', True );
text := ReplaceRegExpr( 'r', text, 'ر', True );
text := ReplaceRegExpr( 's$', text, 'س', True );
text := ReplaceRegExpr( 's', text, 'س', True );
text := ReplaceRegExpr( 't', text, 'ت', True );
text := ReplaceRegExpr( 'u', text, 'و', True );
text := ReplaceRegExpr( 'v', text, 'ف', True );
text := ReplaceRegExpr( 'w', text, 'و', True );
text := ReplaceRegExpr( 'x', text, 'كس', True );
text := ReplaceRegExpr( 'y', text, 'ي', True );
text := ReplaceRegExpr( 'z', text, 'ز', True );
conv2arabic.Memo2.Text := conv2arabic.Memo2.Text + ' ' + text;
end;
if IsInteger( MyArray[ i ] ) = 1 then
begin
conv2arabic.Memo2.Text := conv2arabic.Memo2.Text + ' ' + text;
end;
end;
end;
if ( Clipboard.AsText <> '' ) then
Sleep( 150 );
s := ReplaceStr( Clipboard.AsText, 'ذ', '`' );
s := ReplaceStr( s, 'ض', 'q' );
s := ReplaceStr( s, 'ص', 'w' );
s := ReplaceStr( s, 'ث', 'e' );
s := ReplaceStr( s, 'ق', 'r' );
s := ReplaceStr( s, 'ف', 't' );
s := ReplaceStr( s, 'غ', 'y' );
s := ReplaceStr( s, 'ع', 'u' );
s := ReplaceStr( s, 'ه', 'i' );
s := ReplaceStr( s, 'خ', 'o' );
s := ReplaceStr( s, 'ح', 'p' );
s := ReplaceStr( s, 'ج', '[' );
s := ReplaceStr( s, 'د', ']' );
s := ReplaceStr( s, 'ش', 'a' );
s := ReplaceStr( s, 'س', 's' );
s := ReplaceStr( s, 'ي', 'd' );
s := ReplaceStr( s, 'ب', 'f' );
s := ReplaceStr( s, 'ت', 'j' );
s := ReplaceStr( s, 'ن', 'k' );
s := ReplaceStr( s, 'م', 'l' );
s := ReplaceStr( s, 'ك', ';' );
s := ReplaceStr( s, 'ط', chr( 39 ) );
s := ReplaceStr( s, 'ئ', 'z' );
s := ReplaceStr( s, 'ء', 'x' );
s := ReplaceStr( s, 'ؤ', 'c' );
s := ReplaceStr( s, 'ر', 'v' );
s := ReplaceStr( s, 'ى', 'n' );
s := ReplaceStr( s, 'ة', 'm' );
s := ReplaceStr( s, 'و', ',' );
s := ReplaceStr( s, 'ز', '.' );
s := ReplaceStr( s, 'ظ', '/' );
s := ReplaceStr( s, 'ّ', '~' );
s := ReplaceStr( s, 'َ', 'Q' );
s := ReplaceStr( s, 'ً', 'W' );
s := ReplaceStr( s, 'ُ', 'E' );
s := ReplaceStr( s, 'ٌ', 'R' );
s := ReplaceStr( s, '?', 'U' );
s := ReplaceStr( s, '÷', 'I' );
s := ReplaceStr( s, '×', 'O' );
s := ReplaceStr( s, '؛', 'P' );
s := ReplaceStr( s, '<', '{' );
s := ReplaceStr( s, '>', '}' );
s := ReplaceStr( s, 'ِ', 'A' );
s := ReplaceStr( s, 'ٍ', 'S' );
s := ReplaceStr( s, ']', 'D' );
s := ReplaceStr( s, '[', 'F' );
s := ReplaceStr( s, 'أ', 'H' );
s := ReplaceStr( s, 'ـ', 'J' );
s := ReplaceStr( s, '،', 'K' );
s := ReplaceStr( s, '/', 'L' );
s := ReplaceStr( s, ':', ':' );
s := ReplaceStr( s, '"', '"' );
s := ReplaceStr( s, '~', 'Z' );
s := ReplaceStr( s, 'ْ', 'X' );
s := ReplaceStr( s, '}', 'C' );
s := ReplaceStr( s, '{', 'V' );
//------------------------------
s := ReplaceStr( s, 'لآ', 'B' );
s := ReplaceStr( s, 'لأ', 'G' );
s := ReplaceStr( s, 'لا', 'b' );
s := ReplaceStr( s, 'لإ', 'T' );
s := ReplaceStr( s, 'إ', 'Y' );
s := ReplaceStr( s, 'ل', 'g' );
s := ReplaceStr( s, 'ا', 'h' );
s := ReplaceStr( s, 'آ', 'N' );
//------------------------------
s := ReplaceStr( s, '?', 'M' );
s := ReplaceStr( s, ',', '<' );
s := ReplaceStr( s, '.', '>' );
s := ReplaceStr( s, '؟', '?' );
//ShowMessage(s);
clean.Text:= s;
s := clean.Text;
مجتمع لمناقشة وتبادل الخبرات حول تطوير الويب. ناقش أحدث التقنيات، اللغات، والأدوات في عالم تطوير المواقع والتطبيقات. شارك مشاريعك، اسأل عن نصائح، وتعاون مع مطورين محترفين وهواة.