infinite scroll for search results

This commit is contained in:
Jonas Winkler
2020-11-02 12:25:02 +01:00
parent 3d02d4b446
commit 658f038f3c
6 changed files with 75 additions and 38 deletions

View File

@@ -2,27 +2,9 @@ import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { PaperlessDocument } from 'src/app/data/paperless-document';
import { SearchResult } from 'src/app/data/search-result';
import { environment } from 'src/environments/environment';
export class SearchResultHighlightedText {
text?: string
term?: number
toString(): string {
return this.text
}
}
export class SearchResult {
id?: number
title?: string
content?: string
score?: number
highlights?: SearchResultHighlightedText[][]
document?: PaperlessDocument
}
@Injectable({
providedIn: 'root'
@@ -31,8 +13,12 @@ export class SearchService {
constructor(private http: HttpClient) { }
search(query: string): Observable<SearchResult[]> {
return this.http.get<SearchResult[]>(`${environment.apiBaseUrl}search/`, {params: new HttpParams().set('query', query)})
search(query: string, page?: number): Observable<SearchResult> {
let httpParams = new HttpParams().set('query', query)
if (page) {
httpParams = httpParams.set('page', page.toString())
}
return this.http.get<SearchResult>(`${environment.apiBaseUrl}search/`, {params: httpParams})
}
autocomplete(term: string): Observable<string[]> {