48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { HttpService } from "@nestjs/axios";
|
|
import { Injectable } from "@nestjs/common";
|
|
import { map, Observable } from "rxjs";
|
|
|
|
/**
|
|
* Search service provider
|
|
*/
|
|
@Injectable()
|
|
export class SearchService {
|
|
constructor(private readonly httpService: HttpService) {}
|
|
|
|
// Find paper by its ID
|
|
findByID(id: string): object {
|
|
let es_query = {
|
|
query: {
|
|
query_string: {
|
|
query: 'id:' + id
|
|
}
|
|
}
|
|
}
|
|
|
|
return this.httpService.get('http://localhost:9200/_search', {
|
|
data: es_query,
|
|
headers: {'Content-Type': 'application/json'},
|
|
}).pipe(
|
|
map(response=>response.data)
|
|
);
|
|
}
|
|
|
|
// Find paper by context
|
|
findByContext(query_str: string): object {
|
|
let es_query = {
|
|
query: {
|
|
query_string: {
|
|
query: query_str,
|
|
default_field: "content"
|
|
}
|
|
}
|
|
}
|
|
|
|
return this.httpService.get('http://localhost:9200/_search', {
|
|
data: es_query,
|
|
headers: {'Content-Type': 'application/json'},
|
|
}).pipe(
|
|
map(response=>response.data)
|
|
);
|
|
}
|
|
} |