mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	add observables to search results
This commit is contained in:
		| @@ -1,9 +1,11 @@ | ||||
| import { HttpClient, HttpParams } from '@angular/common/http'; | ||||
| import { Injectable } from '@angular/core'; | ||||
| import { Observable } from 'rxjs'; | ||||
| import { map } from 'rxjs/operators'; | ||||
| import { PaperlessDocument } from 'src/app/data/paperless-document'; | ||||
| import { SearchResult } from 'src/app/data/search-result'; | ||||
| import { environment } from 'src/environments/environment'; | ||||
| import { DocumentService } from './document.service'; | ||||
|  | ||||
|  | ||||
| @Injectable({ | ||||
| @@ -11,14 +13,19 @@ import { environment } from 'src/environments/environment'; | ||||
| }) | ||||
| export class SearchService { | ||||
|    | ||||
|   constructor(private http: HttpClient) { } | ||||
|   constructor(private http: HttpClient, private documentService: DocumentService) { } | ||||
|  | ||||
|   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}) | ||||
|     return this.http.get<SearchResult>(`${environment.apiBaseUrl}search/`, {params: httpParams}).pipe( | ||||
|       map(result => { | ||||
|         result.results.forEach(hit => this.documentService.addObservablesToDocument(hit.document)) | ||||
|         return result | ||||
|       }) | ||||
|     ) | ||||
|   } | ||||
|  | ||||
|   autocomplete(term: string): Observable<string[]> { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 jonaswinkler
					jonaswinkler