Facets stop working after upgrade from v1.1 to v2.0.1

Created on 24 April 2024, 7 months ago
Updated 30 April 2024, 7 months ago

Problem/Motivation

My searches are often set up as a fulltext search with additionals filters provided as facet checkboxes.
They can be placed nicely with the module views_block_area in the header of the view.

This works with most searches as it did using v1.1
I have one site/index however, where an update to search_api_meilisearch (and the new facets submodule) makes the facets disappear.

Drupal/search_api_meilisearch just does not seem to think there are any facets.

These are the things I tried:
Reindexed all items. Same situation.
Created a new index with 3 sample fields of the content that is indexed in the broken one as well. Created a new search view on this index. Added new facets based on this new view. Same situation.
Downgraded meilisearch/meilisearch-php to the lowest possible 1.3.0. Same situation.
Compared the two indexes (working site vs. not working one), both have their filterable attributes set to the expected fields.

Put several debug statements into the respective code, comparing a working site and the broken one.

I think it boils down to the new protected function getFacetData in v2.0.1 not retrieving any facets. I get an empty facetHits array at the broken site.
This in turn means return $index->facetSearch($facetSearch); in public function searchFacets does not retrieve the facets.
This is outside this module, which is strange.

This is how a Meilisearch debug log looks like for the two cases:

Working v1.1 based search, loading the search page
[2024-04-24T12:28:12Z DEBUG meilisearch::routes::indexes::search] search called with params: SearchQuery { q: Some(""), vector: None, hybrid: None, offset: 0, limit: 20, page: None, hits_per_page: None, attributes_to_retrieve: None, attributes_to_crop: None, crop_length: 10, attributes_to_highlight: None, show_matches_position: false, show_ranking_score: false, show_ranking_score_details: false, filter: None, sort:Some(["field_project_number:desc"]), facets: Some(["body", "display_title", "field_project_category", "field_project_contact_email", "field_project_contact_fax", "field_project_contact_firstname", "field_project_contact_lastname", "field_project_coverage", "field_project_finanzierung", "field_project_id", "field_project_institution_addr", "field_project_institution_name", "field_project_institution_web", "field_project_keywords", "field_project_number", "field_project_settings", "field_project_status", "field_project_targetgroups", "field_project_targetgroups_main", "status", "uid"]), highlight_pre_tag: "<em>", highlight_post_tag: "</em>", crop_marker: "…", matching_strategy: Last, attributes_to_search_on: None }

Broken v2.0.1 based search, loading the search page
[2024-04-24T12:29:32Z DEBUG meilisearch::routes::indexes::search] search called with params: SearchQuery { q: Some(""), vector: None, hybrid: None, offset: 0, limit: 20, page: None, hits_per_page: None, attributes_to_retrieve: None, attributes_to_crop: None, crop_length: 10, attributes_to_highlight: None, show_matches_position: false, show_ranking_score: false, show_ranking_score_details: false, filter: None, sort: Some(["field_project_number:desc"]), facets: None, highlight_pre_tag: "<em>", highlight_post_tag: "</em>", crop_marker: "…", matching_strategy: Last, attributes_to_search_on: None }

Note facets: None where the old version correctly queried the necessary facets.

Dug deeper still.

The request that should get the facets is the following:
curl -X POST -H 'Content-Type: application/json' -H 'Authorization: Bearer APIKEY' --data-binary '{ "facetName": "field_project_category" }' 'http://localhost:7700/indexes/project_index/facet-search'
And it returns
{"facetHits":[],"facetQuery":null,"processingTimeMs":0}

So this does not seem to be search_api_meilisearch's fault in the querying step.

The index has field_project_category as one of its filterable attributes if I query them:

curl -H 'Authorization: Bearer APIKEY' -X GET 'http://localhost:7700/indexes/project_index/settings/filterable-attributes'

I am pretty much at my wit's end.
It seems the index is to blame, but
a) How do I fix it?
and
b) If I let search_api_meilisearch create everything anew, it still does not work, so it seems there is some bug in the index creation step as well.

Any clues?

🐛 Bug report
Status

Active

Version

2.0

Component

Facets

Created by

🇦🇹Austria tgoeg

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @tgoeg
  • 🇦🇹Austria tgoeg

    This seems to be https://github.com/meilisearch/meilisearch/issues/4060 as we have a numerical field in this index.
    Switching it to string for this field fixes it for us.

    I see two issues:

    1. This very issue. We know there are only a handful of users using v1.x. They also have to have a numerical field and facets. If they upgrade, they will see this issue (i.e., have a working setup, upgrade, have a broken setup). For the time being and the probability of this to actually happen, I think this issue here is enough for documentation purposes.
    2. The other part however is the general problem that this poses. As this does not stem from upgrading at all, I will open another issue: 🐛 Using facets on numerical fields makes them disappear Active

    If maintainers feel this is good enough then this issue can be closed.

Production build 0.71.5 2024