2020-05-23 10:25:22 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const Expression = require('./expression');
|
|
|
|
const NoteSet = require('../note_set');
|
2021-06-29 22:15:57 +02:00
|
|
|
const buildComparator = require("../services/build_comparator");
|
2020-05-23 10:25:22 +02:00
|
|
|
|
2020-05-23 20:52:55 +02:00
|
|
|
/**
|
2023-06-30 11:18:34 +02:00
|
|
|
* Search string is lower cased for case-insensitive comparison. But when retrieving properties,
|
|
|
|
* we need the case-sensitive form, so we have this translation object.
|
2020-05-23 20:52:55 +02:00
|
|
|
*/
|
|
|
|
const PROP_MAPPING = {
|
|
|
|
"noteid": "noteId",
|
|
|
|
"title": "title",
|
|
|
|
"type": "type",
|
|
|
|
"mime": "mime",
|
|
|
|
"isprotected": "isProtected",
|
2020-08-20 00:15:08 +02:00
|
|
|
"isarchived": "isArchived",
|
2020-05-23 20:52:55 +02:00
|
|
|
"datecreated": "dateCreated",
|
|
|
|
"datemodified": "dateModified",
|
|
|
|
"utcdatecreated": "utcDateCreated",
|
|
|
|
"utcdatemodified": "utcDateModified",
|
|
|
|
"parentcount": "parentCount",
|
|
|
|
"childrencount": "childrenCount",
|
|
|
|
"attributecount": "attributeCount",
|
|
|
|
"labelcount": "labelCount",
|
2021-02-19 20:42:34 +01:00
|
|
|
"ownedlabelcount": "ownedLabelCount",
|
2021-01-22 22:20:17 +01:00
|
|
|
"relationcount": "relationCount",
|
2021-02-19 20:42:34 +01:00
|
|
|
"ownedrelationcount": "ownedRelationCount",
|
|
|
|
"relationcountincludinglinks": "relationCountIncludingLinks",
|
|
|
|
"ownedrelationcountincludinglinks": "ownedRelationCountIncludingLinks",
|
|
|
|
"targetrelationcount": "targetRelationCount",
|
|
|
|
"targetrelationcountincludinglinks": "targetRelationCountIncludingLinks",
|
2021-01-22 22:20:17 +01:00
|
|
|
"contentsize": "contentSize",
|
|
|
|
"notesize": "noteSize",
|
|
|
|
"revisioncount": "revisionCount"
|
2020-05-23 20:52:55 +02:00
|
|
|
};
|
|
|
|
|
2020-05-23 10:25:22 +02:00
|
|
|
class PropertyComparisonExp extends Expression {
|
2020-05-23 20:52:55 +02:00
|
|
|
static isProperty(name) {
|
|
|
|
return name in PROP_MAPPING;
|
|
|
|
}
|
|
|
|
|
2021-02-18 22:10:49 +01:00
|
|
|
constructor(searchContext, propertyName, operator, comparedValue) {
|
2020-05-23 10:25:22 +02:00
|
|
|
super();
|
|
|
|
|
2020-05-23 20:52:55 +02:00
|
|
|
this.propertyName = PROP_MAPPING[propertyName];
|
2021-02-18 22:10:49 +01:00
|
|
|
this.operator = operator; // for DEBUG mode
|
|
|
|
this.comparedValue = comparedValue; // for DEBUG mode
|
|
|
|
this.comparator = buildComparator(operator, comparedValue);
|
2021-01-22 22:20:17 +01:00
|
|
|
|
|
|
|
if (['contentsize', 'notesize', 'revisioncount'].includes(this.propertyName)) {
|
|
|
|
searchContext.dbLoadNeeded = true;
|
|
|
|
}
|
2020-05-23 10:25:22 +02:00
|
|
|
}
|
|
|
|
|
2022-12-23 14:02:18 +01:00
|
|
|
execute(inputNoteSet, executionContext, searchContext) {
|
2020-05-23 10:25:22 +02:00
|
|
|
const resNoteSet = new NoteSet();
|
|
|
|
|
2020-05-23 12:27:44 +02:00
|
|
|
for (const note of inputNoteSet.notes) {
|
2020-05-23 20:52:55 +02:00
|
|
|
let value = note[this.propertyName];
|
2020-05-23 10:25:22 +02:00
|
|
|
|
2020-05-23 20:52:55 +02:00
|
|
|
if (value !== undefined && value !== null && typeof value !== 'string') {
|
|
|
|
value = value.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
value = value.toLowerCase();
|
|
|
|
}
|
2020-07-19 23:19:45 +02:00
|
|
|
|
2020-05-23 10:25:22 +02:00
|
|
|
if (this.comparator(value)) {
|
|
|
|
resNoteSet.add(note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return resNoteSet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = PropertyComparisonExp;
|