From 55cd57b49ddb1c3236053f0bab5ad25325249cb9 Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Thu, 13 Jul 2017 14:12:25 +0100 Subject: [PATCH] Search add wildcard * to match all the (#2079) --- ng2-components/ng2-alfresco-search/README.md | 2 +- .../alfresco-search-autocomplete.component.ts | 1 + .../components/alfresco-search.component.spec.ts | 13 ++++++++----- .../src/components/alfresco-search.component.ts | 1 + 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ng2-components/ng2-alfresco-search/README.md b/ng2-components/ng2-alfresco-search/README.md index 5068e00f85..ad4f3d0944 100644 --- a/ng2-components/ng2-alfresco-search/README.md +++ b/ng2-components/ng2-alfresco-search/README.md @@ -91,7 +91,7 @@ results page will be shown. | --- | --- | --- | --- | --- | | searchTerm | string | | Search term to use when executing the search. Updating this value will run a new search and update the results | | rootNodeId | string | "-root-" | NodeRef or node name where the search should start. | -| resultType | string | | Node type to filter search results by, e.g. 'cm:content'. | +| resultType | string | | Node type to filter search results by, e.g. 'cm:content', 'cm:folder' if you want only the files. | | maxResults | number | 20 | Maximum number of results to show in the search. | | resultSort | string | | Criteria to sort search results by, must be one of "name" , "modifiedAt" or "createdAt" | | navigationMode | string | "dblclick" | Event used to initiate a navigation action to a specific result, one of "click" or "dblclick" | diff --git a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.ts b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.ts index ebb17ef062..f22daf819c 100644 --- a/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.ts +++ b/ng2-components/ng2-alfresco-search/src/components/alfresco-search-autocomplete.component.ts @@ -101,6 +101,7 @@ export class AlfrescoSearchAutocompleteComponent implements OnInit, OnChanges { orderBy: this.resultSort }; if (searchTerm !== null && searchTerm !== '') { + searchTerm = searchTerm + '*'; this.searchService .getNodeQueryResults(searchTerm, searchOpts) .subscribe( diff --git a/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.spec.ts b/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.spec.ts index 41638ace52..8003f3fa75 100644 --- a/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.spec.ts +++ b/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.spec.ts @@ -105,8 +105,8 @@ describe('AlfrescoSearchComponent', () => { declarations: [AlfrescoSearchComponent], // declare the test component providers: [ AlfrescoSearchService, - { provide: AlfrescoTranslationService, useClass: TranslationMock }, - { provide: NotificationService, useClass: NotificationService } + {provide: AlfrescoTranslationService, useClass: TranslationMock}, + {provide: NotificationService, useClass: NotificationService} ] }).compileComponents().then(() => { fixture = TestBed.createComponent(AlfrescoSearchComponent); @@ -155,8 +155,10 @@ describe('AlfrescoSearchComponent', () => { describe('Search results', () => { - it('should call search service with the correct parameters', (done) => { - let searchTerm = 'searchTerm63688', options = { + it('should add wildcard in the search parameters', (done) => { + let searchTerm = 'searchTerm6368'; + let searchTermOut = 'searchTerm6368*'; + let options = { include: ['path', 'allowableOperations'], skipCount: 0, rootNodeId: '-my-', @@ -164,6 +166,7 @@ describe('AlfrescoSearchComponent', () => { maxItems: 20, orderBy: null }; + component.searchTerm = searchTerm; component.rootNodeId = '-my-'; component.resultType = 'my:type'; @@ -174,7 +177,7 @@ describe('AlfrescoSearchComponent', () => { component.resultsLoad.subscribe(() => { fixture.detectChanges(); - expect(searchService.getQueryNodesPromise).toHaveBeenCalledWith(searchTerm, options); + expect(searchService.getQueryNodesPromise).toHaveBeenCalledWith(searchTermOut, options); done(); }); }); diff --git a/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.ts b/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.ts index e6fcb63557..e0420928d1 100644 --- a/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.ts +++ b/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.ts @@ -108,6 +108,7 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit { */ private displaySearchResults(searchTerm) { if (searchTerm && this.searchService) { + searchTerm = searchTerm + '*'; let searchOpts: SearchOptions = { include: ['path', 'allowableOperations'], skipCount: this.skipCount,