[ADF-3381][ADF-3492] search results improvements (#3727)

* search results improvements

* fix search term formatting

* rollback the query change

* fix search test

* lint fix

* lint fix

* search page component to ts
This commit is contained in:
Denys Vuika
2018-10-16 16:51:49 +01:00
committed by Eugenio Romano
parent 0fc504b69e
commit 415d2185b1
12 changed files with 411 additions and 453 deletions

View File

@@ -73,12 +73,17 @@
"options": [
{ "key": "name", "label": "Name", "type": "FIELD", "field": "cm:name", "ascending": true },
{ "key": "content.sizeInBytes", "label": "Size", "type": "FIELD", "field": "content.size", "ascending": true },
{ "key": "description", "label": "Description", "type": "FIELD", "field": "cm:description", "ascending": true },
{ "key": "createdByUser", "label": "Author", "type": "FIELD", "field": "cm:creator", "ascending": true },
{ "key": "createdAt", "label": "Created", "type": "FIELD", "field": "cm:created", "ascending": true }
{ "key": "createdAt", "label": "Created", "type": "FIELD", "field": "cm:created", "ascending": true },
{ "key": "score", "label": "Relevance", "type": "FIELD", "field": "score", "ascending": false}
],
"defaults": [
{ "key": "name", "type": "FIELD", "field": "cm:name", "ascending": true }
{
"key": "score",
"type": "FIELD",
"field": "score",
"ascending": false
}
]
},
"filterQueries": [
@@ -101,11 +106,11 @@
"queries": [
{ "query": "created:2018", "label": "1.Created This Year" },
{ "query": "content.mimetype", "label": "2.Type" },
{ "query": "content.size:[0 TO 10240]", "label": "3.Size: xtra small"},
{ "query": "content.size:[0 TO 10240]", "label": "3.Size: Extra small"},
{ "query": "content.size:[10240 TO 102400]", "label": "4.Size: small"},
{ "query": "content.size:[102400 TO 1048576]", "label": "5.Size: medium" },
{ "query": "content.size:[1048576 TO 16777216]", "label": "6.Size: large" },
{ "query": "content.size:[16777216 TO 134217728]", "label": "7.Size: xtra large" },
{ "query": "content.size:[16777216 TO 134217728]", "label": "7.Size: Extra large" },
{ "query": "content.size:[134217728 TO MAX]", "label": "8.Size: XX large" }
]
},

View File

@@ -1,11 +1,3 @@
<adf-search [searchTerm]="searchedWord"
[maxResults]="maxItems"
[skipResults]="skipCount"
(resultLoaded)="onSearchResultLoaded($event)"
#searchResult>
</adf-search>
<div class="adf-search-results__facets">
<adf-search-chip-list [searchFilter]="searchFilter"></adf-search-chip-list>
</div>
@@ -14,6 +6,7 @@
<adf-search-filter #searchFilter></adf-search-filter>
<div class="adf-search-results__content">
<mat-progress-bar *ngIf="isLoading" color="primary" mode="indeterminate"></mat-progress-bar>
<div class="adf-search-results__sorting">
<adf-search-sorting-picker></adf-search-sorting-picker>
</div>
@@ -25,7 +18,7 @@
[showSitePicker]="false"
[showSettingsPanel]="false"
[currentFolderId]="null"
[nodeResult]="resultNodePageList"
[nodeResult]="data"
[disableDragArea]="true"
[pagination]="pagination"
(changedPageSize)="onRefreshPagination($event)"
@@ -33,7 +26,7 @@
(turnedNextPage)="onRefreshPagination($event)"
(loadNext)="onRefreshPagination($event)"
(turnedPreviousPage)="onRefreshPagination($event)"
(deleteElementSuccess)="onDeleteElementSuccess($event)">
(deleteElementSuccess)="onDeleteElementSuccess()">
</app-files-component>
</div>
</div>

View File

