mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
committed by
Eugenio Romano
parent
d6f391c40e
commit
8dc9eba4c7
@@ -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 = '';
|
||||
|
||||
|
Reference in New Issue
Block a user