Skip to content

Commit

Permalink
Search by section
Browse files Browse the repository at this point in the history
  • Loading branch information
ksuess committed Feb 1, 2023
1 parent 6913a84 commit d0ab19a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 20 deletions.
41 changes: 31 additions & 10 deletions src/components/Searchkit/CustomESRequestSerializer.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extend, isEmpty, trim } from 'lodash';
import { extend, isEmpty, keyBy, trim } from 'lodash';
import { getObjectFromObjectList } from '../helpers.jsx';

import { listFilterFields } from './constants.js';
Expand All @@ -10,6 +10,7 @@ export class CustomESRequestSerializer {
this.facet_fields = getObjectFromObjectList(config.facet_fields);
this.allowed_content_types = config.allowed_content_types;
this.allowed_review_states = config.allowed_review_states;
this.search_sections = config.search_sections;
}
/**
* Convert Array of filters to Object of filters
Expand Down Expand Up @@ -277,6 +278,18 @@ export class CustomESRequestSerializer {
review_state: this.allowed_review_states,
},
});
// Push section.
const filters_dict = keyBy(filters, (e) => {
return e[0];
});
const section = filters_dict['section'];
if (section && section[1] !== 'others') {
terms.push({
terms: {
section: [section[1]],
},
});
}

let filter = [];
if (filters.length) {
Expand Down Expand Up @@ -331,16 +344,24 @@ export class CustomESRequestSerializer {
if (!isEmpty(filter)) {
post_filter['bool']['filter'] = [...filter];
}
// TODO section path
// Obsolete with portal types configurable in block
// if (true) {
// post_filter['bool']['must'].push({
// terms: {
// portal_type: ['Manual'],
// },
// });
// }

// Exclude sections
if (section && section[1] === 'others') {
post_filter['bool']['must_not'] = [
{
terms: {
section: this.search_sections.items.map((el) => {
return el.section;
}),
},
},
];
}
bodyParams['post_filter'] = post_filter;
console.debug(
"bodyParams['post_filter']['bool']",
bodyParams['post_filter']['bool'],
);

/**
* Aggregations
Expand Down
1 change: 1 addition & 0 deletions src/components/Searchkit/ESSearchApi.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class PloneSearchApi {
facet_fields: config.facet_fields,
allowed_content_types: config.allowed_content_types,
allowed_review_states: config.allowed_review_states,
search_sections: config.search_sections,
});
this.responseSerializer = new responseSerializerCls({
backend_url: config.backend_url,
Expand Down
25 changes: 17 additions & 8 deletions src/components/Searchkit/SectionsSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const _SectionsSearch = ({
const restrictSearchToSection = (section) => {
console.debug('restrictSearchToSection');
setActiveSection(section);
let foo = {
let kitquerystate = {
sortBy: 'modified',
sortOrder: 'desc',
layout: 'list',
Expand All @@ -21,13 +21,22 @@ const _SectionsSearch = ({
filters: currentQueryState.filters,
};
if (currentQueryState.queryString) {
foo.queryString = currentQueryState.queryString;
kitquerystate.queryString = currentQueryState.queryString;
}
if (section !== 'all') {
foo.filters.push(['sectionpath', section]);
// Replace filter 'section'
kitquerystate.filters = kitquerystate.filters.filter((el) => {
return el[0] !== 'section';
});
if (section === 'all') {
// pass
} else if (section === 'others') {
kitquerystate.filters.push(['section', section]);
} else {
kitquerystate.filters.push(['section', section]);
}
console.debug('foo', foo);
updateQueryState(foo);

console.debug('kitquerystate.filters', kitquerystate.filters);
updateQueryState(kitquerystate);
};

return (
Expand All @@ -43,8 +52,8 @@ const _SectionsSearch = ({
) : null}
{search_sections.items?.length > 0 && allow_search_excluded_sections ? (
<button
className={activeSection === 'website' ? 'active' : ''}
onClick={() => restrictSearchToSection('website')}
className={activeSection === 'others' ? 'active' : ''}
onClick={() => restrictSearchToSection('others')}
>
Website
</button>
Expand Down
5 changes: 3 additions & 2 deletions src/components/Views/FacetedSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const ploneSearchApi = (data) => {
facet_fields: data.facet_fields,
allowed_content_types: data.allowed_content_types,
allowed_review_states: data.allowed_review_states,
search_sections: data.search_sections,
backend_url: data.backend_url,
frontend_url: data.frontend_url,
elastic_search_api_url: data.elastic_search_api_url,
Expand Down Expand Up @@ -113,8 +114,8 @@ class _ExtraInfo extends React.Component {
<Item.Extra>
{Object.keys(extrainfo_fields).map((extrainfo_key, idx) => {
if (!result[extrainfo_key]) {
console.debug('not indexed:', extrainfo_key);
return;
// console.debug('not indexed:', extrainfo_key);
return null;
}
const extrainfo_value = Array.isArray(result[extrainfo_key])
? result[extrainfo_key]
Expand Down

0 comments on commit d0ab19a

Please sign in to comment.