TagSpaces is an offline, open source, document manager with tagging support
Improvement in the tag calculation
Ilian3217cd22efe8
diff --git a/data/js/search.js b/data/js/search.jsindex 0438ea157..db367c0f1 100644--- a/data/js/search.js+++ b/data/js/search.js@@ -23,6 +23,7 @@ define(function(require, exports, module) {};var calculateTags = function(data) {+ console.log("Calculating tags from search results");var allTags = [];data.forEach(function(fileEntry) {@@ -57,83 +58,88 @@ define(function(require, exports, module) {}// By empty filter just return the data- if(query.length <= 0) {- return data;- }+ if(query.length > 0) {- var queryTerms = query.split(" ");-- // Analysing filter- var includedTerms = [];- var excludedTerms = [];- var includedTags = [];- var excludedTags = [];-- queryTerms.forEach(function (value, index) {- if(value.length > 1) {- if(value.indexOf("!") == 0) {- excludedTerms.push([value.substring(1,value.length),false]);- } else if(value.indexOf("+") == 0) {- includedTags.push([value.substring(1,value.length),true]);- } else if(value.indexOf("-") == 0) {- excludedTags.push([value.substring(1,value.length),true]);- } else {- includedTerms.push([value,false]);- }- }- });-- data = _.filter(data, function(value) {- // Searching in the whole filename- var searchIn = value[TSCORE.fileListFILENAME].toLowerCase();- var tags = value[TSCORE.fileListTAGS];- var result = true;- if(tags.length < 1 && includedTags.length > 0) {- return false;- }- for (var i=0; i < includedTerms.length; i++) {- if(searchIn.indexOf(includedTerms[i][0]) >= 0) {- includedTerms[i][1] = true;+ var queryTerms = query.split(" ");++ // Analysing filter+ var includedTerms = [];+ var excludedTerms = [];+ var includedTags = [];+ var excludedTags = [];++ queryTerms.forEach(function (value, index) {+ if(value.length > 1) {+ if(value.indexOf("!") == 0) {+ excludedTerms.push([value.substring(1,value.length),false]);+ } else if(value.indexOf("+") == 0) {+ includedTags.push([value.substring(1,value.length),true]);+ } else if(value.indexOf("-") == 0) {+ excludedTags.push([value.substring(1,value.length),true]);} else {+ includedTerms.push([value,false]);+ }+ }+ });++ data = _.filter(data, function(value) {+ // Searching in the whole filename+ var searchIn = value[TSCORE.fileListFILENAME].toLowerCase();+ var tags = value[TSCORE.fileListTAGS];+ var result = true;+ if(tags.length < 1 && includedTags.length > 0) {return false;}- };- for (var i=0; i < excludedTerms.length; i++) {- if(searchIn.indexOf(excludedTerms[i][0]) < 0) {- excludedTerms[i][1] = true;- } else {- return false;+ for (var i=0; i < includedTerms.length; i++) {+ if(searchIn.indexOf(includedTerms[i][0]) >= 0) {+ includedTerms[i][1] = true;+ } else {+ return false;+ }+ };+ for (var i=0; i < excludedTerms.length; i++) {+ if(searchIn.indexOf(excludedTerms[i][0]) < 0) {+ excludedTerms[i][1] = true;+ } else {+ return false;+ }+ };++ for (var i=0; i < includedTags.length; i++) {+ includedTags[i][1] = false;+ for (var j=0; j < tags.length; j++) {+ if(tags[j].toLowerCase() == includedTags[i][0]) {+ includedTags[i][1] = true;+ }+ }+ };+ for (var i=0; i < includedTags.length; i++) {+ result = result & includedTags[i][1];}- };- for (var i=0; i < includedTags.length; i++) {- includedTags[i][1] = false;- for (var j=0; j < tags.length; j++) {- if(tags[j].toLowerCase() == includedTags[i][0]) {- includedTags[i][1] = true;- }+ for (var i=0; i < excludedTags.length; i++) {+ excludedTags[i][1] = true;+ for (var j=0; j < tags.length; j++) {+ if(tags[j].toLowerCase() == excludedTags[i][0]) {+ excludedTags[i][1] = false;+ }+ }+ };+ for (var i=0; i < excludedTags.length; i++) {+ result = result & excludedTags[i][1];}- };- for (var i=0; i < includedTags.length; i++) {- result = result & includedTags[i][1];- }-- for (var i=0; i < excludedTags.length; i++) {- excludedTags[i][1] = true;- for (var j=0; j < tags.length; j++) {- if(tags[j].toLowerCase() == excludedTags[i][0]) {- excludedTags[i][1] = false;- }- }- };- for (var i=0; i < excludedTags.length; i++) {- result = result & excludedTags[i][1];- }-- return result;- });++ return result;+ });++ currentQuery = nextQuery;+ }- currentQuery = nextQuery;+ if(TSCORE.Config.getCalculateTags()) {+ // Find all tags in the current search results+ exports.calculateTags(data);+ }+return data;};diff --git a/data/js/tags.ui.js b/data/js/tags.ui.jsindex 1e629a2c6..0c231a8d2 100644--- a/data/js/tags.ui.js+++ b/data/js/tags.ui.js@@ -140,6 +140,8 @@ define(function(require, exports, module) {console.log("Generating TagGroups...");$("#tagGroupsContent").empty();$("#tagGroupsContent").addClass("accordion");++ // Show TagGroup create button if no taggroup existif(TSCORE.Config.Settings["tagGroups"].length < 1) {$("#tagGroupsContent").append($("<button>", {"class": "btn",@@ -152,15 +154,28 @@ define(function(require, exports, module) {return true;}- // Adding the the calculated tag group to the general list- //console.log("Calculated tags: "+JSON.stringify(exports.calculatedTags));- for(var i=0; i < TSCORE.Config.Settings["tagGroups"].length; i++) {- if(TSCORE.Config.Settings["tagGroups"][i].key == "CTG") {- TSCORE.Config.Settings["tagGroups"][i].children = exports.calculatedTags;- break;- }+ if(TSCORE.Config.getCalculateTags()) {+ // Adding tags to the calculated tag group+ //console.log("Calculated tags: "+JSON.stringify(exports.calculatedTags));+ for(var i=0; i < TSCORE.Config.Settings["tagGroups"].length; i++) {+ var tagGroupExist = false;+ if(TSCORE.Config.Settings["tagGroups"][i].key == "CTG") {+ TSCORE.Config.Settings["tagGroups"][i].children = exports.calculatedTags;+ tagGroupExist = true;+ break;+ }+ }+ // Adding the calculated tag group if it not exists+ if(!tagGroupExist) {+ TSCORE.Config.Settings["tagGroups"].push({+ "title": "Tags in Perspective",+ "key": "CTG",+ "expanded": true,+ "children": exports.calculatedTags+ });+ }}-+for(var i=0; i < TSCORE.Config.Settings["tagGroups"].length; i++) {$("#tagGroupsContent").append($("<div>", {"class": "accordion-group disableTextSelection",