Support » Plugin: Relevanssi - A Better Search » Current language in relevanssi_hits_filter

  • Resolved erikture

    (@erikture)


    I dont know if it is Relevanssi or SearchWP Live Ajax Search that is the correct place to ask this question.

    I am using both these plugins together with Polylang to make my site multi language. I would like to strip the search results visible in SearchWP Live Ajax Search so only hits at the current language is shown. I am using the relevanssi_hits_filter hook to exclude hits, both depending on language and on permission. For permission it works fine but not for language.

    I am trying the find out the current selected language but it is always the default language of the site that is returned. I have tried a number of different ways that should return the current language, both WordPress build in functions as well as Polylang functions but with no luck. Always the default language is returned. Why?

    I have made a printout of the language returned from these methods I have tried and inside SearchWP Live Ajax Search it is always the default one returned and when pressing enter to display the results the correct language is returned. When is the current language set?

    Later on if pressing enter in the search form Relevanssi returns the matches in the current language.

    /Erik

    https://wordpress.org/plugins/relevanssi/

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

    (@msaari)

    Polylang uses taxonomy terms for setting the language. When it does it, I’m not sure. If the full search results come up with the correct language, then I think you’re better off asking this at SearchWP Live Search forums.

    Thread Starter erikture

    (@erikture)

    Thanks!

    /Erik

    Thread Starter erikture

    (@erikture)

    One more question!

    Somehow the relevanssi_hits_filter hook is called, both when searching SearchWP Live Search plugin and when displaying the matches pressing enter in the searchform. It must be Relevanssi that calls this hook both times. Why is the current language set the second time and not the first time. As I have understood it Relevanssi takes over from the default search engine.

    /Erik

    Plugin Author Mikko Saari

    (@msaari)

    Relevanssi is clearly active in both cases if the filter fires, but why the language is not set, I have no idea. What you can do is to print out the contents of $wp_query->query_vars from both cases and compare: is there a difference?

    Thread Starter erikture

    (@erikture)

    I have found out that it is probably related to the plugin Hyyan WooCommerce Polylang Integration. As that one is not maintained any more I am now trying the qtranslate-x plugin and so far it looks promissing.

    Now I have to filter hits available in the current language as I understand that Relevanssi does not support qtranslate-x out of the box.

    Plugin Author Mikko Saari

    (@msaari)

    Yes, but the mechanism is probably fairly similar, so you can take a look at the WPML/Polylang integration in lib/common.php and do something like that.

    Thread Starter erikture

    (@erikture)

    Thanks!

    I have managed to filter the hits.
    There is one minor problem that I think is hard to solve.
    qtranslate-x stores all language versions in the same post with a language separator. Relevanssi and other searchengines too, can not figure out wich part the match is in. Say that I am searching for ‘hource’ in a swedish site. Then I will get a hit if ‘hource’ is part of a post, any part. I will den return the swedish version of that post if it exists. If there is no swedish version of that post no hit is returned. But the word ‘hource’ will probably not exist in that part of the post. If I am lucky the word ‘häst’ will exist but not fore sure.

    But this is something I have to live with!

    /Erik

    Plugin Author Mikko Saari

    (@msaari)

    Yeah, that’s just nothing you can do about that with Relevanssi.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Current language in relevanssi_hits_filter’ is closed to new replies.