Can I pass array object in algolia facets

I am having data like
Work=[{
“value”:test,
“name”:test123
}]
now what i want is i am using Work.value as my facet but I want the whole object of Work matching the criteria in facets
Is it possible
thanks.

Hi @mayuripansuriya0812,

I’m not sure to understand what you’re trying to achieve. Can you give us more detail about your use case?

From my understanding if you want to match the whole Work object with value to be test and name to be test123, then you need to declare two facets: Work.name and Work.value.

  index.setSettings({
  attributesForFaceting: [
    'Work.name',
    'Work.value',
  ]
});

I am using Work.name as my facet but in front end side I want both value and name in single object.
As the name can be “yellow-color” and value will be “yellow color” .So what i want is filter the data based on name but display same by value.

Can you copy/paste a sample of the hits that are returned by Algolia when filtering on the name? Did you have a specific configuration for Attributes to retrieve?

Hello,

I’m writing on this thread because I’m in the exact same usecase. Right now we have the following facet:

attributesForFaceting [
  'category.name'
]

which is return by Algolia API as:

"facets": {
  "category.name": {
    "4x4": 1,
    "Bateaux moteur": 1,
    "Equipages": 1,
    "Informatique": 1,
    "Voiturettes": 1
  }
}

Our categories have slug which are used in URL (for example category Voiturettes will have a slug such as voiturettes-4 which is used in url like domain.com/categories/voiturettes-4).

Our use case scenario is as follow: when a use click on a category facet, we need to go to that specific url domain.com/categories/voiturettes-4?search=suzuki.

In order to do that, we would ideally need the engine to also return the slug, something like this would be very useful:

"facets": {
  "category": {
    13: {
      "name": "4x4",
      "slug": "4x4-5"
    },
    9: {
      "name": "Bateaux moteur",
      "slug": "bateaux-moteur-12"
    }
  }
}

This is just an example, the important for us would be the ability to get counters along with the entire category object instead of just plain category name as text.

Any idea how to achieve that ?

For now, and based on what @marielaure.thuret said here Can I pass array object in algolia facets
we ended up adding category.slug as facet:

 attributesForFaceting [
  'category.name',
  'category.slug'
]

This way, the API is returning both and we can build something that make sense for us with Javascript:

"facets": {
  "category.name": {
    "Bateaux moteur": 1
  },
  "category.slug": {
    "bateaux-moteur-5": 1
  }
}

It works well but here we are (dangerously) assuming/relying on the fact that the ordering will always be the same. Anyone can confirm that ?