DomDew / strapi-plugin-fuzzy-search

Register a weighted fuzzy search endpoint for Strapi Headless CMS you can add your content types to in no time

Home Page:https://www.npmjs.com/package/strapi-plugin-fuzzy-search

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

locale must be at most 2 characters

amityweb opened this issue · comments

We are using the 4 character locales in Strapi, e.g. fr-FR

But when using fuzzy search it wont allow it:
/api/fuzzy-search/search/?query=c&locale=fr-FR

{"data":null,"error":{"status":400,"name":"BadRequestError","message":"Invalid query","details":"locale must be at most 2 characters"}}

Does not seem to work anyway, am I doing something wrong?

The following URL returns no results even though I have a page with title products in Spanish (es). en works OK.
http://localhost:1337/api/fuzzy-search/search?query=pro&locale=es

The following graphql returns the en/default pages:

query {
  search(query: "pro", locale: "es") {
    pages {
      data {
        attributes
        {
          slug
          title
        }
      }
    }
    products {
      data {
        attributes {
          slug
          name
          description
        }
      }
    }
  }
}

Hey @amityweb,

thank you for bringing this up!

Which version are you on? If you are on 2.0.3 I‘d suggest you either rollback to 2.0.2 or try passing the locale as a filter for the content type (on 2.0.3). I might have introduced a bug with the latest update.

I was on 2.0.3 and downgraded to 2.0.2 but still get the issue. My npm install output states fuzzy-search needs yup but I need to install manually, so did that, but still same issue.

If you think it really should be working then could it be an issue my side? Is the code correct? I have published all the pages.

Using the filters returns empty/no results. Replacing es below with en works OK.

query {
  search(query: "pro") {
    pages(filters: {locale: {eq:"es"}}) {
      data {
        attributes
        {
          slug
          title
        }
      }
    }
    products {
      data {
        attributes {
          slug
          name
          description
        }
      }
    }
  }
}

@amityweb

everything looks good on your end… It‘s weird that you are getting results for en but not for es. Could you check if you are getting results for any of Strapis default endpoints with that filter applied?

Unfortunately I can‘t troubleshoot right now and am sorry that I can‘t be of much help… I will get back to this as soon as possible. If the Strapi endpoints also return no results, you could try rolling back to an earlier v1 version. I had the locale filtering (by passing locale arg) running since the earliest versions…

Going to the following on Strapi does return the other language pages yes:
http://localhost:3000/api/pages?locale=es

Calling pages using GraphQL also works, as the pages themselves work on the website, they show the other language content.

Its just via fuzzy-search api there's no results when using locale=es (or any other language, or non-existent language).

Thanks

Fixed in v2.0.5

@all-contributors please add @amityweb for bug

@DomDew

I've put up a pull request to add @amityweb! 🎉

Fantastic, I think both issues are solved now, the 4 character locale fr-FR and search results also show. Thanks a lot.