Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ describe('SearchConfigurationService', () => {
const prefixFilter = {
'f.author': ['another value'],
'f.date.min': ['2013'],
'f.date.max': ['2018']
'f.date.max': ['2018'],
'f.subject': ['some subject,contains']
};
const defaults = new PaginatedSearchOptions({
pagination: Object.assign(new PaginationComponentOptions(), { id: 'page-id', currentPage: 1, pageSize: 20 }),
Expand All @@ -31,8 +32,10 @@ describe('SearchConfigurationService', () => {
});

const backendFilters = [
new SearchFilter('f.author', ['another value']),
new SearchFilter('f.date', ['[2013 TO 2018]'], 'equals')
new SearchFilter('f.author', ['another value'], 'equals'),
new SearchFilter('f.date', ['[2013 TO 2018]'], 'equals'),
// value already carries an operator suffix -> operator must stay unset (not overridden to equals)
new SearchFilter('f.subject', ['some subject,contains'])
];
Comment thread
milanmajchrak marked this conversation as resolved.

const routeService = jasmine.createSpyObj('RouteService', {
Expand Down
10 changes: 9 additions & 1 deletion src/app/core/shared/search/search-configuration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,15 @@ export class SearchConfigurationService implements OnDestroy {
filters.push(new SearchFilter(realKey, ['[' + min + ' TO ' + max + ']'], 'equals'));
}
} else {
filters.push(new SearchFilter(key, filterParams[key]));
// Default to the "equals" operator only when a filter value carries none (e.g. a legacy
// or crawled URL like "f.subject=foo" instead of "f.subject=foo,equals"), which the
// backend would otherwise reject with HTTP 422. Values that already embed an operator
// (contain a comma, e.g. "foo,contains") keep it and leave SearchFilter.operator unset,
// matching SearchOptions.toRestUrl and consumers that read filter.operator directly
// (e.g. CSV export). dspace-customers#781.
const values = filterParams[key];
const operator = values.every((value) => value.includes(',')) ? undefined : 'equals';
filters.push(new SearchFilter(key, values, operator));
}
});
return filters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('MyDSpaceConfigurationService', () => {
});

const backendFilters = [
new SearchFilter('f.namedresourcetype', ['another value']),
new SearchFilter('f.namedresourcetype', ['another value'], 'equals'),
new SearchFilter('f.dateSubmitted', ['[2013 TO 2018]'], 'equals')
];

Expand Down
Loading