mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 18:30:09 +00:00
added tag querying.... (not checked to be optimal)
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
96594be0db
commit
cad5d21697
@ -152,19 +152,6 @@ var TagsPrototype = {
|
|||||||
// }
|
// }
|
||||||
__index: null,
|
__index: null,
|
||||||
|
|
||||||
// XXX each of the arguments can be:
|
|
||||||
// - tag -> resolves to list of values
|
|
||||||
// - query -> resolves to list of values
|
|
||||||
// - list of values
|
|
||||||
__query_ns: {
|
|
||||||
and: function(...args){
|
|
||||||
},
|
|
||||||
or: function(...args){
|
|
||||||
},
|
|
||||||
not: function(...args){
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
// Utils...
|
// Utils...
|
||||||
//
|
//
|
||||||
@ -337,7 +324,8 @@ var TagsPrototype = {
|
|||||||
return [...new Set(
|
return [...new Set(
|
||||||
Object.entries(this.__index || {})
|
Object.entries(this.__index || {})
|
||||||
.filter(function(e){
|
.filter(function(e){
|
||||||
return tag == '*' || that.match(tag, e[0]) })
|
return tag == '*'
|
||||||
|
|| that.match(tag, e[0]) })
|
||||||
.map(function(s){ return [...s[1]] })
|
.map(function(s){ return [...s[1]] })
|
||||||
.flat())] },
|
.flat())] },
|
||||||
|
|
||||||
@ -458,9 +446,53 @@ var TagsPrototype = {
|
|||||||
// 'x',
|
// 'x',
|
||||||
// ['or', 'a', 'b'],
|
// ['or', 'a', 'b'],
|
||||||
// ['not', 'z']])
|
// ['not', 'z']])
|
||||||
query: function(){
|
// XXX each of the arguments can be:
|
||||||
|
// - tag -> resolves to list of values
|
||||||
|
// - query -> resolves to list of values
|
||||||
|
// - list of values
|
||||||
|
__query_ns: {
|
||||||
|
and: function(...args){
|
||||||
|
// NOTE: we are sorting the lists here to start with the
|
||||||
|
// largest and smallest lists (head/tail) to drop the
|
||||||
|
// majority of the values the earliest and speed things
|
||||||
|
// up...
|
||||||
|
args = args
|
||||||
|
.sort(function(a, b){ return a.length - b.length })
|
||||||
|
return [...args
|
||||||
|
.reduce(function(res, l){
|
||||||
|
return res.intersect(l) },
|
||||||
|
new Set(args.pop()))] },
|
||||||
|
or: function(...args){
|
||||||
|
return [...new Set(args.flat())] },
|
||||||
|
not: function(...args){
|
||||||
|
return [...args
|
||||||
|
.reduce(function(res, l){
|
||||||
|
return res.subtract(l) },
|
||||||
|
new Set(args.shift()))] },
|
||||||
|
},
|
||||||
|
// XXX add support for string queries...
|
||||||
|
parseQuery: function(query){
|
||||||
// XXX
|
// XXX
|
||||||
},
|
},
|
||||||
|
query: function(query){
|
||||||
|
var that = this
|
||||||
|
var ns = this.__query_ns
|
||||||
|
|
||||||
|
// Query Language Executor...
|
||||||
|
var QL = function(args){
|
||||||
|
return args[0] in ns ?
|
||||||
|
ns[args[0]].call(ns, ...QL(args.slice(1)))
|
||||||
|
: args
|
||||||
|
.map(function(arg){
|
||||||
|
return arg instanceof Array ?
|
||||||
|
QL(arg)
|
||||||
|
: that.values(arg) }) }
|
||||||
|
|
||||||
|
return QL(query instanceof Array ?
|
||||||
|
query
|
||||||
|
: [query] )
|
||||||
|
.flat()
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
// Object utility API...
|
// Object utility API...
|
||||||
|
|||||||
@ -215,6 +215,7 @@ Array.prototype.sortAs = function(other){
|
|||||||
|
|
||||||
|
|
||||||
// Set set operation shorthands...
|
// Set set operation shorthands...
|
||||||
|
// XXX should these accept lists of sets???
|
||||||
Set.prototype.unite = function(other){
|
Set.prototype.unite = function(other){
|
||||||
return new Set([...this, ...other]) }
|
return new Set([...this, ...other]) }
|
||||||
Set.prototype.intersect = function(other){
|
Set.prototype.intersect = function(other){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user