From 1ae224ba4aba48438024defbaa19337e0ffb86cd Mon Sep 17 00:00:00 2001 From: ksuess Date: Mon, 17 May 2021 09:36:11 +0200 Subject: [PATCH] dummy es filter for updating the search filter counts --- .../Searchkit/CustomESRequestSerializer.jsx | 74 +++++++++++++++---- src/components/Views/FacetedSearch.jsx | 37 ++++------ 2 files changed, 74 insertions(+), 37 deletions(-) diff --git a/src/components/Searchkit/CustomESRequestSerializer.jsx b/src/components/Searchkit/CustomESRequestSerializer.jsx index ea447ba9..616fbfaa 100644 --- a/src/components/Searchkit/CustomESRequestSerializer.jsx +++ b/src/components/Searchkit/CustomESRequestSerializer.jsx @@ -188,15 +188,15 @@ export class CustomESRequestSerializer { } return accumulator; }, []); - // console.debug('serialize: filter', filter); + console.debug('serialize: filter', filter); } const post_filter = { bool: { must: terms } }; - console.debug('filter', filter); + // console.debug('filter', filter); if (filter.length) { post_filter['bool']['filter'] = filter; } - console.debug('post_filter', post_filter); + // console.debug('post_filter', post_filter); bodyParams['post_filter'] = post_filter; // aggregations @@ -222,20 +222,66 @@ export class CustomESRequestSerializer { // console.debug('aggs', fieldName, nestedFields.includes(fieldName)); if (nestedFields.includes(fieldName)) { // console.log('fieldName in nestedFields:', fieldName, aggName); + + const filter_debug = { + nested: { + path: 'informationtype', + query: { + bool: { + must: [ + { + terms: { + 'informationtype.token': ['Anleitung', 'FAQ'], + }, + }, + ], + }, + }, + }, + }; + + // const aggBucketTermsComponent_old = { + // [myaggs[0]]: { + // nested: { + // path: fieldName, + // }, + // aggs: { + // [myaggs[1]]: { + // terms: { + // field: fieldName + '.token', + // order: { _key: 'asc' }, + // }, + // aggs: { + // somemoredatafromelasticsearch: { + // top_hits: { size: 1, _source: { include: [fieldName] } }, + // }, + // }, + // }, + // }, + // }, + // }; const aggBucketTermsComponent = { [myaggs[0]]: { - nested: { - path: fieldName, - }, + filter: filter_debug, // TODO filter aggs: { - [myaggs[1]]: { - terms: { - field: fieldName + '.token', - order: { _key: 'asc' }, + inner: { + nested: { + path: fieldName, }, aggs: { - somemoredatafromelasticsearch: { - top_hits: { size: 1, _source: { include: [fieldName] } }, + [myaggs[1]]: { + terms: { + field: fieldName + '.token', + order: { _key: 'asc' }, + }, + aggs: { + somemoredatafromelasticsearch: { + top_hits: { + size: 1, + _source: { include: [fieldName] }, + }, + }, + }, }, }, }, @@ -250,7 +296,9 @@ export class CustomESRequestSerializer { }; } -// payload demo +/** + * payload demo + */ /* { "size": 10, diff --git a/src/components/Views/FacetedSearch.jsx b/src/components/Views/FacetedSearch.jsx index 042f5f89..877446ef 100644 --- a/src/components/Views/FacetedSearch.jsx +++ b/src/components/Views/FacetedSearch.jsx @@ -411,15 +411,15 @@ const initialState = { }; /** - * + * FacetedSearch * @param {string} filterLayout default 'dropdown' * @param {object} overriddenComponents Override with custom components, ignore to stay with default 'dropdown' or step back to react-searchkit default components with value {} - * @returns + * @returns */ const FacetedSearch = ({ data, overriddenComponents, - filterLayout = config.settings.searchkitblock.filterLayout + filterLayout = config.settings.searchkitblock.filterLayout, }) => { const { search_url = data.elastic_search_api_url || 'http://localhost:9200', @@ -431,7 +431,7 @@ const FacetedSearch = ({ overriddenComponents = overriddenComponents ?? { ...defaultOverriddenComponents, ...(filterLayout === 'dropdown' && dropdownOverriddenComponents), - } + }; const dispatch = useDispatch(); @@ -452,19 +452,6 @@ const FacetedSearch = ({ }, }); - // useEffect(() => { - // // TODO set value of input field - // let searchParams = new URLSearchParams(location?.search); - // let q = searchParams.get('q'); - // // console.debug('FNView useEffect: querystring of location', q, location); - // }, [location, dispatch]); - - // const onResetSearch = () => { - // console.log('reset searchstring'); - // updateQueryString(''); - // console.log('searchstring reseted'); - // }; - const payloadOfReset = { searchQuery: { sortBy: 'bestmatch', @@ -563,36 +550,38 @@ const FacetedSearch = ({