سؤال فيما يخص تحسين البحث عن الداتا

لقد كنت في مقابلة عمل فيما يخص تطوير الويب، وسُئلت سؤالا لم اجب عليه بدقة وهو كالآتي :

اذا كان لدينا موقع لغته انجليزية بالكامل مع الداتا، وأتى شخص ادخل في حقل البحث كلمة عربية ك مثال 'إلكترون'، ولا يوجد في الداتابيس كلمة الكترون بالعربي لكن يوجد مرادف لها بالانجليزية 'electron'، ما هي الطريقة المناسبة لجعله يأتي بالنتائج التي تحتوي على كلمة elctron بالانجليزي والشخص بحثَ عن كلمة إلكترون بالعربي؟

اجابتي ربما كانت غير دقيقة، لكنها كانت كالاتي :

نعمل function يستقبل كلمة البحث، ونفحص اذا كانت الاحرف عربية باستخدام الاسكي كود، ونجعل كل حرف عربي مقابله شبيهه بالانجليزية مثلاً : ك -> k

وهكذا mapping، ربما ليست دقيقة بشكل كبير لكنها ستفي بالغرض.

سؤالي، هل يوجد طُرق اكثر كفاءة وتفي بالغرض بشكل سليم؟ :)

وشكرًا


beshoo أضف ردا

ابحث عن برنامج ابو الحروف :) قمت بها في عام 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;