mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
server-ts: Port services/search/value_extractor
This commit is contained in:
parent
80e6ced5db
commit
216f3f2c07
@ -1,5 +1,5 @@
|
|||||||
const {note} = require('./becca_mocking.js');
|
const {note} = require('./becca_mocking.js');
|
||||||
const ValueExtractor = require('../../src/services/search/value_extractor.js');
|
const ValueExtractor = require('../../src/services/search/value_extractor');
|
||||||
const becca = require('../../src/becca/becca.js');
|
const becca = require('../../src/becca/becca.js');
|
||||||
const SearchContext = require('../../src/services/search/search_context');
|
const SearchContext = require('../../src/services/search/search_context');
|
||||||
|
|
||||||
|
@ -450,7 +450,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getAttributeCaseInsensitive(type: string, name: string, value: string | null) {
|
getAttributeCaseInsensitive(type: string, name: string, value?: string | null) {
|
||||||
name = name.toLowerCase();
|
name = name.toLowerCase();
|
||||||
value = value ? value.toLowerCase() : null;
|
value = value ? value.toLowerCase() : null;
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ const NoteContentFulltextExp = require('../expressions/note_content_fulltext.js'
|
|||||||
const OrderByAndLimitExp = require('../expressions/order_by_and_limit.js');
|
const OrderByAndLimitExp = require('../expressions/order_by_and_limit.js');
|
||||||
const AncestorExp = require('../expressions/ancestor.js');
|
const AncestorExp = require('../expressions/ancestor.js');
|
||||||
const buildComparator = require('./build_comparator.js');
|
const buildComparator = require('./build_comparator.js');
|
||||||
const ValueExtractor = require('../value_extractor.js');
|
const ValueExtractor = require('../value_extractor');
|
||||||
const utils = require('../../utils');
|
const utils = require('../../utils');
|
||||||
const TrueExp = require('../expressions/true.js');
|
const TrueExp = require('../expressions/true.js');
|
||||||
const IsHiddenExp = require('../expressions/is_hidden.js');
|
const IsHiddenExp = require('../expressions/is_hidden.js');
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
import BNote = require("../../becca/entities/bnote");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search string is lower cased for case-insensitive comparison. But when retrieving properties,
|
* Search string is lower cased for case-insensitive comparison. But when retrieving properties,
|
||||||
* we need a case-sensitive form, so we have this translation object.
|
* we need a case-sensitive form, so we have this translation object.
|
||||||
*/
|
*/
|
||||||
const PROP_MAPPING = {
|
const PROP_MAPPING: Record<string, string> = {
|
||||||
"noteid": "noteId",
|
"noteid": "noteId",
|
||||||
"title": "title",
|
"title": "title",
|
||||||
"type": "type",
|
"type": "type",
|
||||||
@ -32,8 +34,14 @@ const PROP_MAPPING = {
|
|||||||
"revisioncount": "revisionCount"
|
"revisioncount": "revisionCount"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface SearchContext {
|
||||||
|
dbLoadNeeded: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
class ValueExtractor {
|
class ValueExtractor {
|
||||||
constructor(searchContext, propertyPath) {
|
private propertyPath: string[];
|
||||||
|
|
||||||
|
constructor(searchContext: SearchContext, propertyPath: string[]) {
|
||||||
this.propertyPath = propertyPath.map(pathEl => pathEl.toLowerCase());
|
this.propertyPath = propertyPath.map(pathEl => pathEl.toLowerCase());
|
||||||
|
|
||||||
if (this.propertyPath[0].startsWith('#')) {
|
if (this.propertyPath[0].startsWith('#')) {
|
||||||
@ -81,10 +89,10 @@ class ValueExtractor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extract(note) {
|
extract(note: BNote) {
|
||||||
let cursor = note;
|
let cursor: BNote | null = note;
|
||||||
|
|
||||||
let i;
|
let i: number = 0;
|
||||||
|
|
||||||
const cur = () => this.propertyPath[i];
|
const cur = () => this.propertyPath[i];
|
||||||
|
|
||||||
@ -105,8 +113,7 @@ class ValueExtractor {
|
|||||||
i++;
|
i++;
|
||||||
|
|
||||||
const attr = cursor.getAttributeCaseInsensitive('relation', cur());
|
const attr = cursor.getAttributeCaseInsensitive('relation', cur());
|
||||||
|
cursor = (attr ? attr.targetNote || null : null);
|
||||||
cursor = attr ? attr.targetNote : null;
|
|
||||||
}
|
}
|
||||||
else if (cur() === 'parents') {
|
else if (cur() === 'parents') {
|
||||||
cursor = cursor.parents[0];
|
cursor = cursor.parents[0];
|
||||||
@ -118,7 +125,7 @@ class ValueExtractor {
|
|||||||
return Math.random().toString(); // string is expected for comparison
|
return Math.random().toString(); // string is expected for comparison
|
||||||
}
|
}
|
||||||
else if (cur() in PROP_MAPPING) {
|
else if (cur() in PROP_MAPPING) {
|
||||||
return cursor[PROP_MAPPING[cur()]];
|
return (cursor as any)[PROP_MAPPING[cur()]];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// FIXME
|
// FIXME
|
Loading…
x
Reference in New Issue
Block a user