working on text search in tags...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-12-09 08:44:54 +03:00
parent b48441e2cc
commit fca01b2699

View File

@ -52,8 +52,8 @@ var TagsClassPrototype = {
// c:b/a -> b:c/a - sort sets within pats (current) // c:b/a -> b:c/a - sort sets within pats (current)
// or // or
// c:b/a -> b/a:c - sort paths within sets // c:b/a -> b/a:c - sort paths within sets
// XXX should this be .normalizeTags(..) ???
// XXX should we support priority braces, i.e. c:(b/a) // XXX should we support priority braces, i.e. c:(b/a)
// XXX should this be .normalizeTags(..) ???
normalize: function(...tags){ normalize: function(...tags){
var that = this var that = this
var tagRemovedChars = (this.config || {})['tagRemovedChars'] var tagRemovedChars = (this.config || {})['tagRemovedChars']
@ -72,10 +72,10 @@ var TagsClassPrototype = {
.toLowerCase() .toLowerCase()
.replace(tagRemovedChars, '') .replace(tagRemovedChars, '')
// sort sets within paths... // sort sets within paths...
.split(/[\\\/]/g) .split(/[\\\/]+/g)
.map(function(e){ .map(function(e){
return e return e
.split(/:/g) .split(/:+/g)
.sort() .sort()
.join(':') }) .join(':') })
.join('/') }) .join('/') })
@ -89,6 +89,15 @@ var TagsClassPrototype = {
res.pop() res.pop()
: res : res
}, },
splitTag: function(...tags){
tags = (tags.length == 1 && tags[0] instanceof Array) ?
tags.pop()
: tags
return this.normalize(tags)
.map(function(tag){
return tag.split(/[:\\\/]/g) })
.flat()
.unique() },
// Query parser... // Query parser...
// //
@ -226,10 +235,12 @@ var TagsPrototype = {
// Utils... // Utils...
// //
// proxy to Tags.normalize(..) // proxies to class methods...
// XXX Q: should this be .normalizeTags(..) ??? // XXX Q: should this be .normalizeTags(..) ???
normalize: function(...tags){ normalize: function(...tags){
return this.constructor.normalize.call(this, ...tags) }, return this.constructor.normalize.call(this, ...tags) },
splitTag: function(...tags){
return this.constructor.splitTag.call(this, ...tags) },
// NOTE: the query parser is generic and thus is implemented in the // NOTE: the query parser is generic and thus is implemented in the
// constructor... // constructor...
parseQuery: function(query){ parseQuery: function(query){
@ -365,13 +376,29 @@ var TagsPrototype = {
// XXX should we .match(..) the results??? // XXX should we .match(..) the results???
// ...not sure if this is needed as we are taking .tags() as input... // ...not sure if this is needed as we are taking .tags() as input...
// on the other hand we'd need to normalize the search string somehow... // on the other hand we'd need to normalize the search string somehow...
// ...this will likely force us into using a special regexp-like
// search syntax with special meanings given to ':' and '/' (and '\\')
search: function(str, tags){ search: function(str, tags){
// XXX should we do any pre-processing??? // XXX should we do any pre-processing???
str = str instanceof RegExp ? str : RegExp(str) str = str instanceof RegExp ? str : RegExp(str)
return (tags || this.tags()) return (tags || this._tags())
.filter(function(tag){ .filter(function(tag){
return str.test(tag) }) }, return str.test(tag) }) },
// XXX find a logical name...
// .searchable(..)
// .searchableTags(..)
// .expandedTags(..)
// ...
// XXX should we combine this with tags???
_tags: function(...args){
var that = this
return this.tags(...args)
// include original list...
.run(function(){
return this.concat(that.splitTag(this)) })
.unique() },
// Introspection... // Introspection...
// //
@ -400,6 +427,9 @@ var TagsPrototype = {
// //
// NOTE: this includes all the .persistent tags as well as all the // NOTE: this includes all the .persistent tags as well as all the
// tags actually used. // tags actually used.
//
// XXX should this return split values???
// i.e. 'red:car' -> ['red', 'car']
tags: function(value, ...tags){ tags: function(value, ...tags){
var that = this var that = this