• Resolved wissam6

    (@wissam6)


    hi,
    I have many pages written in arabic. to be able to search without the accents i added in function.php a function to remove these accents. the problem is that the plugin doesn’t highlihting the search term anymore.
    is there a workaround?
    thx

    P.S: here i the function that i am using

    add_filter( ‘relevanssi_remove_punctuation’, ‘rlv_remove_arabic_diacritics’ );
    function rlv_remove_arabic_diacritics( $a ) {
    $a = preg_replace( ‘~[\x{064B}-\x{065B}]~u’, ”, $a );
    return $a;
    }

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Mikko Saari

    (@msaari)

    For Latin alphabet, Relevanssi handles this with a replacement array, so that when doing the highlights, instead of “a” Relevanssi looks for “a”, “á”, “à” or “â” and so on.

    Look what Relevanssi does in relevanssi_add_accent_variations() in the /lib/excerpt-highlights.php file and then use the relevanssi_accents_replacement_arrays filter hook to create the Arabic accent variations. See the filter documentation here.

    Thread Starter wissam6

    (@wissam6)

    can i make what you are suggesting in function.php ?

    Plugin Author Mikko Saari

    (@msaari)

    Yes, that’s where you should add the function, yes.

    Thread Starter wissam6

    (@wissam6)

    what ae you saying is to remove the letters a c e …etc. and put the arabic alphabet, no?

    array(
      'from'    => array( 'a', 'c', 'e', 'i', 'o', 'u', 'n' ),
      'to'      => array( '(?:a|á|à|â)', '(?:c|ç)', '(?:e|é|è|ê|ë)', '(?:i|í|ì|î|ï)', '(?:o|ó|ò|ô|õ)', '(?:u|ú|ù|ü|û)', '(?:n|ñ)' ),
      'from_re' => array( "/(s)('|’)?$/", "/<a href="'|’">^(|:</a>/" ),
      'to_re'   => array( "(?:(?:'|’)?\1|\1(?:'|’)?)", "?('|’)?" ),
    )
    Plugin Author Mikko Saari

    (@msaari)

    Yes. In the from list are the letters without diacritics, and in the to array are the same letters with the diacritics, so the first one in both is “a” and the matching forms, the second one is “c” and the matching forms and so on.

    Thread Starter wissam6

    (@wissam6)

    can i make what you are suggesting in function.php ?
    because i have an error when i try to declare the array 🙁

    Plugin Author Mikko Saari

    (@msaari)

    Yes you can. If there’s an error, then there’s something wrong with your code. Please share it here so I can see.

    Thread Starter wissam6

    (@wissam6)

    i put this code in function.php
    for the the time beeing i didn’t replace anything, i use what you suggest, the problem is in line which beging with “from_re” , because i tried to build the array line by line and i noticed that on this line there’s the problem.

    the error is: Your PHP code changes were rolled back due to an error on line 0 of file Unknown. Please fix and try saving again.

    Exception thrown without a stack frame

    thank you for your help.

    $array = array(
    ‘from’ => array( ‘a’, ‘c’, ‘e’, ‘i’, ‘o’, ‘u’, ‘n’ ),
    ‘to’ => array( ‘(?:a|á|à|â)’, ‘(?:c|ç)’, ‘(?:e|é|è|ê|ë)’, ‘(?:i|í|ì|î|ï)’, ‘(?:o|ó|ò|ô|õ)’, ‘(?:u|ú|ù|ü|û)’, ‘(?:n|ñ)’ ),
    ‘from_re’ => array( “/(s)(‘|’)?$/”, “/^(|:/” ),
    ‘to_re’ => array( “(?:(?:’|’)?\1|\1(?:’|’)?)”, “?(‘|’)?” ),
    );

    add_filter( ‘relevanssi_accents_replacement_arrays’, function ( $replacements ) {
    $replacements[‘to’][0] = ‘(?:a|á|à|â|ä)’;
    return $replacements;
    });`

    Plugin Author Mikko Saari

    (@msaari)

    You don’t need the first part – that’s just the Relevanssi default variables you’ll be replacing within your function.

    Your function should look like this:

    add_filter( ‘relevanssi_accents_replacement_arrays’, function ( $replacements ) {
    $replacements['from'] = array( ‘a’, ‘c’, ‘e’, ‘i’, ‘o’, ‘u’, ‘n’ );
    $replacements['to'] = array( ‘(?:a|á|à|â)’, ‘(?:c|ç)’, ‘(?:e|é|è|ê|ë)’, ‘(?:i|í|ì|î|ï)’, ‘(?:o|ó|ò|ô|õ)’, ‘(?:u|ú|ù|ü|û)’, ‘(?:n|ñ)’ );
    return $replacements;
    });
    Thread Starter wissam6

    (@wissam6)

    thanks a lot, it works

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘search: remove diacritics’ is closed to new replies.