Skip to content

Commit

Permalink
DT-781: Use logical AND to combine filters in the DUOS UI (#2715)
Browse files Browse the repository at this point in the history
  • Loading branch information
pshapiro4broad authored Nov 7, 2024
1 parent 19c11fa commit e5e60a1
Showing 1 changed file with 32 additions and 38 deletions.
70 changes: 32 additions & 38 deletions src/components/data_search/DatasetSearchTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,60 +104,54 @@ export const DatasetSearchTable = (props) => {
queryChunks.push(...searchModifier);
}

var filterQuery = {};
let filterQuery = {};
if (numSelectedFilters(filters) > 0) {
const shouldTerms = [];
const filterTerms = [];

filters.accessManagement.forEach(term => {
shouldTerms.push({
'term': {
'accessManagement': term
}
});
filterTerms.push({
'bool': {
'should':
filters.accessManagement.map(term => ({
'term': {
'accessManagement': term
}
}))
}
});

filters.dataUse.forEach(term => {
shouldTerms.push({
'match': {
'dataUse.primary.code': term
}
});
filterTerms.push({
'bool': {
'should':
filters.dataUse.map(term => ({
'match': {
'dataUse.primary.code': term
}
}))
}
});

if (shouldTerms.length > 0) {
if (filterTerms.length > 0) {
filterQuery = [
{
'bool': {
'should': shouldTerms
'must': filterTerms
}
}
];
}
}

// do not add filter subquery if no filters are applied
if (numSelectedFilters(filters) > 0) {
return {
'from': 0,
'size': 10000,
'query': {
'bool': {
'must': queryChunks,
'filter': filterQuery
}
}
};
} else {
return {
'from': 0,
'size': 10000,
'query': {
'bool': {
'must': queryChunks
}
return {
'from': 0,
'size': 10000,
'query': {
'bool': {
'must': queryChunks,
// Only add filter subquery when filters are applied.
...(Object.keys(filterQuery).length > 0 && { 'filter': filterQuery })
}
};
}
}
};
};

const filterHandler = (event, data, category, filter) => {
Expand Down

0 comments on commit e5e60a1

Please sign in to comment.