Skip to content

Commit

Permalink
added new permanent filter, so we can exclude some documents from glo…
Browse files Browse the repository at this point in the history
…bal search
  • Loading branch information
zotya committed Aug 18, 2023
1 parent b9e3d98 commit 4a1095b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
48 changes: 26 additions & 22 deletions src/config/filters.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
import { getTodayWithTime } from '../utils';

export default {
// filter values that are always added to the ES requests
permanentFilters: [
{ term: { hasWorkflowState: 'published' } },
() => ({
constant_score: {
filter: {
bool: {
should: [
{
bool: {
must_not: {
exists: {
field: 'issued',
},
function constantScore() {
return {
constant_score: {
filter: {
bool: {
should: [
{
bool: {
must_not: {
exists: {
field: 'issued',
},
},
},
{
range: { 'issued.date': { lte: getTodayWithTime() } },
},
],
},
},
{
range: { 'issued.date': { lte: getTodayWithTime() } },
},
],
},
},
}),
},
};
}
constantScore.id = 'constantScore';

export default {
// filter values that are always added to the ES requests
permanentFilters: [
{ term: { hasWorkflowState: 'published' } },
constantScore,
],
};
16 changes: 16 additions & 0 deletions src/config/global-search-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,20 @@ globalSearchConfig.facets = globalSearchConfig.facets.filter(
(facet) => facet['field'] !== 'subject.keyword',
);

// customize permanent filters
const index = globalSearchConfig.permanentFilters.findIndex(
(f) => f.id === 'constantScore',
);
const baseConstantScore = globalSearchConfig.permanentFilters[index];

globalSearchConfig.permanentFilters[index] = () => {
const base = baseConstantScore();
base.constant_score.filter.bool.must_not = {
exists: {
field: 'exclude_from_globalsearch',
},
};
return base;
};

export default globalSearchConfig;

0 comments on commit 4a1095b

Please sign in to comment.