Viewing 15 replies - 1 through 15 (of 18 total)
  • Nice. I just read this plugin offers a filter hook relevanssi_hits_filter

    Maybe you can do something around that?

    Thread Starter Amir Helzer

    (@amirhelzer)

    Can you give me a quick push and post a list to where that filter is described?

    Apparently there are more filters available (relevanssi_where looks promising), see the plugin FAQ http://wordpress.org/extend/plugins/relevanssi/faq/

    I just found this plugin and started to experiment with it…

    so I am not the author of Relevanssi, sorry if I sounded misleading

    Plugin Author Mikko Saari

    (@msaari)

    Well, I’m the author of Relevanssi and I’m very interested in getting Relevanssi and WPML to work together (I use WPML myself), I just haven’t had the time to do it yet.

    The relevanssi_hits_filter is one way to approach it. It gives you a list of hits found with the query, so it’s possible to go through them and discard the hits that are in the wrong language.

    It’s on line 570 of Relevanssi 2.6.

    $filter_data = array($hits, $q);
    	$hits_filters_applied = apply_filters('relevanssi_hits_filter', $filter_data);
    	$hits = $hits_filters_applied[0];

    The first part of the data is an array of post objects, the second is the search query. You need to return an array containing an array of post objects in index 0.

    That’s one way to approach it. Then there’s relevanssi_where, which allows you to modify query restrictions. That’s what gets slapped in the end of the MySQL query that finds the hits. You could add some MySQL code that restricts the search to only current language (essentially in the shape of ” AND doc IN (list of allowed post ID’s) ” or ” AND doc NOT IN (list of forbidden post ID’s) “.

    If you can come up with something that makes Relevanssi work with WPML, I’d be delighted to add it to Relevanssi core if necessary, since WPML is such a significant plugin. If WPML is active, user could choose to restrict the search to the active language or to search all languages.

    You can email me directly at mikko at mikkosaari.fi.

    Hi, I got another issue with the combination of those plugins.

    If you try this search: http://www.dentfix.ro/?s=dentist+copil

    you get this error:

    Catchable fatal error: Object of class WP_Error could not be converted to string in /home/dentfixr/public_html/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 3514

    But all is OK when doing this search: http://www.dentfix.ro/?s=dentist+copil&lang=en

    Plugin Author Mikko Saari

    (@msaari)

    Hmm, that sounds like a WPML problem… In any case, I’m going to work on Relevanssi-WPML relations and got some good tips from WPML folks.

    Nice. Filtering on the current language might eliminate this problem too since I noticed all searches with hits in only one language are performed correctly, while those with hits in more languages might just break.

    So if you want to add as an option seaching in multiple languages this issue should be addressed.

    My simple solution to return hits only in the current language:

    add_filter ('relevanssi_hits_filter','relevanssi_wpml_filter_hits');
    
    function relevanssi_wpml_filter_hits($hits) {
    
        $filtered_hits = array();
        foreach ($hits[0] as $hit) {
            if ($hit->ID == icl_object_id($hit->ID, 'post',false,ICL_LANGUAGE_CODE))
                    $filtered_hits[] = $hit;
            if ($hit->ID == icl_object_id($hit->ID, 'page',false,ICL_LANGUAGE_CODE))
                    $filtered_hits[] = $hit;
            if ($hit->ID == icl_object_id($hit->ID, 'customposttype1',false,ICL_LANGUAGE_CODE))
                    $filtered_hits[] = $hit;
            if ($hit->ID == icl_object_id($hit->ID, 'customposttype2',false,ICL_LANGUAGE_CODE))
                    $filtered_hits[] = $hit;
            if ($hit->ID == icl_object_id($hit->ID, 'customposttype3',false,ICL_LANGUAGE_CODE))
                    $filtered_hits[] = $hit;
        }
        $filtered = array($filtered_hits,$hits[1]);
        return $filtered;
    }

    I noticed that filtering the search this way, the fatal error issue described above has dissapeared.

    If more info can be useful to spot the issue, I also noticed that the fatal error happens for unfiltered results in all languages, in any desktop theme. But it works fine with the mobile themes under WPTouch Pro 🙂

    Plugin Author Mikko Saari

    (@msaari)

    I just wrote the code for WPML-Relevanssi integration today. My solution is similar to yours, though I grab the id’s of entries in current language from the db and compare to that.

    I’ll release 2.7 soon, though I’ve got a couple of more features to add, and then Relevanssi and WPML will work together.

    Yes, I suppose the DB stuff will work faster… and the code would not depend on the names of the custom post types defined.

    After some good sleep I realized that the function can be wrote much shorter and that WPML guys are going to preserve the icl_object_id function even if they decide at some point to change the database structure.

    function relevanssi_wpml_filter_hits($hits) {
    
        $filtered_hits = array();
        foreach ($hits[0] as $hit) {
            if ($hit->ID == icl_object_id($hit->ID, $hit->post_type,false,ICL_LANGUAGE_CODE))
                    $filtered_hits[] = $hit;
        }
        return array($filtered_hits,$hits[1]);
    }
    Plugin Author Mikko Saari

    (@msaari)

    Nice solution! I’ll use this code in Relevanssi. Thanks!

    Plugin Author Mikko Saari

    (@msaari)

    The version 2.7 is now out and has automatic WPML support.

    Hi, I upgraded to v2.7 but for some reason if I disable my integration code the module behaves just like 2.6 with no integration. Please explain a bit how did you do it maybe I can debug the issue.

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘[Plugin: Relevanssi – A Better Search] Compatibility with WPML’ is closed to new replies.