public async searchBooks(query: string): Promise<Book[]> {
const aggregationPipeline = [
{
$search: {
"index": "fulltextsearch",
"compound": {
"must": [
{
"text": {
query,
"path": ["title", "authors.name", "genres"],
fuzzy: {
maxEdits: 2
}
}
}
],
"should": [
{
"equals": {
"value": true,
"path": "bookOfTheMonth",
"score": {
"boost": { value: 10 }
}
}
}
]
}
}
}
];
const books = await collections?.books?.aggregate(aggregationPipeline).toArray() as Book[];
return books;
}