1

I have data structured as follows:

{
  "id": 12345,
  "name": "Brother PJ-663 Direct A4 Thermal Mobile Printer",
  "type": "Thermal printer",
  "features": "USB, Mobile Print"
}, 

I'm trying to create a refinementList widget based on the values out of the features string (exploded), same as I do for type, but I'm not sure if this is the right approach or even possible.

How should I format the data to be able to create a single instantsearch.widgets.refinementList widget?

Also I use _tags instead and add each of those features as a tag, would it be possible to achieve this?

1 Answer 1

2

The best way is to reformat (split by ,) your data before indexing and index features and type as arrays:

{
  "id": 12345,
  "name": "Brother PJ-663 Direct A4 Thermal Mobile Printer",
  "type": [
    "Thermal printer"
  ],
  "features": [
    "USB", 
    "Mobile Print"
  ]
}

Then set those attributes as attributes for faceting in Algolia settings and you are good to go. The you can use instantsearch.js's refinementList widget to filter your results according those attributes.

I wouldn't go for _tags here as you have 2 different attributes you want to use for filtering and _tags won't allow you to do it in easy way.

2
  • I already tried that, but then I get as option to filter ["USB", "Mobile Print"], where I would like to end up with two options, "USB" and "Mobile Print".
    – Strnm
    Commented Nov 16, 2016 at 14:01
  • Solved, the problem was the way I was uploading the data, thank you!
    – Strnm
    Commented Nov 16, 2016 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.