• Resolved matijagudlin

    (@matijagudlin)


    Hi support,

    when entering search term autocomplete shows results for CATEGORY in all languages we have on website – it is not limited to current language (EN, DE, HR). Can it be fixed so only category from currently selected language is recommended in autocomplete window?

    For example if I write Violin autocomplete will suggest category in English, German and Croatian. What I would need is to show only German category if my language is set to German. Is this possible somehow?

    We use WPML for translations.

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hi @matijagudlin

    I would check out https://github.com/WebDevStudios/wp-search-with-algolia/wiki/WPML which is where we highlight how to fetch and output the current language being used to the client side, and subsequently use that current language as a filter. The very last section at the bottom of the page will be where the usage for Autocomplete is at.

    Thread Starter matijagudlin

    (@matijagudlin)

    Hi Michael,

    when I add code in functions.php and in autocomplete.php, and reindex everything (also push settings) category is no longer among the search results.

    Here is screenshot https://ibb.co/XZkJ36p

    And this is how it looks when I disable (remove the part of code in autocomplete.php > filters: ‘wpml.locale:”‘ + current_locale + ‘”‘,) but leave code in functions.php – it shows results only in english

    https://ibb.co/hZR5nc4

    If you need credentials to check it on live site please let me know.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Before we do anything like that, it’d be best to also check your Algolia.com dashboard index to confirm whether or not the content is there as well. That’s the source of truth for what will show up in the Autocomplete UI.

    Thread Starter matijagudlin

    (@matijagudlin)

    I checked Algolia dashboard and checked for categories and all the settings, is there something specific I need to look at?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Mostly whether or not the content is there at all. If the expected content is not in your algolia dashboard, then the UI on the website has nothing to query against and show results for.

    Also you can try queries in there to verify results and result quality, before moving back over to the WP side to test and confirm the same results.

    Thread Starter matijagudlin

    (@matijagudlin)

    We checked in Algolia dashboard index and as I can see the content is not there. All categories are translated and re-indexed, settings are pushed. Funny thing is that if we change language in dashboard to Croatian and then re-index and push settings search gives results only for Croatian, if we do the same when “All languages” is selected nothing changes – results are still in English ony.

    https://ibb.co/Qbsp620

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    So as is, the issue is that we’re not managing to get all of the intended content indexed, and if we did at one point, the return values weren’t like expected.

    To be certain, what autocomplete content options do you ideally have checked? Based on the initial screenshot, it’s just showing product variations and product categories, both of which I am assuming are WooCommerce taxonomies. What else? I think first step would be figuring out why not everything is getting indexed like expected. Ideally end result would be all taxonomy terms, regardless of language.

    An important note to know is that for each checkbox in the Autocomplete settings, each gets its own index and its own configuration. The only case where “sort of” not would be the “All Posts” option, which would share the “wp_searchable_posts” index with Search Page settings.

    Thread Starter matijagudlin

    (@matijagudlin)

    Lots of options are checked, from category and posts to custom meta fields. Now the status has changed, categories show up but we still get results for all the languages instead of only selected language: here is short video demonsttration https://vimeo.com/945667131/90f169d2d6?share=copy

    In this video you can see that I do search for term “violina” which is Croatian term for violin, first result is correct one but there are results for both violin (English) and violine (German). Then when I click on searched product category it transfers me to Croatian version, and over there I can again search for all terms of other languages. How can we limit it to show only results from current language?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Sounds like things are indexed again, and that’ll bring us back to my reply with https://github.com/WebDevStudios/wp-search-with-algolia/wiki/WPML

    For the examples to work, it’s basically a matter of storing the associated language code as part of the category term object in Algolia, and then using Algolia’s filtering capabilities to only show items from the current language.

    Thread Starter matijagudlin

    (@matijagudlin)

    Yes, indexing is ok now.

    The problem now is that categories don’t show up in autocomplete at all when this line is added in autocomplete.php (tested on all languages) filters: 'wpml.locale:"' + current_locale + '"',

    I added neccesary code in functions.php as well and in instantsearch.php
    Is there any reason why this happens?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Ahh, I think I know the details being missed. The way that I’ve pointed out this filtering is ending up being applied to ALL of the indexes being considered for the Autocomplete. Then when it’s just the product categories that have the wpml portion applied, it only ends up working for that specific index.

    Give me a few to think this over a bit more ??

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    This is more a proof of concept, to have the filtering apply only for a specific taxonomy index:

    source: algoliaHitsSource( client.initIndex( config[ 'index_name' ] ), {
    	hitsPerPage: config[ 'max_suggestions' ],
    	attributesToSnippet: [
    		'content:10'
    	],
    	highlightPreTag: '__ais-highlight__',
    	highlightPostTag: '__/ais-highlight__',
    	filters:
    		( 'terms_product_cat' === config[ 'index_name' ] ) ?
    		wpml.locale:"' + current_locale + '"' :
    		'',
    } ),

    Ideally though, it’s probably a case of needing to get the wpml.locale detail into all things posts and terms, because I assume you want the language-appropriate filtering to apply to everything.

    As is, this example above would only apply it to the product category taxonomy from WooCommerce.

    Thread Starter matijagudlin

    (@matijagudlin)

    Thank you Michael for your effort so far.

    I tried to add this filter as you suggested, it ‘broke’ autocomplete and it didn’t work (at all, we got no results for any query) so I added single quote to wpml.locale:”‘ like this ‘wpml.locale:”‘ – it helped to regain autocomplete results but they are the same as before – here is short video demonstration that first shows how it works with this modified code and then copy of your code without modification

    https://vimeo.com/946457934/01ed492b6c?share=copy

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Honestly not sure what may be going on outside of either javascript errors going on, API errors being encountered, or possibly rate limiting given that your autocomplete is configured to query against 41 indexes for each keystroke. We could attempt some debouncing, but I’m not sure how much that’ll help. I know it’s not necessarily my place to interject, but I do wonder if it’d be worth reducing down your sources for the autocomplete, and optimize what you keep.

    Just trying to help as best I can.

    Thread Starter matijagudlin

    (@matijagudlin)

    Hi, we change the code and now results are limited to language selected. Previously mentioned problem still remains – if we reindex for example EN language it will show only results when EN language is selected. If we reindex DE language after that it will not show category for EN language any more but only for DE. And finally if HR language is selected it will only show category results in autocomplete when you’re on HR language, all other will not have any results in category.

    When viewing Index in algolia it is reflecting the same results. Is this really the only case where product categories are not showing properly when having multilingual site?

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Autocomplete shows category results for all languages rather than selected one’ is closed to new replies.