Sort array of objects by matchLevel

I have records on algolia. Each record contains an array of meals. Each meal has a title.
One of my searchable attributes is meal.title
An example of hits searching for “pizza”, I see for instance one of the objects with this:

...
"meals": Array [
  Object {
    "title": Object {
      "matchLevel": "none",
      "matchedWords": Array [],
      "value": "Green salad",
    },
    "description": Object {
      "fullyHighlighted": false,
      "matchLevel": "full",
      "matchedWords": Array [
        "pizza",
      ],
      "value": "Pepperoni <em>pizza</em> for the brave in heart",
    },
  },
],
...

When returning the object from Algolia, I would like to have the array sorted by matchLevel. Is it possible? How?
If not, is there a way to return some field from the meals array objects in the hits? This way I could sort the array when receiving the results. It’s not as nice, but could work. So for instance if the results would look something like this (adding the id of the object), then I could sort the array by the object id:

...
"meals": Array [
  Object {
    "title": Object {
      "matchLevel": "none",
      "matchedWords": Array [],
      "value": "Green salad",
      "id": "293847ksadjhfdsaf"
    },
    "description": Object {
      "fullyHighlighted": false,
      "matchLevel": "full",
      "matchedWords": Array [
        "pizza",
      ],
      "value": "Pepperoni <em>pizza</em> for the brave in heart",
      "id": "bhflkj098dfgklsdf"
    },
  },
],
...

What do you guys recommend?

Hi,

It seems that you are looking at the _hightlightResults field which is quite specific to highlighting. Algolia does not provide any capabilities to sort by match level or to include additional information in this field. This filtering and augmentation is a post-processing step that is up to the implementer.

I am not 100% sure what your use case is, but assuming it is that you want to push up in the array of meals the keywords that the user searched for, I can maybe invite to look at what we did for the Places.js library where we have a somewhat similar sorting & rendering strategy: places/formatHit.js at master · algolia/places · GitHub

Finally, you can control which attributes are included in the highlighting using attributesToHighlight | API parameters | API Reference | Algolia Documentation. This will not add fields to the “match” object, but it will apply it to all the fields that defined in this array of attributes, meaning that for instance your meals array could look like this:

{
  meals: [
    {
      title: { matchLevel: "none", value: "Green salad", ... },
      description: { matchLevel: "none", ... },
      mealID: { matchLevel: "none", value: "someMealId", ... },
    },
    {
      title: { matchLevel: "full", value: "Pepperoni <em>pizza</em>", ... },
      description: { matchLevel: "full", ... },
      mealID: { matchLevel: "none", value: "someOtherMealId", ... },
    },
    ...
  ]
}

I hope this answers your question.
Best,