mirror of
https://github.com/alexankitty/Myrient-Search-Engine.git
synced 2026-01-15 16:33:15 -03:00
45 lines
922 B
JavaScript
45 lines
922 B
JavaScript
import debugPrint from "../utility/printutils.js";
|
|
import {
|
|
search as elasticSearch,
|
|
getSuggestions as elasticSuggestions,
|
|
} from "../services/elasticsearch.js";
|
|
import { File, Metadata } from "../database/models/index.js";
|
|
|
|
export default class Searcher {
|
|
constructor(fields) {
|
|
this.fields = [...fields];
|
|
this.indexing = false;
|
|
}
|
|
|
|
async findAllMatches(query, options) {
|
|
try {
|
|
return await elasticSearch(query, options);
|
|
} catch (err) {
|
|
console.error(err);
|
|
return { items: [], elapsed: 0 };
|
|
}
|
|
}
|
|
|
|
async getSuggestions(query, options) {
|
|
try {
|
|
return await elasticSuggestions(query, options);
|
|
} catch (err) {
|
|
console.error(err);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
findIndex(id) {
|
|
return File.findByPk(id, {
|
|
include: {
|
|
model: Metadata,
|
|
as: "details"
|
|
}
|
|
});
|
|
}
|
|
|
|
async getIndexSize() {
|
|
return await File.count();
|
|
}
|
|
}
|