-
Notifications
You must be signed in to change notification settings - Fork 6
/
results.component.ts
84 lines (66 loc) · 2.53 KB
/
results.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { Component, Inject } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { ActivatedRoute, Params } from '@angular/router';
import { ApiResponseError, CountQueryResponse, KnoraApiConnection } from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken, NotificationService, SearchParams } from '@dasch-swiss/dsp-ui';
@Component({
selector: 'app-results',
templateUrl: './results.component.html',
styleUrls: ['./results.component.scss']
})
export class ResultsComponent {
searchParams: SearchParams;
resIri: string;
resourceIri: string;
// number of all results
numberOfAllResults: number;
// search params
searchQuery: string;
searchMode: 'fulltext' | 'gravsearch';
// progress status
loading = true;
constructor(
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection,
private _notification: NotificationService,
private _route: ActivatedRoute,
private _titleService: Title
) {
this._route.paramMap.subscribe((params: Params) => {
this.searchQuery = decodeURIComponent(params.get('q'));
this.searchMode = (decodeURIComponent(params.get('mode')) === 'fulltext' ? 'fulltext' : 'gravsearch');
this.checkResourceCount();
this.searchParams = {
query: this.searchQuery,
mode: this.searchMode
};
// get the project iri if exists
if (params.get('project')) {
this.searchParams.filter = {
limitToProject: decodeURIComponent(params.get('project'))
};
}
});
// set the page title
this._titleService.setTitle('Search results for ' + this.searchParams.mode + ' search');
}
// get the number of search results for given query
checkResourceCount() {
this.loading = true;
if (this.searchMode === 'fulltext') {
// perform count query
this._dspApiConnection.v2.search.doFulltextSearchCountQuery(this.searchQuery).subscribe(
(response: CountQueryResponse) => {
this.numberOfAllResults = response.numberOfResults;
this.loading = false;
},
(error: ApiResponseError) => {
this._notification.openSnackBar(error);
this.loading = false;
}
);
}
}
openResource(id: string) {
this.resourceIri = id;
}
}