@@ -15,11 +15,11 @@
* limitations under the License.
*/
import { Component, OnInit, Optional, ViewChild, OnDestroy } from '@angular/core';
import { Component, OnInit, Optional, OnDestroy } from '@angular/core';
import { Router, ActivatedRoute, Params } from '@angular/router';
import { NodePaging, Pagination } from 'alfresco-js-api';
import { SearchComponent, SearchQueryBuilderService } from '@alfresco/adf-content-services';
import { UserPreferencesService, SearchService, SearchConfigurationService } from '@alfresco/adf-core';
import { SearchQueryBuilderService } from '@alfresco/adf-content-services';
import { UserPreferencesService, SearchService } from '@alfresco/adf-core';
import { Subscription } from 'rxjs';
@Component({
@@ -30,15 +30,11 @@ import { Subscription } from 'rxjs';
})
export class SearchResultComponent implements OnInit, OnDestroy {
@ViewChild('searchResult')
searchResult: SearchComponent;
queryParamName = 'q';
searchedWord = '';
resultNodePageList: NodePaging;
data: NodePaging;
pagination: Pagination;
maxItems: number;
skipCount = 0;
isLoading = true;
sorting = ['name', 'asc'];
@@ -47,9 +43,7 @@ export class SearchResultComponent implements OnInit, OnDestroy {
constructor(public router: Router,
private preferences: UserPreferencesService,
private queryBuilder: SearchQueryBuilderService,
private searchConfiguration: SearchConfigurationService,
@Optional() private route: ActivatedRoute) {
this.maxItems = this.preferences.paginationSize;
queryBuilder.paging = {
maxItems: this.preferences.paginationSize,
skipCount: 0
@@ -63,36 +57,55 @@ export class SearchResultComponent implements OnInit, OnDestroy {
this.subscriptions.push(
this.queryBuilder.updated.subscribe(() => {
this.sorting = this.getSorting();
this.isLoading = true;
}),
this.queryBuilder.executed.subscribe(data => {
this.onSearchResultLoaded(data);
this.isLoading = false;
})
);
if (this.route) {
this.route.params.forEach((params: Params) => {
this.searchedWord = params.hasOwnProperty(this.queryParamName) ? params[this.queryParamName] : null;
if (this.searchedWord) {
const queryBody = this.searchConfiguration.generateQueryBody(this.searchedWord, 0, 100);
const query = this.formatSearchQuery(this.searchedWord);
this.queryBuilder.userQuery = queryBody.query.query;
if (query) {
this.queryBuilder.userQuery = query;
this.queryBuilder.update();
} else {
this.queryBuilder.userQuery = null;
this.queryBuilder.executed.next({ list: { pagination: { totalItems: 0 }, entries: [] } });
}
});
}
}
private formatSearchQuery(userInput: string) {
if (!userInput) {
return null;
}
const suffix = userInput.lastIndexOf('*') >= 0 ? '' : '*';
const query = `cm:name:${userInput}${suffix} OR cm:title:${userInput}${suffix} OR cm:description:${userInput}${suffix}
OR ia:whatEvent:${userInput}${suffix} OR ia:descriptionEvent:${userInput}${suffix} OR lnk:title:${userInput}${suffix}
OR lnk:description:${userInput}${suffix} OR TEXT:${userInput}${suffix} OR TAG:${userInput}${suffix}`;
return query;
}
ngOnDestroy() {
this.subscriptions.forEach(subscription => subscription.unsubscribe());
this.subscriptions = [];
}
onSearchResultLoaded(nodePaging: NodePaging) {
this.resultNodePageList = nodePaging;
this.pagination = {...nodePaging.list.pagination };
this.data = nodePaging;
this.pagination = { ...nodePaging.list.pagination };
}
onRefreshPagination(pagination: Pagination) {
this.maxItems = pagination.maxItems;
this.skipCount = pagination.skipCount;
this.queryBuilder.paging = {
maxItems: pagination.maxItems,
skipCount: pagination.skipCount
@@ -100,8 +113,8 @@ export class SearchResultComponent implements OnInit, OnDestroy {
this.queryBuilder.update();
}
onDeleteElementSuccess(element: any) {
this.searchResult.reload();
onDeleteElementSuccess() {
this.queryBuilder.execute();
}
private getSorting(): string[] {