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
https://www.npmjs.com/package/strapi-plugin-fuzzy-search
MIT License
70 stars 19 forks source link

Fuzzy return data is in a different structure to strapi rest query data #167

Open gregg-cbs opened 6 months ago

gregg-cbs commented 6 months ago

Hi,

There is inconsistencies in your data response vs strapi rest api data response which is creating an anti-pattern.

When populating on fuzzy search we get back results like this:

[
  {
    "id": 4,
    "name": "YurMart",
    "banner": { // populated field
      "id": 79,
      "url": "https://ik.imagekit.io/cbs/ticketland/dev/crowd.jpg_FCCgK-CSL.png",
      "type": "image"
    }
  }
]

But in strapi rest api the root and populated results are nested in "data" and "attributes" properties:

[
  {
    "id": 4,
    "attributes": {  // nested in attributes
      "name": "YurMart",
      "banner": { // rest api populated field
        "data": {
          "id": 79,
          "attributes": {
            "url": "https://ik.imagekit.io/cbs/ticketland/dev/crowd.jpg_FCCgK-CSL.png",
            "type": "image"
          }
        }
      }
    }
  }
]

I tried to ditch the initial strapi rest api query for fuzzy search just to return some initial data for page load but you cannot use fuzzy search without passing a search query.

What do you recommend?

gregg-cbs commented 6 months ago

I can also see in your docs that graphql fuzzy search returns the data correctly. So it is just the rest portion of it.

DomDew commented 6 months ago

@gregg-cbs Thanks for bringing this up. I'll include this in the next major version bump 🙂