mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-4083] search facetIntervals - empty spaced labels support (#4327)
* [ADF-4083] fix space-label issue for intervals * [ADF-4083] remove mention to [SEARCH-1487] issue - for future reference, also check https://issues.alfresco.com/jira/browse/ADF-4144 * [ADF-4083] add missing types * [ADF-4083] refactor method * [ADF-4083] fix test * [ADF-4083] small refactoring * [ADF-4083] better param naming * [ADF-4083] changes after rebase - keep better param naming * [ADF-4083] fix space-label issue for the sets of intervals * [ADF-4083] update test
This commit is contained in:
committed by
Eugenio Romano
parent
777a15f92d
commit
71dca95749
@@ -189,7 +189,7 @@ export class SearchFilterComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
private parseFacetItems(context: ResultSetContext, configFacetFields, itemType): FacetField[] {
|
||||
private parseFacetItems(context: ResultSetContext, configFacetFields: FacetField[], itemType: string): FacetField[] {
|
||||
return configFacetFields.map((field) => {
|
||||
const responseField = (context.facets || []).find((response) => response.type === itemType && response.label === field.label) || {};
|
||||
const responseBuckets = this.getResponseBuckets(responseField, field)
|
||||
@@ -315,9 +315,31 @@ export class SearchFilterComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private getCorrespondingFilterQuery (configFacetItem: FacetField, bucketLabel: string): string {
|
||||
if (!configFacetItem.field || !bucketLabel) {
|
||||
return null;
|
||||
let filterQuery = null;
|
||||
|
||||
if (configFacetItem.field && bucketLabel) {
|
||||
|
||||
if (configFacetItem.sets) {
|
||||
const configSet = configFacetItem.sets.find((set) => bucketLabel === set.label);
|
||||
|
||||
if (configSet) {
|
||||
filterQuery = this.buildIntervalQuery(configFacetItem.field, configSet);
|
||||
}
|
||||
return `${configFacetItem.field}:"${bucketLabel}"`;
|
||||
|
||||
} else {
|
||||
filterQuery = `${configFacetItem.field}:"${bucketLabel}"`;
|
||||
}
|
||||
}
|
||||
|
||||
return filterQuery;
|
||||
}
|
||||
|
||||
private buildIntervalQuery(fieldName: string, interval: any): string {
|
||||
const start = interval.start;
|
||||
const end = interval.end;
|
||||
const startLimit = (interval.startInclusive === undefined || interval.startInclusive === true) ? '[' : '<';
|
||||
const endLimit = (interval.endInclusive === undefined || interval.endInclusive === true) ? ']' : '>';
|
||||
|
||||
return `${fieldName}:${startLimit}"${start}" TO "${end}"${endLimit}`;
|
||||
}
|
||||
}
|
||||
|
@@ -31,4 +31,5 @@ export interface FacetField {
|
||||
currentPageSize?: number;
|
||||
checked?: boolean;
|
||||
type?: string;
|
||||
[propName: string]: any;
|
||||
}
|
||||
|
@@ -22,28 +22,28 @@ import { SearchCategory } from './search-category.interface';
|
||||
import { SearchSortingDefinition } from './search-sorting-definition.interface';
|
||||
|
||||
export interface SearchConfiguration {
|
||||
include?: Array<string>;
|
||||
fields?: Array<string>;
|
||||
categories: Array<SearchCategory>;
|
||||
filterQueries?: Array<FilterQuery>;
|
||||
include?: string[];
|
||||
fields?: string[];
|
||||
categories: SearchCategory[];
|
||||
filterQueries?: FilterQuery[];
|
||||
filterWithContains?: boolean;
|
||||
facetQueries?: {
|
||||
label?: string;
|
||||
pageSize?: number;
|
||||
expanded?: boolean;
|
||||
mincount?: number;
|
||||
queries: Array<FacetQuery>;
|
||||
queries: FacetQuery[];
|
||||
};
|
||||
facetFields?: {
|
||||
expanded?: boolean;
|
||||
fields: Array<FacetField>;
|
||||
fields: FacetField[];
|
||||
};
|
||||
facetIntervals?: {
|
||||
expanded?: boolean;
|
||||
intervals: Array<any>;
|
||||
intervals: FacetField[];
|
||||
};
|
||||
sorting?: {
|
||||
options: Array<SearchSortingDefinition>;
|
||||
defaults: Array<SearchSortingDefinition>;
|
||||
options: SearchSortingDefinition[];
|
||||
defaults: SearchSortingDefinition[];
|
||||
};
|
||||
}
|
||||
|
@@ -425,13 +425,59 @@ describe('SearchQueryBuilder', () => {
|
||||
label: 'test_intervals1',
|
||||
field: 'f1',
|
||||
sets: [
|
||||
{ label: 'interval1', start: 's1', end: 'e1' },
|
||||
{ label: 'interval2', start: 's2', end: 'e2' }
|
||||
{ label: 'interval1', start: 's1', end: 'e1', startInclusive: true, endInclusive: true },
|
||||
{ label: 'interval2', start: 's2', end: 'e2', startInclusive: false, endInclusive: true }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'test_intervals2',
|
||||
field: 'f2',
|
||||
sets: [
|
||||
{ label: 'interval3', start: 's3', end: 'e3', startInclusive: true, endInclusive: false },
|
||||
{ label: 'interval4', start: 's4', end: 'e4', startInclusive: false, endInclusive: false }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
const builder = new SearchQueryBuilderService(buildConfig(config), null);
|
||||
builder.queryFragments['cat1'] = 'cm:name:test';
|
||||
|
||||
const compiled = builder.buildQuery();
|
||||
expect(compiled.facetIntervals).toEqual(jasmine.objectContaining(config.facetIntervals));
|
||||
});
|
||||
|
||||
it('should build query with custom facet intervals automatically getting their request compatible labels', () => {
|
||||
const spacesLabel = {
|
||||
configValue: 'label with spaces',
|
||||
requestCompatibleValue: '"label with spaces"'
|
||||
};
|
||||
const noSpacesLabel = {
|
||||
configValue: 'label',
|
||||
requestCompatibleValue: 'label'
|
||||
};
|
||||
const spacesLabelForSet = {
|
||||
configValue: 'label for set',
|
||||
requestCompatibleValue: '"label for set"'
|
||||
};
|
||||
|
||||
const config: SearchConfiguration = {
|
||||
categories: [
|
||||
<any> { id: 'cat1', enabled: true }
|
||||
],
|
||||
facetIntervals: {
|
||||
intervals: [
|
||||
{
|
||||
label: spacesLabel.configValue,
|
||||
field: 'f1',
|
||||
sets: [
|
||||
{ label: spacesLabelForSet.configValue, start: 's1', end: 'e1' },
|
||||
{ label: 'interval2', start: 's2', end: 'e2' }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: noSpacesLabel.configValue,
|
||||
field: 'f2',
|
||||
sets: [
|
||||
{ label: 'interval3', start: 's3', end: 'e3' },
|
||||
{ label: 'interval4', start: 's4', end: 'e4' }
|
||||
@@ -444,7 +490,13 @@ describe('SearchQueryBuilder', () => {
|
||||
builder.queryFragments['cat1'] = 'cm:name:test';
|
||||
|
||||
const compiled = builder.buildQuery();
|
||||
expect(compiled.facetIntervals).toEqual(jasmine.objectContaining(config.facetIntervals));
|
||||
expect(compiled.facetIntervals.intervals[0].label).toEqual(spacesLabel.requestCompatibleValue);
|
||||
expect(compiled.facetIntervals.intervals[0].label).not.toEqual(spacesLabel.configValue);
|
||||
expect(compiled.facetIntervals.intervals[1].label).toEqual(noSpacesLabel.requestCompatibleValue);
|
||||
expect(compiled.facetIntervals.intervals[1].label).toEqual(noSpacesLabel.configValue);
|
||||
|
||||
expect(compiled.facetIntervals.intervals[0].sets[0].label).toEqual(spacesLabelForSet.requestCompatibleValue);
|
||||
|
||||
});
|
||||
|
||||
it('should build query with sorting', () => {
|
||||
|
@@ -323,9 +323,15 @@ export class SearchQueryBuilderService {
|
||||
|
||||
return {
|
||||
intervals: configIntervals.intervals.map((interval) => <any> {
|
||||
label: interval.label,
|
||||
label: this.getSupportedLabel(interval.label),
|
||||
field: interval.field,
|
||||
sets: interval.sets
|
||||
sets: interval.sets.map((set) => <any> {
|
||||
label: this.getSupportedLabel(set.label),
|
||||
start: set.start,
|
||||
end: set.end,
|
||||
startInclusive: set.startInclusive,
|
||||
endInclusive: set.endInclusive
|
||||
})
|
||||
})
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user