Give the possibility to set the attributesToXXX
irevoire opened this issue · comments
Description
I noticed that some of our users, for example meilisearch.com, had large documents but only needs one or two fields.
For example in the case of meilisearch.com we are querying this very large JSON TWICE when all we need is actually the two selected fields;
It would be cool if instant-meilisearch was able to detect which fields are used (but I highly doubt that's possible) or if we could specify ourselves the attributesToRetrieve
, attributesToHighlight
and attributesToCrop
settings.
Basic example
instantMeiliSearch(
process.env.NEXT_PUBLIC_DEMO_MOVIES_HOST,
process.env.NEXT_PUBLIC_DEMO_MOVIES_API_KEY,
{
paginationTotalHits: 4,
primaryKey: 'id',
attributesToRetrieve: ["poster_path"],
attributesToHighlight: ["title"],
}
)
Other
To give you an idea, on meilisearch.com that would make the size of each request goes from 23675 bytes to 980.
Hello!
This is a very good suggestion. This should be working as the the configure
widget is supposed to handle every search parameter of algolia which supports attributesToRetrieve.
I tried it out and it appears to be a bug. When settings a attributesToRetrieve in configure
in throws an error
Exemple:
<Configure
attributesToRetrieve={['name']}
/>
throws:
src.a2b27638.js:55729 TypeError: Cannot read properties of undefined (reading 'toString')
at addEllipsis (src.a2b27638.js:55176:50)
at resolveSnippet (src.a2b27638.js:55208:10)
at adaptSnippet (src.a2b27638.js:55243:27)
at adaptFormating (src.a2b27638.js:55279:95)
at src.a2b27638.js:55365:127
at Array.map (<anonymous>)
at adaptHits (src.a2b27638.js:55359:37)
at adaptSearchResponse (src.a2b27638.js:55409:41)
at Object.<anonymous> (src.a2b27638.js:55722:72)
at step (src.a2b27638.js:50418:17)