Hello <@U01PL2YSG8L> ```I am searching for produc...
# community-help
h
Hello @Kishore Nallan
Copy code
I am searching for products in Typesense using title or variants.title, and it works fine.
Each product has multiple variants stored as an array.
My requirement is: when a user searches for a term, the best-matching variant should be placed first in the variants array in the search response (because by default we show the first variant's data).

Example:
    product_data = {
                    "id": "1",
                    "title": "shirt",
                    "variants": [
                        { "title": "red", "image": "1.png" },
                        { "title": "blue", "image": "2.png" },
                        { "title": "green", "image": "3.png" }
                    ]
                }

    Search term: "green shirt"

    // Required response from Typesense:
    response = {
                "id": "1",
                "title": "shirt",
                "variants": [
                    { "title": "green", "image": "3.png" },
                    { "title": "red", "image": "1.png" },
                    { "title": "blue", "image": "2.png" }
                ]
            }

In short, I want the matched variant to be reordered to the top of the variants array in the Typesense search result.

Please suggest if there is another way to achieve the same things.
Hi @Kishore Nallan @Jason Bosco can you check please
a
Hi @Hussain Sakariya You mean you want the array (variant.title) of the document returned to be sorted?
h
Yes, the highly matched variant title should be shown at the first index.
@Kishore Nallan Any Updates ?
f
The contents of the array returned in the document will be returned exactly as they were indexed. The sorting has to be done on the client side
h
@Fanis Tharropoulos @Kishore Nallan Let me explain my question another way: if I have one product, a T-shirt, that has multiple variants like red, yellow, and black in a JSON array, and I search for 'red T-shirt', how can I show the red variant by default instead of the other variants?
k
As Fanis said, response returned is the full document in the exact order. The highlight will contain only the matched segment: you can use that to maybe re-order on the client side. There are no flags to control this behavior on server side.
h
okay