mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-16 09:19:43 +00:00
a8f70b08a8
* First pass at modular wiki indexes An exploratory experiment * Fix tests * Faster checking for existence of index methods We don't really need to check the type * Use the index for the has operator * Fix typo * Move iterator index methods into indexer modules Now boot.js doesn't know the core indexers * Fix up the other iterator index functions * Fix crash with missing index branch * Limit the field indexer to values less than 128 characters * Fallback to the old manual scan if the index method returns null * Sadly, we can no longe re-use the field indexer to accelerate the `has` operator, because the index now omits tiddlers that have field values longer than the limit Still need to make the index configuration exposed somehow * Rearrange tests so that we can test with and without indexers We also need to expose the list of enabled indexers as a config option * Test the field indexer with different length fields So that we test the indexed and non-indexed codepaths
59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
/*\
|
|
title: $:/core/modules/filters/tag.js
|
|
type: application/javascript
|
|
module-type: filteroperator
|
|
|
|
Filter operator for checking for the presence of a tag
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
/*
|
|
Export our filter function
|
|
*/
|
|
exports.tag = function(source,operator,options) {
|
|
var results = [],indexedResults;
|
|
if((operator.suffix || "").toLowerCase() === "strict" && !operator.operand) {
|
|
// New semantics:
|
|
// Always return copy of input if operator.operand is missing
|
|
source(function(tiddler,title) {
|
|
results.push(title);
|
|
});
|
|
} else {
|
|
// Old semantics:
|
|
var tiddlers;
|
|
if(operator.prefix === "!") {
|
|
// Returns a copy of the input if operator.operand is missing
|
|
tiddlers = options.wiki.getTiddlersWithTag(operator.operand);
|
|
source(function(tiddler,title) {
|
|
if(tiddlers.indexOf(title) === -1) {
|
|
results.push(title);
|
|
}
|
|
});
|
|
} else {
|
|
// Returns empty results if operator.operand is missing
|
|
if(source.byTag) {
|
|
indexedResults = source.byTag(operator.operand);
|
|
if(indexedResults) {
|
|
return indexedResults;
|
|
}
|
|
} else {
|
|
tiddlers = options.wiki.getTiddlersWithTag(operator.operand);
|
|
source(function(tiddler,title) {
|
|
if(tiddlers.indexOf(title) !== -1) {
|
|
results.push(title);
|
|
}
|
|
});
|
|
results = options.wiki.sortByList(results,operator.operand);
|
|
}
|
|
}
|
|
}
|
|
return results;
|
|
};
|
|
|
|
})();
|