Jan
08/27/2024, 9:31 AM{
"title": "test",
"dates": [
{
"from_date": "2024-08-26",
"till_date": "2024-08-30",
"available": true,
"preview": false,
"mp": 2
},
{
"from_date": "2024-09-26",
"till_date": "2024-09-30",
"available": true,
"preview": false,
"mp": 2
},
{
"from_date": "2024-10-26",
"till_date": "2024-10-30",
"available": true,
"preview": false,
"mp": 2
},
{
"from_date": "2024-11-02",
"till_date": "2024-11-07",
"available": false,
"preview": true,
"mp": 2
}
]
}
My goal is to find all the documents matching a query like "from_date and till_date in Oktober 2024" (or any other range). Or combinations like in october an preview == true.
What I understood from the documentation and git issues: There is currently no good solution to do this without flattening the data.
Flatten the Array and include multiple entries is no problem and works great (I think).
But: I lose a lot of possiblities with the result set. Because every Trip is in the result 1-20 times. so all counts are off.
is there a good way to "unflatten" the result back in typesense?
I would think this is a common problem, but did not find a good solution.
Thank you!Fanis Tharropoulos
08/27/2024, 9:37 AMJan
08/27/2024, 9:42 AMFanis Tharropoulos
08/27/2024, 9:43 AMTo simplify traversing the data in the results, you might want to send both the flattened and unflattened version of the nested fields into Typesense, and only set the flattened keys as indexed in the collection's schema and use them for search/filtering/faceting. At display time when parsing the results, you can then use the nested version.You could then take a look at the Curation feature, with which you can set organic filtering by query (for example, if a query contains the sentence
available
inside, filter by only available events etc. There's a more visual way of handling curation over at Typesense Cloud (the hosted SaaS product of Typesense), which has a Dashboard that includes many more features other than curationJan
08/27/2024, 9:45 AMJan
08/27/2024, 9:48 AMJan
08/27/2024, 9:52 AMfrom_date:> '2024-10-01 as timestamp && from_date:< '2024-10-31 as stimestamp' && preview == true
Fanis Tharropoulos
08/27/2024, 9:53 AMreduce()
you could use some grouping parameters https://typesense.org/docs/26.0/api/search.html#grouping-parameters if you plan to aggregate resultsFanis Tharropoulos
08/27/2024, 9:54 AMIf i understood the documentation correct, my search would not be possible in that structure:
You can also use ranges for numeric filtering:from_date:> '2024-10-01 as timestamp && from_date:< '2024-10-31 as stimestamp' && preview == true
Numeric Filtering:
Filter documents with numeric values between a min and max value, using the range operatoror using simple comparison operators[min..max]
,>
>=
,<
,<=
.=
You can enableon the numerical field schema for fast range queries (will incur additional memory usage for the index though)."range_index": true
Examples:
-num_employees:[10..100]
-num_employees:<40
-(Filter docs where value is between 10 to 100 or exactly 40).num_employees:[10..100,40]
Jan
08/27/2024, 9:56 AMFanis Tharropoulos
08/27/2024, 9:58 AMFanis Tharropoulos
08/27/2024, 10:01 AMdate-fns
Fanis Tharropoulos
08/27/2024, 10:02 AMJan
08/27/2024, 10:05 AM{"q":"Zucker","query_by":"*","group_by":"nr","group_limit":1,"per_page":30,"filter_by":"fd:[1725148800..1727740800]"}
is my last attempt on using the grouping feature.
the problem here is that the result is now grouped into 1 element arrays
like this
result["grouped_hits"][0]["hits"]
i would need to result['grouped_hits'].map{ |gh| gh['hits'].first }
but with this i lost all of your sorting and counting options, correct?Jan
08/27/2024, 10:06 AMMind you, I would avoid doing this on blur, as it can be computationally intensive and lead to lag, but it is possiblewhat do you mean with "doing it on blur"?
Fanis Tharropoulos
08/27/2024, 10:07 AMJan
08/27/2024, 10:08 AMFanis Tharropoulos
08/27/2024, 10:11 AMJan
08/27/2024, 10:30 AMFanis Tharropoulos
08/27/2024, 10:57 AMJason Bosco
08/27/2024, 9:59 PM