[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:
Suzana Dirla
2019-02-25 21:49:36 +02:00
committed by Eugenio Romano
parent 777a15f92d
commit 71dca95749
7 changed files with 101 additions and 20 deletions

View File

@@ -136,7 +136,7 @@
"expanded": true, "expanded": true,
"intervals":[ "intervals":[
{ {
"label":"TheCreated", "label":"The Created",
"field":"cm:created", "field":"cm:created",
"sets":[ "sets":[
{ "label":"lastYear", "start":"2018", "end":"2019", "endInclusive":false }, { "label":"lastYear", "start":"2018", "end":"2019", "endInclusive":false },

View File

@@ -37,7 +37,7 @@ export class SearchFiltersPage {
'mat-expansion-panel[data-automation-id="expansion-panel-My facet queries"]')); 'mat-expansion-panel[data-automation-id="expansion-panel-My facet queries"]'));
facetQueriesTypeGroup = element(by.css('mat-expansion-panel[data-automation-id="expansion-panel-Type facet queries"]')); facetQueriesTypeGroup = element(by.css('mat-expansion-panel[data-automation-id="expansion-panel-Type facet queries"]'));
facetQueriesSizeGroup = element(by.css('mat-expansion-panel[data-automation-id="expansion-panel-Size facet queries"]')); facetQueriesSizeGroup = element(by.css('mat-expansion-panel[data-automation-id="expansion-panel-Size facet queries"]'));
facetIntervalsByCreated = element(by.css('mat-expansion-panel[data-automation-id="expansion-panel-TheCreated"]')); facetIntervalsByCreated = element(by.css('mat-expansion-panel[data-automation-id="expansion-panel-The Created"]'));
facetIntervalsByModified = element(by.css('mat-expansion-panel[data-automation-id="expansion-panel-TheModified"]')); facetIntervalsByModified = element(by.css('mat-expansion-panel[data-automation-id="expansion-panel-TheModified"]'));
checkSearchFiltersIsDisplayed() { checkSearchFiltersIsDisplayed() {

View File

@@ -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) => { return configFacetFields.map((field) => {
const responseField = (context.facets || []).find((response) => response.type === itemType && response.label === field.label) || {}; const responseField = (context.facets || []).find((response) => response.type === itemType && response.label === field.label) || {};
const responseBuckets = this.getResponseBuckets(responseField, field) const responseBuckets = this.getResponseBuckets(responseField, field)
@@ -315,9 +315,31 @@ export class SearchFilterComponent implements OnInit, OnDestroy {
} }
private getCorrespondingFilterQuery (configFacetItem: FacetField, bucketLabel: string): string { private getCorrespondingFilterQuery (configFacetItem: FacetField, bucketLabel: string): string {
if (!configFacetItem.field || !bucketLabel) { let filterQuery = null;
return 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);
}
} else {
filterQuery = `${configFacetItem.field}:"${bucketLabel}"`;
}
} }
return `${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}`;
} }
} }

View File

@@ -31,4 +31,5 @@ export interface FacetField {
currentPageSize?: number; currentPageSize?: number;
checked?: boolean; checked?: boolean;
type?: string; type?: string;
[propName: string]: any;
} }

View File

@@ -22,28 +22,28 @@ import { SearchCategory } from './search-category.interface';
import { SearchSortingDefinition } from './search-sorting-definition.interface'; import { SearchSortingDefinition } from './search-sorting-definition.interface';
export interface SearchConfiguration { export interface SearchConfiguration {
include?: Array<string>; include?: string[];
fields?: Array<string>; fields?: string[];
categories: Array<SearchCategory>; categories: SearchCategory[];
filterQueries?: Array<FilterQuery>; filterQueries?: FilterQuery[];
filterWithContains?: boolean; filterWithContains?: boolean;
facetQueries?: { facetQueries?: {
label?: string; label?: string;
pageSize?: number; pageSize?: number;
expanded?: boolean; expanded?: boolean;
mincount?: number; mincount?: number;
queries: Array<FacetQuery>; queries: FacetQuery[];
}; };
facetFields?: { facetFields?: {
expanded?: boolean; expanded?: boolean;
fields: Array<FacetField>; fields: FacetField[];
}; };
facetIntervals?: { facetIntervals?: {
expanded?: boolean; expanded?: boolean;
intervals: Array<any>; intervals: FacetField[];
}; };
sorting?: { sorting?: {
options: Array<SearchSortingDefinition>; options: SearchSortingDefinition[];
defaults: Array<SearchSortingDefinition>; defaults: SearchSortingDefinition[];
}; };
} }

View File

@@ -425,13 +425,59 @@ describe('SearchQueryBuilder', () => {
label: 'test_intervals1', label: 'test_intervals1',
field: 'f1', field: 'f1',
sets: [ sets: [
{ label: 'interval1', start: 's1', end: 'e1' }, { label: 'interval1', start: 's1', end: 'e1', startInclusive: true, endInclusive: true },
{ label: 'interval2', start: 's2', end: 'e2' } { label: 'interval2', start: 's2', end: 'e2', startInclusive: false, endInclusive: true }
] ]
}, },
{ {
label: 'test_intervals2', label: 'test_intervals2',
field: 'f2', 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: [ sets: [
{ label: 'interval3', start: 's3', end: 'e3' }, { label: 'interval3', start: 's3', end: 'e3' },
{ label: 'interval4', start: 's4', end: 'e4' } { label: 'interval4', start: 's4', end: 'e4' }
@@ -444,7 +490,13 @@ describe('SearchQueryBuilder', () => {
builder.queryFragments['cat1'] = 'cm:name:test'; builder.queryFragments['cat1'] = 'cm:name:test';
const compiled = builder.buildQuery(); 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', () => { it('should build query with sorting', () => {

View File

@@ -323,9 +323,15 @@ export class SearchQueryBuilderService {
return { return {
intervals: configIntervals.intervals.map((interval) => <any> { intervals: configIntervals.intervals.map((interval) => <any> {
label: interval.label, label: this.getSupportedLabel(interval.label),
field: interval.field, 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
})
}) })
}; };
} }