1

I want to add elements to an array, or remove some keys from my map in my custom searcher results in Vespa.

For ex: I have the following fields in my hit of the searcher:

fields:
    n: 0,
    myArray: [0, 1, 2]
    myMap: {"key1":"value1", "key2":"value2"}

I want to append values (3, 4) to my array and remove a key (key2) from my map, in the result hits, to return:

fields:
    n: 0,
    myArray: [0, 1, 2, 3, 4]
    myMap: {"key1":"value1"}

I have followed the reference link Inspecting Structured Data but I am unable to add or remove entries from the Inspector Object that I have created. I don't want to create a new SlimeAdapter Object for my array/struct. As this will need to traverse the array completely and add individual entries to my new object, which I want to avoid.

Please, suggest an approach for the same.

1 Answers1

1

All the fields values returned from hits are read-only. There are several reasons for this but the most important one is performance.

If you want to edit the structured data of a field in a Searcher you either need to traverse it completely, or create a wrapper which keeps track of your edits and produces a view consisting of the read-only data with your changes applied.

You mention you don't want to do the first option. If that is for observed performance reasons you could consider the second option.

And if you do that one generally please consider contributing it back.

Jon
  • 2,043
  • 11
  • 9