From 9f7224df969083973ab6275eadb22a588e800ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Z=C3=BCbeyde=20Civelek?= Date: Wed, 11 Feb 2026 21:50:45 +0100 Subject: [PATCH] demos: add range facet to opensearch and videos --- src/demos/cern-videos/App.js | 16 ++++++ src/demos/opensearch/App.js | 12 +++++ .../opensearch/DemoOSRequestSerializer.js | 54 +++++++++++++++++-- 3 files changed, 77 insertions(+), 5 deletions(-) diff --git a/src/demos/cern-videos/App.js b/src/demos/cern-videos/App.js index 0c3a2f57..98676606 100644 --- a/src/demos/cern-videos/App.js +++ b/src/demos/cern-videos/App.js @@ -14,6 +14,7 @@ import { Accordion, Card, Container, Grid, Image, Item, Menu } from "semantic-ui import { InvenioSearchApi } from "../../lib/api/contrib/invenio"; import { BucketAggregation, + RangeFacet, EmptyResults, Error, ReactSearchKit, @@ -180,6 +181,21 @@ export class App extends Component { + +
+ { - const obj = {}; + Object.keys(aggValueObj).forEach((aggName) => { + const values = aggValueObj[aggName]; + if (aggName === "years") { + const rangeValue = values[0]; + if (!rangeValue) return; + + const [fromPart, toPart] = rangeValue.split(".."); + if (!fromPart || !toPart) return; + + const fromYear = fromPart.slice(0, 4); + const toYear = toPart.slice(0, 4); + + const gte = fromPart.length > 4 ? fromPart : `${fromYear}-01-01`; + const lte = toPart.length > 4 ? toPart : `${toYear}-12-31`; + + mustClauses.push({ + range: { + date: { gte, lte }, + }, + }); + + return; + } const fieldName = aggFieldsMapping[aggName]; - obj[fieldName] = aggValueObj[aggName]; - return { terms: obj }; + if (fieldName) { + mustClauses.push({ + terms: { + [fieldName]: values, + }, + }); + } }); - bodyParams["post_filter"] = { bool: { must: terms } }; + + if (mustClauses.length) { + bodyParams.post_filter = { + bool: { + must: mustClauses, + }, + }; + } } // simulate a backend that defines all the possible complex aggregations per index @@ -114,6 +148,16 @@ export class DemoOSRequestSerializer { }; _extend(bodyParams["aggs"], aggBucketNestedEmployeeType); + _extend(bodyParams.aggs, { + years: { + date_histogram: { + field: "date", + calendar_interval: "year", + format: "yyyy", + }, + }, + }); + return bodyParams; }; }