mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
search result fixes (#413)
This commit is contained in:
@@ -64,14 +64,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="inner-layout__content">
|
<div class="inner-layout__content">
|
||||||
<adf-search
|
|
||||||
#search
|
|
||||||
[searchTerm]="searchedWord"
|
|
||||||
[maxResults]="maxItems"
|
|
||||||
[skipResults]="skipCount"
|
|
||||||
(resultLoaded)="onSearchResultLoaded($event)">
|
|
||||||
</adf-search>
|
|
||||||
|
|
||||||
<div class="inner-layout__panel">
|
<div class="inner-layout__panel">
|
||||||
<div class="adf-search-results">
|
<div class="adf-search-results">
|
||||||
<adf-search-filter #searchFilter></adf-search-filter>
|
<adf-search-filter #searchFilter></adf-search-filter>
|
||||||
|
@@ -27,7 +27,7 @@ import { Component, OnInit, ViewChild } from '@angular/core';
|
|||||||
import { NodePaging, Pagination, MinimalNodeEntity } from 'alfresco-js-api';
|
import { NodePaging, Pagination, MinimalNodeEntity } from 'alfresco-js-api';
|
||||||
import { ActivatedRoute, Params } from '@angular/router';
|
import { ActivatedRoute, Params } from '@angular/router';
|
||||||
import { SearchQueryBuilderService, SearchComponent as AdfSearchComponent, NodePermissionService } from '@alfresco/adf-content-services';
|
import { SearchQueryBuilderService, SearchComponent as AdfSearchComponent, NodePermissionService } from '@alfresco/adf-content-services';
|
||||||
import { SearchConfigurationService, UserPreferencesService, SearchService } from '@alfresco/adf-core';
|
import { UserPreferencesService } from '@alfresco/adf-core';
|
||||||
import { PageComponent } from '../page.component';
|
import { PageComponent } from '../page.component';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { AppStore } from '../../store/states/app.state';
|
import { AppStore } from '../../store/states/app.state';
|
||||||
@@ -37,7 +37,6 @@ import { NavigateToLocationAction } from '../../store/actions';
|
|||||||
selector: 'app-search',
|
selector: 'app-search',
|
||||||
templateUrl: './search.component.html',
|
templateUrl: './search.component.html',
|
||||||
styleUrls: ['./search.component.scss'],
|
styleUrls: ['./search.component.scss'],
|
||||||
providers: [SearchService]
|
|
||||||
})
|
})
|
||||||
export class SearchComponent extends PageComponent implements OnInit {
|
export class SearchComponent extends PageComponent implements OnInit {
|
||||||
|
|
||||||
@@ -48,14 +47,11 @@ export class SearchComponent extends PageComponent implements OnInit {
|
|||||||
queryParamName = 'q';
|
queryParamName = 'q';
|
||||||
data: NodePaging;
|
data: NodePaging;
|
||||||
totalResults = 0;
|
totalResults = 0;
|
||||||
maxItems = 5;
|
|
||||||
skipCount = 0;
|
|
||||||
sorting = ['name', 'asc'];
|
sorting = ['name', 'asc'];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public permission: NodePermissionService,
|
public permission: NodePermissionService,
|
||||||
private queryBuilder: SearchQueryBuilderService,
|
private queryBuilder: SearchQueryBuilderService,
|
||||||
private searchConfiguration: SearchConfigurationService,
|
|
||||||
store: Store<AppStore>,
|
store: Store<AppStore>,
|
||||||
preferences: UserPreferencesService,
|
preferences: UserPreferencesService,
|
||||||
route: ActivatedRoute) {
|
route: ActivatedRoute) {
|
||||||
@@ -72,23 +68,41 @@ export class SearchComponent extends PageComponent implements OnInit {
|
|||||||
|
|
||||||
this.sorting = this.getSorting();
|
this.sorting = this.getSorting();
|
||||||
|
|
||||||
|
this.subscriptions.push(
|
||||||
this.queryBuilder.updated.subscribe(() => {
|
this.queryBuilder.updated.subscribe(() => {
|
||||||
this.sorting = this.getSorting();
|
this.sorting = this.getSorting();
|
||||||
});
|
}),
|
||||||
|
|
||||||
|
this.queryBuilder.executed.subscribe(data => {
|
||||||
|
console.log(data);
|
||||||
|
this.onSearchResultLoaded(data);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
if (this.route) {
|
if (this.route) {
|
||||||
this.route.params.forEach((params: Params) => {
|
this.route.params.forEach((params: Params) => {
|
||||||
this.searchedWord = params.hasOwnProperty(this.queryParamName) ? params[this.queryParamName] : null;
|
this.searchedWord = params.hasOwnProperty(this.queryParamName) ? params[this.queryParamName] : null;
|
||||||
if (this.searchedWord) {
|
const query = this.formatSearchQuery(this.searchedWord);
|
||||||
const queryBody = this.searchConfiguration.generateQueryBody(this.searchedWord, 0, 100);
|
|
||||||
|
|
||||||
this.queryBuilder.userQuery = queryBody.query.query;
|
if (query) {
|
||||||
|
this.queryBuilder.userQuery = query;
|
||||||
this.queryBuilder.update();
|
this.queryBuilder.update();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private formatSearchQuery(userInput: string) {
|
||||||
|
if (!userInput) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const suffix = userInput.lastIndexOf('*') >= 0 ? '' : '*';
|
||||||
|
const query = `${userInput}${suffix} OR name:${userInput}${suffix}`;
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
onSearchResultLoaded(nodePaging: NodePaging) {
|
onSearchResultLoaded(nodePaging: NodePaging) {
|
||||||
this.data = nodePaging;
|
this.data = nodePaging;
|
||||||
this.totalResults = this.getNumberOfResults();
|
this.totalResults = this.getNumberOfResults();
|
||||||
@@ -102,9 +116,6 @@ export class SearchComponent extends PageComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onPaginationChanged(pagination: Pagination) {
|
onPaginationChanged(pagination: Pagination) {
|
||||||
this.maxItems = pagination.maxItems;
|
|
||||||
this.skipCount = pagination.skipCount;
|
|
||||||
|
|
||||||
this.queryBuilder.paging = {
|
this.queryBuilder.paging = {
|
||||||
maxItems: pagination.maxItems,
|
maxItems: pagination.maxItems,
|
||||||
skipCount: pagination.skipCount
|
skipCount: pagination.skipCount
|
||||||
|
Reference in New Issue
Block a user