lots of fixes to .match(..)

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-12-27 04:17:11 +03:00
parent 7022eb93b7
commit 5aedf7ac30
2 changed files with 46 additions and 22 deletions

View File

@ -2034,9 +2034,9 @@ module.CollectionTags = core.ImageGridFeatures.Feature({
new Set(that.data.tags.values(tag)) new Set(that.data.tags.values(tag))
: new Set() : new Set()
/*/ /*/
// XXX this is not correct as we can have mixed tags...
// ...use actual tag API...
local_tags[tag] = (!new_set || title == MAIN_COLLECTION_TITLE) ? local_tags[tag] = (!new_set || title == MAIN_COLLECTION_TITLE) ?
// XXX this is not correct as we can have mixed tags...
// ...use actual tag API...
[...(that.data.tags.__index || {})[tag] || []] [...(that.data.tags.__index || {})[tag] || []]
: [] : []
//*/ //*/

View File

@ -552,8 +552,19 @@ var BaseTagsPrototype = {
// tags and path graph to check tag "reachability"... // tags and path graph to check tag "reachability"...
// //
// Matching rule: // Matching rule:
// a and b match iff both a and b are reachable on a single path // a and b match iff both a and b match existing tags and at least
// where a is above b. // one matching pair exists where both items are reachable on a single
// combined path in the order given.
//
// i.e. for paths: a/b/c/x, c/d/e the following are reachable:
// a and c -- on single path
// a and e -- on combined path
// a/b and e -- a/b matches a/b/c and on combined path with e
// a/b and c/e --
// while the following are not:
// c and a -- reverse order
// a/d and e -- a/d does not match anything
// a/x and e -- x and e are not reachable
// //
// //
// Example: // Example:
@ -575,15 +586,18 @@ var BaseTagsPrototype = {
// ts.match('c', 'a') // -> false // ts.match('c', 'a') // -> false
// //
// //
// NOTE: matching a root/base tag will yield true if at least one // NOTE: when matching a root/base tag this matches iff b is root/base
// occurrence of the tag in the system exists as root/base. // this is equivalent to .directMatch(..)
// ...there is an alternative way to think about this issue //
// where .match(..) would return true iff the tag is exclusively // XXX REVISE...
// a root/base tag respectively but this seems a bit less useful. // XXX this will not build a tree if given a list in b... is this correct???
match: function(a, b, cmp){ match: function(a, b, cmp){
var that = this var that = this
var PP = this.PATH_SEPARATOR_PATTERN var PP = this.PATH_SEPARATOR_PATTERN
var root = /^\s*[\\\/]/.test(a)
var base = /[\\\/]\s*$/.test(a)
// get paths with tag... // get paths with tag...
var paths = function(tag){ var paths = function(tag){
return that.directMatch(tag, cmp) return that.directMatch(tag, cmp)
@ -595,7 +609,7 @@ var BaseTagsPrototype = {
seen = seen || new Set() seen = seen || new Set()
return paths(tag) return paths(tag)
.reduce(function(res, path){ .reduce(function(res, path){
if(res == true){ if(res){
return res return res
} }
@ -614,15 +628,25 @@ var BaseTagsPrototype = {
false false
: search(target, tag, seen.add(tag)) }, false) }, false) } : search(target, tag, seen.add(tag)) }, false) }, false) }
var res = this.directMatch(...arguments) var seen = new Set()
return res !== false ? var res = (root || base
|| b instanceof Array
|| typeof(b) == typeof('str')) ?
// b is given and a is an edge -> try a direct match...
this.directMatch(...arguments)
// get all the compatible tags...
: Object.keys(this.__index || {})
.concat([...(this.persistent || [])])
.unique()
.filter(function(tag){
return that.directMatch(a, tag)
|| search(a, tag, seen) })
return (root || base || res !== false) ?
res res
// if there is no edge (root/base) a then no point in further // if a is a path then it must exist and search it's tail...
// searching... : this.directMatch(a).length > 0
: ((/^\s*[\\\/]/.test(a) || /[\\\/]\s*$/.test(a)) && search(this.splitPath(a).pop(), b)
&& this.match(a, cmp).length == 0) ?
false
: search(a, b)
}, },
// Search tags... // Search tags...
// //
@ -837,14 +861,14 @@ var BaseTagsPrototype = {
// NOTE: this does not support any query syntax... // NOTE: this does not support any query syntax...
values: function(tag){ values: function(tag){
var that = this var that = this
tag = this.normalize(tag || '*') tag = tag || '*'
return [...new Set( return Object.entries(this.__index || {})
Object.entries(this.__index || {})
.filter(function(e){ .filter(function(e){
return tag == '*' return tag == '*'
|| that.match(tag, e[0]) }) || that.match(tag, e[0]) })
.map(function(s){ return [...s[1]] }) .map(function(s){ return [...s[1]] })
.flat())] }, .flat()
.unique() },
// Definitions as paths... // Definitions as paths...
// //