Model Variants and Editions
A catalogue often has one work with several editions or variants: a book in hardback, paperback and e-book; a product in three colours and two sizes. Users want one result card per work, but they want to filter at variant level ("paperback under 200 kr").
Indx does this without a group-by step: put the variants inside the document as an array.
One document per work
{
"id": 4711,
"title": "Sult",
"author": "Knut Hamsun",
"editions": [
{ "isbn": "9788205001954", "format": "paperback", "price": 149, "inStock": true },
{ "isbn": "9788205001961", "format": "hardback", "price": 349, "inStock": false },
{ "isbn": "9788205001978", "format": "ebook", "price": 99, "inStock": true }
]
}Init names the nested fields editions.isbn, editions.format, editions.price and
editions.inStock, each holding one value per array element. Mark them Filterable and
Facetable as usual.
Filtering at variant level
A value or range filter on an array field matches the document if any element matches. Combine filters with AND to require the same document to satisfy all of them:
// paperbacks under 200
POST …/filters/value { "fieldName": "editions.format", "value": "paperback" } → A
POST …/filters/range { "fieldName": "editions.price", "lowerLimit": 0, "upperLimit": 200 } → B
POST …/filters/combine { "a": A, "b": B, "useAndOperation": true }Note the semantics: the combined filter matches documents that have a paperback edition
and an edition under 200. For most catalogues those are the same edition; when they must
be, denormalise a combined field ("formatPrice": "paperback:149") or keep one document per
edition and accept multiple cards.
Facets on editions.format count documents, not editions — "paperback (312)" means 312 works
have a paperback edition.
What RemoveDuplicates does — and does not — do
Query.RemoveDuplicates (default true) keeps only the best-scoring document among those
that share the same foreign key. It is not a group-by on arbitrary fields: it will not
collapse three separate edition documents into one card. If your source gives you one row per
edition, merge them into one document per work before loading, as above.
Showing the right edition on the card
Search results return the whole document, so the card can pick the edition to display —
the cheapest in stock, or the one matching the active format filter — client-side from the
editions array. No second request is needed.