Suddenly have an 'uncaught typeError'

I built a search page with WordPress & Algolia, and it’s been working fine for a few months, but suddenly, I am getting the following error:

“Uncaught TypeError: Cannot read property ‘matchedWords’ of undefined”

The facet filters are no longer working and the search results are not being displayed.

Page in question is:

Is this error because some of the required JS files are missing? I can’t pinpoint anything having changed so I don’t really know how to fix this error.

Please help!

Thanks in advance.


matchedWords is a key of the object holding highlighting information returned by the Algolia API.

The error you’re seeing is usually because you are trying to highlight a word (or sentence) that does not match your current query. For example you’re trying to highlight “iPhone” while searching for “Samsung”.

My guess is that the error is coming from your JavaScript highlighting function. You should add a check in it to only highlight elements that can be highlighted (ie. have a matching key in the results sent by Algolia).

Once this error will be fixed, the rest of your JavaScript will execute correctly and your facets and results will be back.

Hi @andyb,

I’ve answered your question on StackOverflow here because I didn’t know you cross posted :wink:

BTW @pixelastic answer gives you even more information about why the error is raised.

I hope that with both answers you manage to solve the issue,

Keep us posted!

Thank you for the replies, much appreciated.

I have ‘fixed’ the error temporarily by removing all code relating to ‘highlightResult’ from my instantsearch hit template.

The template now simply shows the data returned from the search query but doesn’t have any functionality to highlight search results.

I am going to rebuild my indices, and then try to get my result highlighting working again.

Will report back once I’ve had a go at this.

Thanks again.

I deleted all my Algolia Indices, and reindexed everything required, and reverted back to my old instantsearch hit template, which indeed worked again, with search highlighting working again.

One thing doesn’t work though. I was previously using data.images.medium to display thumbnails of each search result. For some reason this no longer works, as in no image is displayed. There are no console errors present and I can’t figure out what’s changed.

I can get data.images.thumbnail working to display a thumbnail with each search result. I want however to grab a higher resolution image, which I was previously able to do using data.images.medium

Any ideas?

I found out the answer from this post - Image size on Instantsearch page

Since version 2.x, all image sizes are not returned with each search since it incurs performance issues.

To return custom image sizes other than thumbnails this code needs to be added to a plugin / functions file.

add_filter('algolia_post_images_sizes', function($sizes) {
    $sizes[] = 'medium'; 

    return $sizes;

Once this code has been added to functions or your own custom plugin file, you’ll need to reindex everything and then your chosen custom image sizes should start to work.

Hopefully this is helpful.

1 Like

I’ve implemented the above mentioned code in my functions.php and then reindexed everything.
But the custom image size doesn’t work?

(I’m running version 2.6.1)