[ADF-3677] Add highlight configuration to SearchQueryBuilder (#4358)

* [ADF-3677] Add highlight configuration to SearchQueryBuilder

* highlight property in search

* Update files.component.ts

* remove comma

* highlight missspell

* fix schhema json highilight

* fix test

* fix lint

* fix lint

* fix lint

* fix search sorting tests

* fix search sorting

* fix lint

* remove useless test

* check for null nodes

* remove duplicated test

* lint

* fix sorting tests

* remove test not search component related
This commit is contained in:
davidcanonieto
2019-03-17 17:23:07 +00:00
committed by Eugenio Romano
parent d6f391c40e
commit 8dc9eba4c7
19 changed files with 401 additions and 444 deletions
@@ -20,11 +20,12 @@ import { FacetQuery } from './facet-query.interface';
import { FacetField } from './facet-field.interface';
import { SearchCategory } from './search-category.interface';
import { SearchSortingDefinition } from './search-sorting-definition.interface';
import { RequestHighlight } from '@alfresco/js-api';
export interface SearchConfiguration {
include?: string[];
fields?: string[];
categories: SearchCategory[];
categories?: SearchCategory[];
filterQueries?: FilterQuery[];
filterWithContains?: boolean;
resetButton?: boolean;
@@ -47,4 +48,5 @@ export interface SearchConfiguration {
options: SearchSortingDefinition[];
defaults: SearchSortingDefinition[];
};
highlight?: RequestHighlight;
}
@@ -190,10 +190,12 @@ describe('SearchQueryBuilder', () => {
it('should fetch facet from the config by label', () => {
const config: SearchConfiguration = {
categories: [],
facetFields: { 'fields': [
{ 'field': 'content.mimetype', 'mincount': 1, 'label': 'Type' },
{ 'field': 'content.size', 'mincount': 1, 'label': 'Size' }
]}
facetFields: {
'fields': [
{ 'field': 'content.mimetype', 'mincount': 1, 'label': 'Type' },
{ 'field': 'content.size', 'mincount': 1, 'label': 'Size' }
]
}
};
const builder = new SearchQueryBuilderService(buildConfig(config), null);
const field = builder.getFacetField('Size');
@@ -205,10 +207,12 @@ describe('SearchQueryBuilder', () => {
it('should not fetch facet from the config by label', () => {
const config: SearchConfiguration = {
categories: [],
facetFields: { 'fields': [
{ 'field': 'content.mimetype', 'mincount': 1, 'label': 'Type' },
{ 'field': 'content.size', 'mincount': 1, 'label': 'Size' }
]}
facetFields: {
'fields': [
{ 'field': 'content.mimetype', 'mincount': 1, 'label': 'Type' },
{ 'field': 'content.size', 'mincount': 1, 'label': 'Size' }
]
}
};
const builder = new SearchQueryBuilderService(buildConfig(config), null);
const field = builder.getFacetField('Missing');
@@ -373,10 +377,12 @@ describe('SearchQueryBuilder', () => {
categories: [
<any> { id: 'cat1', enabled: true }
],
facetFields: { fields: [
{ field: 'field1', label: 'field1', mincount: 1, limit: null, offset: 0, prefix: null },
{ field: 'field2', label: 'field2', mincount: 1, limit: null, offset: 0, prefix: null }
]}
facetFields: {
fields: [
{ field: 'field1', label: 'field1', mincount: 1, limit: null, offset: 0, prefix: null },
{ field: 'field2', label: 'field2', mincount: 1, limit: null, offset: 0, prefix: null }
]
}
};
const builder = new SearchQueryBuilderService(buildConfig(config), null);
builder.queryFragments['cat1'] = 'cm:name:test';
@@ -588,4 +594,23 @@ describe('SearchQueryBuilder', () => {
expect(compiledQuery.query.query).toBe(expectedResult);
});
it('should use highlight in the queries', () => {
const config: SearchConfiguration = {
highlight: {
'prefix': 'my-prefix',
'postfix': 'my-postfix',
'mergeContiguous': true
}
};
const builder = new SearchQueryBuilderService(buildConfig(config), null);
builder.userQuery = 'my query';
builder.queryFragments['cat1'] = 'cm:name:test';
const compiled = builder.buildQuery();
expect(compiled.highlight.prefix).toBe('my-prefix');
expect(compiled.highlight.postfix).toBe('my-postfix');
expect(compiled.highlight.mergeContiguous).toBe(true);
});
});
@@ -23,7 +23,8 @@ import {
RequestFacetFields,
RequestFacetField,
RequestSortDefinitionInner,
ResultSetPaging
ResultSetPaging,
RequestHighlight
} from '@alfresco/js-api';
import { SearchCategory } from './search-category.interface';
import { FilterQuery } from './filter-query.interface';
@@ -227,7 +228,8 @@ export class SearchQueryBuilderService {
facetQueries: this.facetQueries,
facetIntervals: this.facetIntervals,
facetFields: this.facetFields,
sort: this.sort
sort: this.sort,
highlight: this.highlight
};
result['facetFormat'] = 'V2';
@@ -296,6 +298,10 @@ export class SearchQueryBuilderService {
return false;
}
get hasFacetHighlight(): boolean {
return this.config && this.config.highlight ? true : false;
}
protected get sort(): RequestSortDefinitionInner[] {
return this.sorting.map((def) => {
return new RequestSortDefinitionInner({
@@ -339,6 +345,10 @@ export class SearchQueryBuilderService {
return null;
}
protected get highlight(): RequestHighlight {
return this.hasFacetHighlight ? this.config.highlight : null;
}
protected getFinalQuery(): string {
let query = '';
+62 -1
View File
@@ -1117,7 +1117,6 @@
],
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
@@ -1148,6 +1147,68 @@
}
}
},
"highlight": {
"description": " Request that highlight fragments to be added to result set rows The properties reflect SOLR highlighting parameters.",
"properties": {
"prefix": {
"description": "The string used to mark the start of a highlight in a fragment",
"type": "string"
},
"postfix": {
"description": "The string used to mark the end of a highlight in a fragment",
"type": "string"
},
"snippetCount": {
"description": "The maximum number of distinct highlight snippets to return for each highlight field",
"type": "number"
},
"fragmentSize": {
"description": "The character length of each snippet",
"type": "number"
},
"maxAnalyzedChars": {
"description": "The number of characters to be considered for highlighting. Matches after this count will not be shown",
"type": "number"
},
"mergeContiguous": {
"description": "If fragments over lap they can be merged into one larger fragment",
"type": "boolean"
},
"usePhraseHighlighter": {
"description": "Should phrases be identified",
"type": "boolean"
},
"fields": {
"type": "array",
"minItems": 1,
"items": {
"description": "The fields to highlight and field specific configuration properties for each field",
"type": "object",
"properties": {
"field": {
"description": "The name of the field to highlight",
"type": "string"
},
"snippetCount": {
"type": "number"
},
"fragmentSize": {
"type": "number"
},
"mergeContiguous": {
"type": "boolean"
},
"prefix": {
"type": "string"
},
"postfix": {
"type": "string"
}
}
}
}
}
},
"sorting": {
"description": "Sorting options and defaults",
"required": [
@@ -96,10 +96,13 @@ describe('EditProcessFilterCloudComponent', () => {
fixture.detectChanges();
const title = fixture.debugElement.nativeElement.querySelector('#adf-edit-process-filter-title-id');
const subTitle = fixture.debugElement.nativeElement.querySelector('#adf-edit-process-filter-sub-title-id');
expect(title).toBeDefined();
expect(subTitle).toBeDefined();
expect(title.innerText).toEqual('FakeRunningProcess');
expect(subTitle.innerText.trim()).toEqual('ADF_CLOUD_EDIT_PROCESS_FILTER.TITLE');
fixture.whenStable().then(() => {
expect(title).toBeDefined();
expect(subTitle).toBeDefined();
expect(title.innerText).toEqual('FakeRunningProcess');
expect(subTitle.innerText.trim()).toEqual('ADF_CLOUD_EDIT_PROCESS_FILTER.TITLE');
});
});
describe('EditProcessFilter form', () => {