Skip to content

Commit

Permalink
dummy es filter for updating the search filter counts
Browse files Browse the repository at this point in the history
  • Loading branch information
ksuess committed May 17, 2021
1 parent 1a3f2e2 commit 1ae224b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 37 deletions.
74 changes: 61 additions & 13 deletions src/components/Searchkit/CustomESRequestSerializer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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] },
},
},
},
},
},
},
Expand All @@ -250,7 +296,9 @@ export class CustomESRequestSerializer {
};
}

// payload demo
/**
* payload demo
*/
/*
{
"size": 10,
Expand Down
37 changes: 13 additions & 24 deletions src/components/Views/FacetedSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -431,7 +431,7 @@ const FacetedSearch = ({
overriddenComponents = overriddenComponents ?? {
...defaultOverriddenComponents,
...(filterLayout === 'dropdown' && dropdownOverriddenComponents),
}
};

const dispatch = useDispatch();

Expand All @@ -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',
Expand Down Expand Up @@ -563,36 +550,38 @@ const FacetedSearch = ({
<Grid.Row>
<Grid.Column
width={12}
className={
'facetedsearch_filter ' + filterLayout
}
className={'facetedsearch_filter ' + filterLayout}
>
<BucketAggregation
title="Komponenten"
agg={{
field: 'kompasscomponent',
aggName: 'kompasscomponent_agg.kompasscomponent_token',
aggName:
'kompasscomponent_agg.inner.kompasscomponent_token',
}}
/>
<BucketAggregation
title="Informationstyp"
agg={{
field: 'informationtype',
aggName: 'informationtype_agg.informationtype_token',
aggName:
'informationtype_agg.inner.informationtype_token',
}}
/>
<BucketAggregation
title="Zielpublikum"
agg={{
field: 'targetaudience',
aggName: 'targetaudience_agg.targetaudience_token',
aggName:
'targetaudience_agg.inner.targetaudience_token',
}}
/>
<BucketAggregation
title="Organisationseinheit"
agg={{
field: 'organisationunit',
aggName: 'organisationunit_agg.organisationunit_token',
aggName:
'organisationunit_agg.inner.organisationunit_token',
}}
/>
</Grid.Column>
Expand Down

0 comments on commit 1ae224b

Please sign in to comment.