0

this is specific case for "Devanagari" fonts/language. I have a small encyclopedia type website having 18000 records in "Marathi" (a local state language in India).

Marathi uses Devanagari script. This is something different than latin as the vowels play very important role. so a word "NITSHE" (नित्शे) is completely different than "NEETSHE" (नीत्शे). People make lot of errors and use wrong spellings. So i altered wordpress search to ignore vowels, basically i & u. The code is follows -

add_filter('posts_search', function ( $search, $wp_query )
{
    if(is_admin() || !$wp_query->is_search()) return $search;
    if( empty($search) ) return $search;

    global $wpdb; $q = $wp_query->query_vars; $search = '';
    foreach ($q['search_terms'] as $term) {
        $term = esc_sql($wpdb->esc_like($term));
        $term = str_replace(array('ि', 'ी', 'ु', 'ू'), '_', $term);
        if(substr($term, 0, 1) == '-'){
            $term = substr($term, 1);
            $search .= " AND ( {$wpdb->posts}.post_title not like '%{$term}%' AND {$wpdb->posts}.post_content not like '%{$term}%' ) ";         
        }
        else
            $search .= " AND ( {$wpdb->posts}.post_title like '%{$term}%' OR {$wpdb->posts}.post_content like '%{$term}%' ) ";
    }

Everything works. Now The problem is : Correct word is "NEETSHE" (नीत्शे). It has 36 Articles. Wrong word is "NITSHE" (नित्शे). It ALSO has 2 Articles. Yah it's wrong data. People may search "NEETSHE" (नीत्शे) or "NITSHE" (नित्शे).. So whenever they search "NEETSHE" (नीत्शे) or "NITSHE" (नित्शे), i replace it with "N_TSHE" (न_त्शे) or "N_TSHE" (न_त्शे).. and this is expected to search all records = 38. This is perfect and works. But when i search "NEETSHE" (नीत्शे), the article with "NEETSHE" (नीत्शे) in title comes to top with perfect relevance whereas when i search "NITSHE" (नित्शे) it's thrown to bottom... though the query i fire is always "N_TSHE" (न_त्शे).

This means relevance is calculated somewhere else. I want this to produce same results and correct relevance. I tried REGEXP, MATCH AGAINST etc... but no luck. Best results by above logic. Just need better order by.

I am sorry if failed to make it understand..

  • People, wordpress/database experts, plz help.. – vinay samant Jul 21 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.