introduction of @isArchived special filter. Fulltext now by default filters with @!isArchived, label search without filtering for archived

This commit is contained in:
zadam 2019-09-03 20:16:38 +02:00
parent 36b575c286
commit 494ec0b051
4 changed files with 44 additions and 11 deletions

View File

@ -67,8 +67,8 @@ module.exports = function(filters, selectedColumns = 'notes.*') {
const params = []; const params = [];
for (const filter of filters) { for (const filter of filters) {
if (['orderby', 'limit'].includes(filter.name.toLowerCase())) { if (['isarchived', 'orderby', 'limit'].includes(filter.name.toLowerCase())) {
continue; // orderby and limit are not real filters continue; // these are not real filters
} }
where += " " + filter.relation + " "; where += " " + filter.relation + " ";

View File

@ -166,7 +166,7 @@ async function findNotes(query) {
return apiResults; return apiResults;
} }
function isArchived(notePath) { function isNotePathArchived(notePath) {
// if the note is archived directly // if the note is archived directly
if (archived[notePath[notePath.length - 1]] !== undefined) { if (archived[notePath[notePath.length - 1]] !== undefined) {
return true; return true;
@ -182,11 +182,23 @@ function isArchived(notePath) {
return false; return false;
} }
/**
* This assumes that note is available. "archived" note means that there isn't a single non-archived note-path
* leading to this note.
*
* @param noteId
*/
function isArchived(noteId) {
const notePath = getSomePath(noteId);
return isNotePathArchived(notePath);
}
function search(noteId, tokens, path, results) { function search(noteId, tokens, path, results) {
if (tokens.length === 0) { if (tokens.length === 0) {
const retPath = getSomePath(noteId, path); const retPath = getSomePath(noteId, path);
if (retPath && !isArchived(retPath)) { if (retPath && !isNotePathArchived(retPath)) {
const thisNoteId = retPath[retPath.length - 1]; const thisNoteId = retPath[retPath.length - 1];
const thisParentNoteId = retPath[retPath.length - 2]; const thisParentNoteId = retPath[retPath.length - 2];
@ -320,7 +332,7 @@ function getSomePath(noteId, path = []) {
function getNotePath(noteId) { function getNotePath(noteId) {
const retPath = getSomePath(noteId); const retPath = getSomePath(noteId);
if (retPath && !isArchived(retPath)) { if (retPath) {
const noteTitle = getNoteTitleForPath(retPath); const noteTitle = getNoteTitleForPath(retPath);
const parentNoteId = childToParent[noteId][0]; const parentNoteId = childToParent[noteId][0];
@ -344,7 +356,7 @@ function evaluateSimilarity(text1, text2, noteId, results) {
return; return;
} }
if (isArchived(notePath)) { if (isNotePathArchived(notePath)) {
coeff -= 0.2; // archived penalization coeff -= 0.2; // archived penalization
} }
@ -449,7 +461,7 @@ function resortChildToParent(noteId) {
/** /**
* @param noteId * @param noteId
* @returns {boolean} - true if note exists (is not deleted) and is not archived. * @returns {boolean} - true if note exists (is not deleted) and is available in current note hoisting
*/ */
function isAvailable(noteId) { function isAvailable(noteId) {
const notePath = getNotePath(noteId); const notePath = getNotePath(noteId);
@ -470,6 +482,7 @@ module.exports = {
getNotePath, getNotePath,
getNoteTitleForPath, getNoteTitleForPath,
isAvailable, isAvailable,
isArchived,
load, load,
findSimilarNotes findSimilarNotes
}; };

View File

@ -74,6 +74,12 @@ module.exports = function (searchText) {
} }
} }
filters.push({
relation: 'and',
name: 'isArchived',
operator: 'not-exists'
});
filters.push({ filters.push({
relation: 'or', relation: 'or',
name: 'noteId', name: 'noteId',

View File

@ -17,19 +17,33 @@ async function searchForNoteIds(searchString) {
const {query, params} = buildSearchQuery(filters, 'notes.noteId'); const {query, params} = buildSearchQuery(filters, 'notes.noteId');
try { try {
const noteIds = await sql.getColumn(query, params); let noteIds = await sql.getColumn(query, params);
const availableNoteIds = noteIds.filter(noteCacheService.isAvailable); noteIds = noteIds.filter(noteCacheService.isAvailable);
const isArchivedFilter = filters.find(filter => filter.name.toLowerCase() === 'isarchived');
if (isArchivedFilter) {console.log(isArchivedFilter);
if (isArchivedFilter.operator === 'exists') {
noteIds = noteIds.filter(noteCacheService.isArchived);
}
else if (isArchivedFilter.operator === 'not-exists') {
noteIds = noteIds.filter(noteId => !noteCacheService.isArchived(noteId));
}
else {
throw new Error(`Unrecognized isArchived operator ${isArchivedFilter.operator}`);
}
}
const limitFilter = filters.find(filter => filter.name.toLowerCase() === 'limit'); const limitFilter = filters.find(filter => filter.name.toLowerCase() === 'limit');
if (limitFilter) { if (limitFilter) {
const limit = parseInt(limitFilter.value); const limit = parseInt(limitFilter.value);
return availableNoteIds.splice(0, limit); return noteIds.splice(0, limit);
} }
else { else {
return availableNoteIds; return noteIds;
} }
} }