DomDew/strapi-plugin-fuzzy-search

Filtering for only published entries not working

piterson-satio opened this issue · 4 comments

Hello, we're using this fuzzy search plugin for our strapi project for the site search, but recently we discovered that it doesn't filter out unpublished/draft entries by default, however even by adding filters to publishedAt and publicationState, the draft entries are still showing up.

Request:
/api/fuzzy-search/search?query=tes&filters[contentTypes]=static-pages&filters[static-pages][publishedAt][$notNull]=true

Result:

{
  "static-pages": [
    {
      "id": 9,
      "title": "tes page",
      "description": "tes",
      "slug": "tes-page",
      "createdAt": "2023-07-28T08:58:55.933Z",
      "updatedAt": "2023-07-28T08:58:55.933Z",
      "publishedAt": null, // note that the publishedAt is null
      "attached_seo_meta_data": null,
      "contents": []
    }
  ]
}

Here's the config object for the collection type we used in /config/plugins.js in case it's relevant.

"fuzzy-search": {
    enabled: true,
    config: {
      contentTypes: [
        // ...
        {
          uid: "api::static-page.static-page",
          modelName: "static-page",
          queryConstraints: {
            populate: true,
          },
          fuzzysortOptions: {
            characterLimit: 500,
            threshold: -1000,
            limit: 10,
            keys: [
              {
                name: "title",
                weight: 100,
              },
              {
                name: "description",
                weight: 100,
              },
              {
                name: "contents",
                weight: 100,
              },
            ],
          },
        },
      ],
    },
  }

Thanks in advance!

DomDew commented

Hey @piterson-satio,

thank you for reporting this bug! I just tried to reproduce your example but for me everything works as expected.

With /api/fuzzy-search/search?query=unpublished&filters[contentTypes]=with-spaces&filters[with-spaces][publishedAt][$notNull]=true I get the expected result of:

// http://localhost:1337/api/fuzzy-search/search?query=unpublished&filters[contentTypes]=with-spaces&filters[with-spaces][publishedAt][$notNull]=true

{
  "with-spaces": [ ]
}

Whereas:

// http://localhost:1337/api/fuzzy-search/search?query=unpublished&filters[contentTypes]=with-spaces

{
  "with-spaces": [
    {
      "id": 7,
      "title": "unpublished",
      "createdAt": "2023-07-31T08:46:38.789Z",
      "updatedAt": "2023-07-31T08:46:38.789Z",
      "publishedAt": null
    }
  ]
}

Could you specify which versions of the package and of Strapi you are on?

Hello, thanks for the reply. Currently we're using Strapi v4.9.0 with the version of the package in the package.json as 1.11.0-beta.1. Do you have a recommended version of the fuzzy search plugin that would be compatible for our current strapi version? Or do we have to use the newest version for this to work?

DomDew commented

Hey hey,

ideally I'd suggest you upgrade to both the latest Strapi version and the latest version of the package (v2.0.4). If you want to stay on your Strapi version (v4.9.0) I think v2.0.3 should work for you - Strapi published a breaking change with the release of Strapi v4.11.4 (the way they compile their utils with typescript) which v2.0.4 accommodates for but renders the package incompatible with Strapi versions <= 4.11.3...

Hi, the v2.0.3 of the plugin works for our v4.9.0 strapi project, thanks a lot for the help!