How to filter in typesensne collection of objects in Laravel?

444 Views Asked by At

I have item collections and in every item have item_prices collections of objects. Just need filter in item_prices and retrieve item_prices which matching with my parameters. Im sending parameters like this

filter_by = item_prices.priceline_id:=2 && 
            item_prices.company_id:=3 

but it retrieves matched and nonmatched item_prices. How can I filter this correctly? enter image description here

For example now my collection is like this

{
            "document": {
                "Brands": "SCHULTHEISS",
                "Categories": [],
                "id": "1398702",
                "item_prices": [
                    {
                        "company_id": "3",
                        "priceline_id": "0",
                    },
                    {
                        "company_id": "3",
                        "priceline_id": "1",
                    },
                    {
                        "company_id": "3",
                        "priceline_id": "2",
                    },
                    {
                        "company_id": "3",
                        "priceline_id": "3",
                    },
}

but when im filtering item_prices.priceline_id:=2 && item_prices.company_id:=3

result must be like this

    {
            "document": {
                "Brands": "SCHULTHEISS",
                "Categories": [],
                "id": "1398702",
                "item_prices": [
                    {
                        "company_id": "3",
                        "priceline_id": "2",
                    }
}
1

There are 1 best solutions below

0
yco On

Typesense will return full documents that have matches, hence the returned document will have all your item_prices and you will have to filter the item_prices yourself.

The only thing that Typesense guarantees, is that the document has some item_prices matching your filter