mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
refactoring to allow unit tests of the whole search subsystem
This commit is contained in:
parent
a06662f4ce
commit
cd48135394
@ -6,7 +6,7 @@ describe("Parser", () => {
|
||||
const rootExp = parser({
|
||||
fulltextTokens: ["hello", "hi"],
|
||||
expressionTokens: [],
|
||||
parsingContext: new ParsingContext(false)
|
||||
parsingContext: new ParsingContext({includeNoteContent: false})
|
||||
});
|
||||
|
||||
expect(rootExp.constructor.name).toEqual("NoteCacheFulltextExp");
|
||||
@ -17,7 +17,7 @@ describe("Parser", () => {
|
||||
const rootExp = parser({
|
||||
fulltextTokens: ["hello", "hi"],
|
||||
expressionTokens: [],
|
||||
parsingContext: new ParsingContext(true)
|
||||
parsingContext: new ParsingContext({includeNoteContent: true})
|
||||
});
|
||||
|
||||
expect(rootExp.constructor.name).toEqual("OrExp");
|
||||
@ -34,7 +34,7 @@ describe("Parser", () => {
|
||||
const rootExp = parser({
|
||||
fulltextTokens: [],
|
||||
expressionTokens: ["#mylabel", "=", "text"],
|
||||
parsingContext: new ParsingContext(true)
|
||||
parsingContext: new ParsingContext()
|
||||
});
|
||||
|
||||
expect(rootExp.constructor.name).toEqual("FieldComparisonExp");
|
||||
@ -64,7 +64,7 @@ describe("Parser", () => {
|
||||
const rootExp = parser({
|
||||
fulltextTokens: [],
|
||||
expressionTokens: ["#first", "=", "text", "#second", "=", "text"],
|
||||
parsingContext: new ParsingContext(true)
|
||||
parsingContext: new ParsingContext()
|
||||
});
|
||||
|
||||
expect(rootExp.constructor.name).toEqual("AndExp");
|
||||
@ -81,7 +81,7 @@ describe("Parser", () => {
|
||||
const rootExp = parser({
|
||||
fulltextTokens: [],
|
||||
expressionTokens: ["#first", "=", "text", "OR", "#second", "=", "text"],
|
||||
parsingContext: new ParsingContext(true)
|
||||
parsingContext: new ParsingContext()
|
||||
});
|
||||
|
||||
expect(rootExp.constructor.name).toEqual("OrExp");
|
||||
@ -98,7 +98,7 @@ describe("Parser", () => {
|
||||
const rootExp = parser({
|
||||
fulltextTokens: ["hello"],
|
||||
expressionTokens: ["#mylabel", "=", "text"],
|
||||
parsingContext: new ParsingContext(false)
|
||||
parsingContext: new ParsingContext()
|
||||
});
|
||||
|
||||
expect(rootExp.constructor.name).toEqual("AndExp");
|
||||
@ -115,7 +115,7 @@ describe("Parser", () => {
|
||||
const rootExp = parser({
|
||||
fulltextTokens: [],
|
||||
expressionTokens: ["#first", "=", "text", "OR", ["#second", "=", "text", "AND", "#third", "=", "text"]],
|
||||
parsingContext: new ParsingContext(false)
|
||||
parsingContext: new ParsingContext()
|
||||
});
|
||||
|
||||
expect(rootExp.constructor.name).toEqual("OrExp");
|
||||
|
7
spec/search.spec.js
Normal file
7
spec/search.spec.js
Normal file
@ -0,0 +1,7 @@
|
||||
const searchService = require('../src/services/search/search');
|
||||
|
||||
describe("Search", () => {
|
||||
it("fulltext parser without content", () => {
|
||||
// searchService.
|
||||
});
|
||||
});
|
@ -12,6 +12,8 @@ const sessionSecret = require('./services/session_secret');
|
||||
const cls = require('./services/cls');
|
||||
require('./entities/entity_constructor');
|
||||
require('./services/handlers');
|
||||
require('./services/hoisted_note_loader');
|
||||
require('./services/note_cache/note_cache_loader');
|
||||
|
||||
const app = express();
|
||||
|
||||
@ -120,4 +122,4 @@ require('./services/scheduler');
|
||||
module.exports = {
|
||||
app,
|
||||
sessionParser
|
||||
};
|
||||
};
|
||||
|
@ -1,19 +1,6 @@
|
||||
const optionService = require('./options');
|
||||
const sqlInit = require('./sql_init');
|
||||
const eventService = require('./events');
|
||||
|
||||
let hoistedNoteId = 'root';
|
||||
|
||||
eventService.subscribe(eventService.ENTITY_CHANGED, async ({entityName, entity}) => {
|
||||
if (entityName === 'options' && entity.name === 'hoistedNoteId') {
|
||||
hoistedNoteId = entity.value;
|
||||
}
|
||||
});
|
||||
|
||||
sqlInit.dbReady.then(async () => {
|
||||
hoistedNoteId = await optionService.getOption('hoistedNoteId');
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
getHoistedNoteId: () => hoistedNoteId
|
||||
};
|
||||
getHoistedNoteId: () => hoistedNoteId,
|
||||
setHoistedNoteId(noteId) { hoistedNoteId = noteId; }
|
||||
};
|
||||
|
14
src/services/hoisted_note_loader.js
Normal file
14
src/services/hoisted_note_loader.js
Normal file
@ -0,0 +1,14 @@
|
||||
const optionService = require('./options');
|
||||
const sqlInit = require('./sql_init');
|
||||
const eventService = require('./events');
|
||||
const hoistedNote = require('./hoisted_note');
|
||||
|
||||
eventService.subscribe(eventService.ENTITY_CHANGED, async ({entityName, entity}) => {
|
||||
if (entityName === 'options' && entity.name === 'hoistedNoteId') {
|
||||
hoistedNote.setHoistedNoteId(entity.value);
|
||||
}
|
||||
});
|
||||
|
||||
sqlInit.dbReady.then(async () => {
|
||||
hoistedNote.setHoistedNoteId(await optionService.getOption('hoistedNoteId'));
|
||||
});
|
@ -166,4 +166,4 @@ eventService.subscribe(eventService.ENTER_PROTECTED_SESSION, () => {
|
||||
noteCache.loadedPromise.then(() => noteCache.decryptProtectedNotes());
|
||||
});
|
||||
|
||||
module.exports = load;
|
||||
load();
|
||||
|
@ -4,8 +4,6 @@ const noteCache = require('./note_cache');
|
||||
const hoistedNoteService = require('../hoisted_note');
|
||||
const stringSimilarity = require('string-similarity');
|
||||
|
||||
require('./note_cache_loader')();
|
||||
|
||||
function isNotePathArchived(notePath) {
|
||||
const noteId = notePath[notePath.length - 1];
|
||||
const note = noteCache.notes[noteId];
|
||||
|
@ -1,10 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
class ParsingContext {
|
||||
constructor(includeNoteContent) {
|
||||
this.includeNoteContent = includeNoteContent;
|
||||
constructor(params = {}) {
|
||||
this.includeNoteContent = !!params.includeNoteContent;
|
||||
this.fuzzyAttributeSearch = !!params.fuzzyAttributeSearch;
|
||||
this.highlightedTokens = [];
|
||||
this.fuzzyAttributeSearch = false;
|
||||
this.error = null;
|
||||
}
|
||||
|
||||
|
@ -61,8 +61,10 @@ async function searchNotesForAutocomplete(query) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const parsingContext = new ParsingContext(false);
|
||||
parsingContext.fuzzyAttributeSearch = true;
|
||||
const parsingContext = new ParsingContext({
|
||||
includeNoteContent: false,
|
||||
fuzzyAttributeSearch: true
|
||||
});
|
||||
|
||||
const expression = parseQueryToExpression(query, parsingContext);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user