Files
Notes/src/services/search/expressions/note_content_fulltext.js
T
2020-05-17 10:11:19 +02:00

34 lines
964 B
JavaScript

"use strict";
const NoteSet = require('../note_set');
const noteCache = require('../../note_cache/note_cache');
class NoteContentFulltextExp {
constructor(tokens) {
this.tokens = tokens;
}
async execute(noteSet) {
const resultNoteSet = new NoteSet();
const wheres = this.tokens.map(token => "note_contents.content LIKE " + utils.prepareSqlForLike('%', token, '%'));
const noteIds = await sql.getColumn(`
SELECT notes.noteId
FROM notes
JOIN note_contents ON notes.noteId = note_contents.noteId
WHERE isDeleted = 0 AND isProtected = 0 AND ${wheres.join(' AND ')}`);
const results = [];
for (const noteId of noteIds) {
if (noteSet.hasNoteId(noteId) && noteId in noteCache.notes) {
resultNoteSet.add(noteCache.notes[noteId]);
}
}
return results;
}
}
module.exports = NoteContentFulltextExp;