diff --git a/demo-shell/resources/i18n/en.json b/demo-shell/resources/i18n/en.json
index f5b981349d..01d3f5be95 100644
--- a/demo-shell/resources/i18n/en.json
+++ b/demo-shell/resources/i18n/en.json
@@ -25,7 +25,12 @@
"SOCIAL": "Social",
"SETTINGS": "Settings",
"OVERLAY_VIEWER": "Overlay Viewer",
- "ABOUT": "About"
+ "ABOUT": "About",
+ "SEARCH": "Extended Search",
+ "EXTENDED_SEARCH_QUERY_BODY": "Extended Search with Query Body",
+ "WORD_TO_SEARCH":"Search Word",
+ "SEARCH_CREATED_BY" : "Created By",
+ "SEARCH_SERVICE_APPROACH": "Check this to disable the input property and use the service approach"
},
"DOCUMENT_LIST": {
"MULTISELECT_CHECKBOXES" :"Multiselect (with checkboxes)",
diff --git a/demo-shell/src/app/app.module.ts b/demo-shell/src/app/app.module.ts
index a320f3bc09..3649774921 100644
--- a/demo-shell/src/app/app.module.ts
+++ b/demo-shell/src/app/app.module.ts
@@ -16,6 +16,7 @@ import { AppLayoutComponent } from './components/app-layout/app-layout.component
import { HomeComponent } from './components/home/home.component';
import { SearchBarComponent } from './components/search/search-bar.component';
import { SearchResultComponent } from './components/search/search-result.component';
+import { SearchExtendedComponent } from './components/search/search-extended.component';
import { AboutComponent } from './components/about/about.component';
import { FormComponent } from './components/form/form.component';
import { FormListComponent } from './components/form/form-list.component';
@@ -68,6 +69,7 @@ import { SharedLinkViewComponent } from './components/shared-link-view/shared-li
HomeComponent,
SearchBarComponent,
SearchResultComponent,
+ SearchExtendedComponent,
AboutComponent,
ProcessServiceComponent,
ShowDiagramComponent,
diff --git a/demo-shell/src/app/app.routes.ts b/demo-shell/src/app/app.routes.ts
index 0052021654..5869b81417 100644
--- a/demo-shell/src/app/app.routes.ts
+++ b/demo-shell/src/app/app.routes.ts
@@ -29,6 +29,7 @@ import { FormViewerComponent } from './components/process-service/form-viewer.co
import { FormNodeViewerComponent } from './components/process-service/form-node-viewer.component';
import { AppsViewComponent } from './components/process-service/apps-view.component';
import { SearchResultComponent } from './components/search/search-result.component';
+import { SearchExtendedComponent } from './components/search/search-extended.component';
import { DataTableComponent } from './components/datatable/datatable.component';
import { WebscriptComponent } from './components/webscript/webscript.component';
@@ -95,6 +96,11 @@ export const appRoutes: Routes = [
component: SearchResultComponent,
canActivate: [AuthGuardEcm]
},
+ {
+ path: 'extendedSearch',
+ component: SearchExtendedComponent,
+ canActivate: [AuthGuardEcm]
+ },
{
path: 'activiti',
component: AppsViewComponent,
diff --git a/demo-shell/src/app/components/app-layout/app-layout.component.ts b/demo-shell/src/app/components/app-layout/app-layout.component.ts
index fc3c044d31..1fef973b98 100644
--- a/demo-shell/src/app/components/app-layout/app-layout.component.ts
+++ b/demo-shell/src/app/components/app-layout/app-layout.component.ts
@@ -41,6 +41,7 @@ export class AppLayoutComponent {
{ href: '/tag', icon: 'local_offer', title: 'APP_LAYOUT.TAG' },
{ href: '/social', icon: 'thumb_up', title: 'APP_LAYOUT.SOCIAL' },
{ href: '/settings', icon: 'settings', title: 'APP_LAYOUT.SETTINGS' },
+ { href: '/extendedSearch', icon: 'search', title: 'APP_LAYOUT.SEARCH' },
{ href: '/overlay-viewer', icon: 'pageview', title: 'APP_LAYOUT.OVERLAY_VIEWER' },
{ href: '/about', icon: 'info_outline', title: 'APP_LAYOUT.ABOUT' }
];
diff --git a/demo-shell/src/app/components/search/search-config-test.service.ts b/demo-shell/src/app/components/search/search-config-test.service.ts
new file mode 100644
index 0000000000..42683447c3
--- /dev/null
+++ b/demo-shell/src/app/components/search/search-config-test.service.ts
@@ -0,0 +1,44 @@
+/*!
+ * @license
+ * Copyright 2016 Alfresco Software, Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { QueryBody } from 'alfresco-js-api';
+import { SearchConfigurationInterface } from '@alfresco/adf-core';
+
+export class TestSearchConfigurationService implements SearchConfigurationInterface {
+
+ constructor() {
+ }
+
+ public generateQueryBody(searchTerm: string, maxResults: string, skipCount: string): QueryBody {
+ const defaultQueryBody: QueryBody = {
+ query: {
+ query: searchTerm ? `${searchTerm}* OR name:${searchTerm}*` : searchTerm
+ },
+ include: ['path', 'allowableOperations'],
+ paging: {
+ maxItems: maxResults,
+ skipCount: skipCount
+ },
+ filterQueries: [
+ /*tslint:disable-next-line */
+ { query: "TYPE:'cm:folder'" },
+ { query: 'NOT cm:creator:System' }]
+ };
+
+ return defaultQueryBody;
+ }
+}
diff --git a/demo-shell/src/app/components/search/search-extended.component.html b/demo-shell/src/app/components/search/search-extended.component.html
new file mode 100644
index 0000000000..5fe9ee9ed7
--- /dev/null
+++ b/demo-shell/src/app/components/search/search-extended.component.html
@@ -0,0 +1,39 @@
+
+
{{'APP_LAYOUT.EXTENDED_SEARCH_QUERY_BODY' | translate}}
+
+ {{'APP_LAYOUT.SEARCH_SERVICE_APPROACH' | translate}}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ item?.entry.name }}
+ {{ item?.entry.createdAt }}
+
+
+
+
+ {{'APP_LAYOUT.SEARCH_CREATED_BY' | translate}}: {{item?.entry.createdByUser?.displayName}}
+
+
+
+
+ {{ 'SEARCH.RESULTS.NONE' | translate:{searchTerm: searchTerm} }}
+
+
+
+
+
diff --git a/demo-shell/src/app/components/search/search-extended.component.scss b/demo-shell/src/app/components/search/search-extended.component.scss
new file mode 100644
index 0000000000..386a94a880
--- /dev/null
+++ b/demo-shell/src/app/components/search/search-extended.component.scss
@@ -0,0 +1,62 @@
+div.search-results-container {
+ padding: 0 20px 20px 20px;
+}
+
+.adf-search-title {
+ font-size: 22px;
+ padding: 15px 0 15px 0;
+}
+
+@media screen and (max-width: 600px) {
+ :host .col-display-name {
+ min-width: 100px;
+ }
+ :host .col-modified-at, :host .col-modified-by {
+ display: none;
+ }
+ :host div.search-results-container table {
+ width: 100%;
+ }
+}
+
+.adf-search-results-content{
+ display: flex;
+}
+
+.search-extended-input-containers {
+ display: flex;
+ flex-direction: row-reverse;
+ justify-content: space-evenly;
+}
+
+.search-extended-input-textarea {
+ width: 300px;
+}
+
+.search-extended-label-error {
+ display: flex;
+ flex-direction: column;
+}
+
+.example-card {
+ width: 200px;
+ flex: 0 20%;
+ margin: 15px;
+ }
+
+ .example-card-search-container {
+ display: flex;
+ flex-wrap: wrap;
+ }
+
+ .example-header-image {
+
+ background-size: cover;
+ margin-bottom: 15px;
+ }
+
+ .example-search-input {
+ width: 100px;
+ border: 1 solid;
+ border-color: black;
+ }
diff --git a/demo-shell/src/app/components/search/search-extended.component.ts b/demo-shell/src/app/components/search/search-extended.component.ts
new file mode 100644
index 0000000000..8f6842b746
--- /dev/null
+++ b/demo-shell/src/app/components/search/search-extended.component.ts
@@ -0,0 +1,84 @@
+/*!
+ * @license
+ * Copyright 2016 Alfresco Software, Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { Component, ViewChild, ViewEncapsulation } from '@angular/core';
+import { NodePaging, Pagination, QueryBody, MinimalNodeEntity } from 'alfresco-js-api';
+import { SearchComponent } from '@alfresco/adf-content-services';
+import { ThumbnailService } from '@alfresco/adf-core';
+import { SearchService, SearchConfigurationService } from '@alfresco/adf-core';
+import { TestSearchConfigurationService } from './search-config-test.service';
+
+@Component({
+ selector: 'app-search-extended-component',
+ templateUrl: './search-extended.component.html',
+ styleUrls: ['./search-extended.component.scss'],
+ encapsulation: ViewEncapsulation.None,
+ providers: [
+ { provide: SearchConfigurationService, useClass: TestSearchConfigurationService },
+ SearchService
+ ]
+})
+export class SearchExtendedComponent {
+
+ @ViewChild('search')
+ search: SearchComponent;
+
+ queryParamName = 'q';
+ searchedWord = '';
+ queryBodyString = '';
+ errorMessage = '';
+ resultNodePageList: NodePaging;
+ maxItems: number;
+ skipCount = 0;
+ pagination: Pagination;
+ queryBody: QueryBody;
+ useServiceApproach = false;
+
+ constructor(public thumbnailService: ThumbnailService) {
+
+ }
+
+ getMimeTypeIcon(node: MinimalNodeEntity): string {
+ let mimeType;
+
+ if (node.entry.content && node.entry.content.mimeType) {
+ mimeType = node.entry.content.mimeType;
+ }
+ if (node.entry.isFolder) {
+ mimeType = 'folder';
+ }
+
+ return this.thumbnailService.getMimeTypeIcon(mimeType);
+ }
+
+ generateQueryBody(searchTerm: string): QueryBody {
+ if (this.useServiceApproach) {
+ return null;
+ } else {
+ return {
+ query: {
+ query: searchTerm ? `${searchTerm}* OR name:${searchTerm}*` : searchTerm
+ },
+ include: ['path', 'allowableOperations'],
+ filterQueries: [
+ /*tslint:disable-next-line */
+ { query: "TYPE:'cm:folder' OR TYPE:'cm:content'" },
+ { query: 'NOT cm:creator:System' }]
+ };
+ }
+ }
+}
diff --git a/docs/search-control.component.md b/docs/search-control.component.md
index 4941dae885..13ae9a1ad8 100644
--- a/docs/search-control.component.md
+++ b/docs/search-control.component.md
@@ -25,7 +25,8 @@ Displays a input text which shows find-as-you-type suggestions.
| expandable | boolean | true | Whether to use an expanding search control, if false then a regular input is used. |
| liveSearchEnabled | boolean | true | Whether find-as-you-type suggestions should be offered for matching content items. Set to false to disable. |
| liveSearchMaxResults | number | 5 | Maximum number of results to show in the live search. |
-| customQueryBody | [QueryBody](https://github.com/Alfresco/alfresco-js-api/blob/1.6.0/src/alfresco-search-rest-api/docs/QueryBody.md) | | object which allow you to perform more elaborated query from the search api |
+| customQueryBody | [QueryBody](https://github.com/Alfresco/alfresco-js-api/blob/1.6.0/src/alfresco-search-rest-api/docs/QueryBody.md) | | object which allow you to perform more elaborated query from the search api. This input is deprecated, to use the extended query body function please refer to the suggested solution [here](./search.component.md#querybody)|
+
### Events
diff --git a/docs/search.component.md b/docs/search.component.md
index 9cb540c144..3f88adc1f5 100644
--- a/docs/search.component.md
+++ b/docs/search.component.md
@@ -19,7 +19,7 @@ Searches items for supplied search terms.
| maxResults | number | 20 | Maximum number of results to show in the search. |
| skipResults | number | 0 | Number of results to skip from the results pagination. |
| displayWith | function | | Function that maps an option's value to its display value in the trigger |
-| queryBody | [QueryBody](https://github.com/Alfresco/alfresco-js-api/blob/1.6.0/src/alfresco-search-rest-api/docs/QueryBody.md) | | object which allow you to perform more elaborated query from the search api |
+| queryBody| [QueryBody](https://github.com/Alfresco/alfresco-js-api/blob/1.6.0/src/alfresco-search-rest-api/docs/QueryBody.md) | | object which allow you to perform more elaborated query from the search api. This input is deprecated, to use the extended query body function please refer to the suggested solution [here](./search.component.md#querybody) |
### Events
@@ -113,3 +113,60 @@ Yuo can do this by exporting the adf-search panel instance into a local template
```
In this way it is possible to fetch the results from the word typed into the input text straight into the adf-search component via the custom template variable.
+
+## QueryBody
+This is an example on how you can provide your own class to generate your custom query body without giving it in input to the search component.
+
+1. Service Class
+ You need to create your own service class which will implement the SearchConfigurationInterface this will force you to create the method generateQueryBody that is the one which needs to return the QueryBody object.
+
+ ```ts
+ import { QueryBody } from 'alfresco-js-api';
+ import { SearchConfigurationInterface } from '@alfresco/adf-core';
+
+ export class TestSearchConfigurationService implements SearchConfigurationInterface {
+
+ constructor() {
+ }
+
+ public generateQueryBody(searchTerm: string, maxResults: string, skipCount: string): QueryBody {
+ const defaultQueryBody: QueryBody = {
+ query: {
+ query: searchTerm ? `${searchTerm}* OR name:${searchTerm}*` : searchTerm
+ },
+ include: ['path', 'allowableOperations'],
+ paging: {
+ maxItems: maxResults,
+ skipCount: skipCount
+ },
+ filterQueries: [
+ { query: "TYPE:'cm:folder'" },
+ { query: 'NOT cm:creator:System' }]
+ };
+
+ return defaultQueryBody;
+ }
+ }
+ ```
+
+2. Provide your service class to the module
+ Once you have created your service class to provide your custom query body you need to inform the component to use your class instead of the default one. This can be easily achieved via your component providers :
+
+ ```ts
+ import { SearchService, SearchConfigurationService } from '@alfresco/adf-core';
+ import { TestSearchConfigurationService } from './search-config-test.service';
+
+ @Component({
+ selector: 'app-search-extended-component',
+ templateUrl: './search-extended.component.html',
+ styleUrls: ['./search-extended.component.scss'],
+ encapsulation: ViewEncapsulation.None,
+ providers: [
+ { provide: SearchConfigurationService, useClass: TestSearchConfigurationService },
+ SearchService
+ ]
+ })
+ ```
+ You need to add as provider even the SearchService to avoid the override of the module instance. So this component will have his own instance of the SearchService that will use as configuration the class you have provided.
+
+
diff --git a/lib/content-services/content-node-selector/content-node-selector-panel.component.spec.ts b/lib/content-services/content-node-selector/content-node-selector-panel.component.spec.ts
index b0153bfcb3..29514fb9e7 100644
--- a/lib/content-services/content-node-selector/content-node-selector-panel.component.spec.ts
+++ b/lib/content-services/content-node-selector/content-node-selector-panel.component.spec.ts
@@ -301,7 +301,7 @@ describe('ContentNodeSelectorComponent', () => {
typeToSearchBox('kakarot');
setTimeout(() => {
- expect(searchSpy).toHaveBeenCalledWith(defaultSearchOptions('kakarot'));
+ expect(searchSpy).toHaveBeenCalledWith(defaultSearchOptions('kakarot'), '25', '0');
done();
}, 300);
});
@@ -325,7 +325,7 @@ describe('ContentNodeSelectorComponent', () => {
component.siteChanged( { entry: { guid: 'namek' } });
expect(searchSpy.calls.count()).toBe(2, 'Search count should be two after the site change');
- expect(searchSpy.calls.argsFor(1)).toEqual([defaultSearchOptions('vegeta', 'namek')]);
+ expect(searchSpy.calls.argsFor(1)).toEqual([defaultSearchOptions('vegeta', 'namek'), '25', '0'] );
done();
}, 300);
});
@@ -523,7 +523,7 @@ describe('ContentNodeSelectorComponent', () => {
component.getNextPageOfSearch({ skipCount });
- expect(searchSpy).toHaveBeenCalledWith(defaultSearchOptions('kakarot', undefined, skipCount));
+ expect(searchSpy).toHaveBeenCalledWith(defaultSearchOptions('kakarot', undefined, skipCount), '25', skipCount.toString());
});
it('should be shown when pagination\'s hasMoreItems is true', () => {
diff --git a/lib/content-services/content-node-selector/content-node-selector.service.ts b/lib/content-services/content-node-selector/content-node-selector.service.ts
index 216c6c9a59..2c5ad8e19b 100644
--- a/lib/content-services/content-node-selector/content-node-selector.service.ts
+++ b/lib/content-services/content-node-selector/content-node-selector.service.ts
@@ -59,6 +59,6 @@ export class ContentNodeSelectorService {
}
};
- return this.searchService.search(defaultSearchNode);
+ return this.searchService.search(defaultSearchNode, maxItems.toString(), skipCount.toString());
}
}
diff --git a/lib/content-services/search/components/search-control.component.html b/lib/content-services/search/components/search-control.component.html
index 7feeb3d0ae..3d33f1ac6c 100644
--- a/lib/content-services/search/components/search-control.component.html
+++ b/lib/content-services/search/components/search-control.component.html
@@ -27,8 +27,8 @@
+ [maxResults]="liveSearchMaxResults"
+ [queryBody]="customQueryBody">
{
- if (searchNode.query.query === 'FAKE_SEARCH_EXMPL') {
+ if (searchNode && searchNode.query.query === 'FAKE_SEARCH_EXMPL') {
return Observable.of(differentResult);
}
- if (searchNode.filterQueries.length === 1 &&
+ if (searchNode && searchNode.filterQueries.length === 1 &&
searchNode.filterQueries[0].query === "TYPE:'cm:folder'") {
return Observable.of(folderResult);
}
@@ -132,18 +132,18 @@ describe('SearchComponent', () => {
});
it('should perform a search based on the query node given', async(() => {
- spyOn(searchService, 'search')
- .and.callFake((searchObj) => fakeNodeResultSearch(searchObj));
+ spyOn(searchService, 'searchByQueryBody')
+ .and.callFake((searchObj) => fakeNodeResultSearch(searchObj));
let fakeSearchNode: QueryBody = {
query: {
- query: ''
+ query: 'TEST-FAKE-NODE'
},
filterQueries: [
{ 'query': "TYPE:'cm:folder'" }
]
};
- component.setSearchNodeTo(fakeSearchNode);
component.setSearchWordTo('searchTerm');
+ component.setSearchNodeTo(fakeSearchNode);
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
@@ -156,7 +156,7 @@ describe('SearchComponent', () => {
it('should perform a search with a defaultNode if no searchnode is given', async(() => {
spyOn(searchService, 'search')
- .and.callFake((searchObj) => fakeNodeResultSearch(searchObj));
+ .and.returnValue(Observable.of(result));
component.setSearchWordTo('searchTerm');
fixture.detectChanges();
fixture.whenStable().then(() => {
@@ -169,7 +169,7 @@ describe('SearchComponent', () => {
}));
it('should perform a search with the searchNode given', async(() => {
- spyOn(searchService, 'search')
+ spyOn(searchService, 'searchByQueryBody')
.and.callFake((searchObj) => fakeNodeResultSearch(searchObj));
let fakeSearchNode: QueryBody = {
query: {
@@ -179,6 +179,7 @@ describe('SearchComponent', () => {
{ 'query': "TYPE:'cm:folder'" }
]
};
+ component.setSearchWordTo('searchTerm');
component.setSearchNodeTo(fakeSearchNode);
fixture.detectChanges();
fixture.whenStable().then(() => {
diff --git a/lib/content-services/search/components/search.component.ts b/lib/content-services/search/components/search.component.ts
index 63d8ec2090..48fc102e23 100644
--- a/lib/content-services/search/components/search.component.ts
+++ b/lib/content-services/search/components/search.component.ts
@@ -18,8 +18,6 @@
import { SearchService } from '@alfresco/adf-core';
import {
AfterContentInit,
- ChangeDetectionStrategy,
- ChangeDetectorRef,
Component,
ContentChild,
ElementRef,
@@ -40,7 +38,6 @@ import { Subject } from 'rxjs/Subject';
styleUrls: ['./search.component.scss'],
encapsulation: ViewEncapsulation.None,
preserveWhitespaces: false,
- changeDetection: ChangeDetectionStrategy.OnPush,
exportAs: 'searchAutocomplete',
host: {
'class': 'adf-search'
@@ -63,12 +60,13 @@ export class SearchComponent implements AfterContentInit, OnChanges {
@Input()
skipResults: number = 0;
- @Input()
- searchTerm: string = '';
-
+ /** @deprecated in 2.1.0 */
@Input()
queryBody: QueryBody;
+ @Input()
+ searchTerm: string = '';
+
@Input('class')
set classList(classList: string) {
if (classList && classList.length) {
@@ -101,13 +99,13 @@ export class SearchComponent implements AfterContentInit, OnChanges {
_classList: { [key: string]: boolean } = {};
constructor(private searchService: SearchService,
- private changeDetectorRef: ChangeDetectorRef,
private _elementRef: ElementRef) {
this.keyPressedStream.asObservable()
.debounceTime(200)
.subscribe((searchedWord: string) => {
this.loadSearchResults(searchedWord);
});
+
}
ngAfterContentInit() {
@@ -115,14 +113,12 @@ export class SearchComponent implements AfterContentInit, OnChanges {
}
ngOnChanges(changes) {
- this.resetResults();
-
+ if (changes.queryBody &&
+ this.hasDifferentQueryBody(changes.queryBody.previousValue, changes.queryBody.currentValue)) {
+ this.loadSearchResults();
+ }
if (changes.searchTerm && changes.searchTerm.currentValue) {
this.loadSearchResults(changes.searchTerm.currentValue);
- } else if (changes.queryBody && changes.queryBody.currentValue) {
- this.loadSearchResults();
- } else {
- this.loadSearchResults(this.searchTerm);
}
}
@@ -135,23 +131,27 @@ export class SearchComponent implements AfterContentInit, OnChanges {
this.loadSearchResults(this.searchTerm);
}
+ private hasDifferentQueryBody(previousQueryBody: QueryBody, currentQueryBody: QueryBody) {
+ return JSON.stringify(previousQueryBody) !== JSON.stringify(currentQueryBody);
+ }
+
private cleanResults() {
if (this.results) {
this.results = {};
}
}
- private hasValidSearchQuery(searchOpts: QueryBody) {
- return searchOpts && searchOpts.query && searchOpts.query.query;
- }
-
private loadSearchResults(searchTerm?: string) {
- let searchOpts: QueryBody = this.getQueryBody(searchTerm);
-
- if (this.hasValidSearchQuery(searchOpts)) {
- this.searchService
- .search(searchOpts)
- .subscribe(
+ this.resetResults();
+ if (searchTerm) {
+ let search$;
+ if (this.queryBody) {
+ search$ = this.searchService.searchByQueryBody(this.queryBody);
+ } else {
+ search$ = this.searchService
+ .search(searchTerm, this.maxResults.toString(), this.skipResults.toString());
+ }
+ search$.subscribe(
results => {
this.results = results;
this.resultLoaded.emit(this.results);
@@ -169,41 +169,11 @@ export class SearchComponent implements AfterContentInit, OnChanges {
}
}
- private getQueryBody(searchTerm: string): QueryBody {
- if (this.queryBody) {
- if (!this.queryBody.query.query && searchTerm) {
- this.queryBody.query.query = searchTerm;
- }
- return this.queryBody;
- } else {
- return this.generateDefaultSearchNode(searchTerm);
- }
- }
-
- private generateDefaultSearchNode(searchTerm: string): QueryBody {
- let defaultQueryBody: QueryBody = {
- query: {
- query: searchTerm ? `${searchTerm}* OR name:${searchTerm}*` : searchTerm
- },
- include: ['path', 'allowableOperations'],
- paging: {
- maxItems: this.maxResults.toString(),
- skipCount: this.skipResults.toString()
- },
- filterQueries: [
- { query: "TYPE:'cm:folder' OR TYPE:'cm:content'" },
- { query: 'NOT cm:creator:System' }]
- };
-
- return defaultQueryBody;
- }
-
hidePanel() {
if (this.isOpen) {
this._classList['adf-search-show'] = false;
this._classList['adf-search-hide'] = true;
this.isOpen = false;
- this.changeDetectorRef.markForCheck();
}
}
@@ -211,6 +181,5 @@ export class SearchComponent implements AfterContentInit, OnChanges {
this.showPanel = !!this.results && !!this.results.list;
this._classList['adf-search-show'] = this.showPanel;
this._classList['adf-search-hide'] = !this.showPanel;
- this.changeDetectorRef.markForCheck();
}
}
diff --git a/lib/core/interface/public-api.ts b/lib/core/interface/public-api.ts
index ed6c8ab637..b69f6f445a 100644
--- a/lib/core/interface/public-api.ts
+++ b/lib/core/interface/public-api.ts
@@ -17,3 +17,4 @@
export * from './authentication.interface';
export * from './injection.tokens';
+export * from './search-configuration.interface';
diff --git a/lib/core/interface/search-configuration.interface.ts b/lib/core/interface/search-configuration.interface.ts
new file mode 100644
index 0000000000..fe68d17edb
--- /dev/null
+++ b/lib/core/interface/search-configuration.interface.ts
@@ -0,0 +1,24 @@
+/*!
+ * @license
+ * Copyright 2016 Alfresco Software, Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { QueryBody } from 'alfresco-js-api';
+
+export interface SearchConfigurationInterface {
+
+ generateQueryBody(searchTerm: string, maxResults: string, skipCount: string): QueryBody;
+
+}
diff --git a/lib/core/services/public-api.ts b/lib/core/services/public-api.ts
index 67cdea661e..f9eea442a1 100644
--- a/lib/core/services/public-api.ts
+++ b/lib/core/services/public-api.ts
@@ -46,3 +46,4 @@ export * from './shared-links-api.service';
export * from './sites.service';
export * from './discovery-api.service';
export * from './comment-process.service';
+export * from './search-configuration.service';
diff --git a/lib/core/services/search-configuration.service.ts b/lib/core/services/search-configuration.service.ts
new file mode 100644
index 0000000000..92d490d382
--- /dev/null
+++ b/lib/core/services/search-configuration.service.ts
@@ -0,0 +1,45 @@
+/*!
+ * @license
+ * Copyright 2016 Alfresco Software, Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { Injectable } from '@angular/core';
+import { QueryBody } from 'alfresco-js-api';
+import { SearchConfigurationInterface } from '../interface/search-configuration.interface';
+
+@Injectable()
+export class SearchConfigurationService implements SearchConfigurationInterface {
+
+ constructor() {
+ }
+
+ public generateQueryBody(searchTerm: string, maxResults: string, skipCount: string): QueryBody {
+ let defaultQueryBody: QueryBody = {
+ query: {
+ query: searchTerm ? `${searchTerm}* OR name:${searchTerm}*` : searchTerm
+ },
+ include: ['path', 'allowableOperations'],
+ paging: {
+ maxItems: maxResults,
+ skipCount: skipCount
+ },
+ filterQueries: [
+ { query: "TYPE:'cm:folder' OR TYPE:'cm:content'" },
+ { query: 'NOT cm:creator:System' }]
+ };
+
+ return defaultQueryBody;
+ }
+}
diff --git a/lib/core/services/search.service.ts b/lib/core/services/search.service.ts
index fa7806bed7..bcf345ca59 100644
--- a/lib/core/services/search.service.ts
+++ b/lib/core/services/search.service.ts
@@ -21,15 +21,14 @@ import { Observable } from 'rxjs/Observable';
import { AlfrescoApiService } from './alfresco-api.service';
import { AuthenticationService } from './authentication.service';
import 'rxjs/add/observable/throw';
+import { SearchConfigurationService } from './search-configuration.service';
-/**
- * Internal service used by Document List component.
- */
@Injectable()
export class SearchService {
constructor(public authService: AuthenticationService,
- private apiService: AlfrescoApiService) {
+ private apiService: AlfrescoApiService,
+ private searchConfigurationService: SearchConfigurationService) {
}
getNodeQueryResults(term: string, options?: SearchOptions): Observable {
@@ -38,8 +37,8 @@ export class SearchService {
.catch(err => this.handleError(err));
}
- search(query: QueryBody): Observable {
- const searchQuery = Object.assign(query);
+ search(searchTerm: string, maxResults: string, skipCount: string): Observable {
+ const searchQuery = Object.assign(this.searchConfigurationService.generateQueryBody(searchTerm, maxResults, skipCount));
const promise = this.apiService.getInstance().search.searchApi.search(searchQuery);
return Observable
@@ -47,6 +46,14 @@ export class SearchService {
.catch(err => this.handleError(err));
}
+ searchByQueryBody(queryBody: QueryBody): Observable {
+ const promise = this.apiService.getInstance().search.searchApi.search(queryBody);
+
+ return Observable
+ .fromPromise(promise)
+ .catch(err => this.handleError(err));
+ }
+
private handleError(error: any): Observable {
return Observable.throw(error || 'Server error');
}
diff --git a/lib/core/services/service.module.ts b/lib/core/services/service.module.ts
index 7aa25ed88b..4a905442b7 100644
--- a/lib/core/services/service.module.ts
+++ b/lib/core/services/service.module.ts
@@ -47,6 +47,7 @@ import { TranslateLoaderService } from './translate-loader.service';
import { TranslationService } from './translation.service';
import { UploadService } from './upload.service';
import { UserPreferencesService } from './user-preferences.service';
+import { SearchConfigurationService } from './search-configuration.service';
@NgModule({
imports: [],
@@ -81,7 +82,8 @@ import { UserPreferencesService } from './user-preferences.service';
SharedLinksApiService,
SitesService,
DiscoveryApiService,
- CommentProcessService
+ CommentProcessService,
+ SearchConfigurationService
],
exports: [
]