Skip to content

Commit 3fef503

Browse files
milanmajchrakclaude
andcommitted
TUL/fix: address review - only default operator when value has none
Previously getCurrentFilters set operator='equals' on every non-range filter, even when the URL value already embedded an operator (e.g. "foo,contains"), which could confuse consumers reading filter.operator directly (e.g. CSV export). Now default to 'equals' only when no value carries an operator suffix (contains a comma), matching SearchOptions.toRestUrl. Added a spec fixture for an operator-embedded value asserting the operator stays unset. Per Copilot review on #1368. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent c3a1086 commit 3fef503

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/app/core/shared/search/search-configuration.service.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ describe('SearchConfigurationService', () => {
2020
const prefixFilter = {
2121
'f.author': ['another value'],
2222
'f.date.min': ['2013'],
23-
'f.date.max': ['2018']
23+
'f.date.max': ['2018'],
24+
'f.subject': ['some subject,contains']
2425
};
2526
const defaults = new PaginatedSearchOptions({
2627
pagination: Object.assign(new PaginationComponentOptions(), { id: 'page-id', currentPage: 1, pageSize: 20 }),
@@ -32,7 +33,9 @@ describe('SearchConfigurationService', () => {
3233

3334
const backendFilters = [
3435
new SearchFilter('f.author', ['another value'], 'equals'),
35-
new SearchFilter('f.date', ['[2013 TO 2018]'], 'equals')
36+
new SearchFilter('f.date', ['[2013 TO 2018]'], 'equals'),
37+
// value already carries an operator suffix -> operator must stay unset (not overridden to equals)
38+
new SearchFilter('f.subject', ['some subject,contains'])
3639
];
3740

3841
const routeService = jasmine.createSpyObj('RouteService', {

src/app/core/shared/search/search-configuration.service.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,15 @@ export class SearchConfigurationService implements OnDestroy {
196196
filters.push(new SearchFilter(realKey, ['[' + min + ' TO ' + max + ']'], 'equals'));
197197
}
198198
} else {
199-
// Default to the "equals" operator when a filter value carries none (e.g. a legacy or
200-
// crawled URL like "f.subject=foo" instead of "f.subject=foo,equals"). Without this the
201-
// backend rejects the operator-less filter with HTTP 422. Values that already embed an
202-
// operator (contain a comma) keep it - see SearchOptions.toRestUrl. dspace-customers#781.
203-
filters.push(new SearchFilter(key, filterParams[key], 'equals'));
199+
// Default to the "equals" operator only when a filter value carries none (e.g. a legacy
200+
// or crawled URL like "f.subject=foo" instead of "f.subject=foo,equals"), which the
201+
// backend would otherwise reject with HTTP 422. Values that already embed an operator
202+
// (contain a comma, e.g. "foo,contains") keep it and leave SearchFilter.operator unset,
203+
// matching SearchOptions.toRestUrl and consumers that read filter.operator directly
204+
// (e.g. CSV export). dspace-customers#781.
205+
const values = filterParams[key];
206+
const operator = values.every((value) => value.includes(',')) ? undefined : 'equals';
207+
filters.push(new SearchFilter(key, values, operator));
204208
}
205209
});
206210
return filters;

0 commit comments

Comments
 (0)