Item search with name includes
This commit is contained in:
parent
c3c11dca3b
commit
4ec573e822
2 changed files with 23 additions and 1 deletions
|
@ -25,7 +25,7 @@
|
|||
<div class="left" id="search-filter" style="display: inline-block; vertical-align: top">
|
||||
<label for="search-filter-field">Filter By:</label>
|
||||
<br>
|
||||
<input id="search-filter-field" type="text" placeholder="str >= 15 & dex >= 10" style="width: 25vw; padding: 8px">
|
||||
<input id="search-filter-field" type="text" placeholder="name ?= "blue" & str >= 15 & dex >= 10" style="width: 25vw; padding: 8px">
|
||||
<br>
|
||||
<div id="search-filter-error" style="color: #ff0000"></div>
|
||||
</div>
|
||||
|
|
22
query.js
22
query.js
|
@ -6,6 +6,7 @@
|
|||
* | cmpEq
|
||||
*
|
||||
* cmpEq := cmpRel "=" cmpEq
|
||||
* | cmpRel "?=" sLit
|
||||
* | cmpRel "!=" cmpEq
|
||||
*
|
||||
* cmpRel := sum "<=" cmpRel
|
||||
|
@ -308,6 +309,10 @@ const compileQueryExpr = (function() {
|
|||
++col;
|
||||
continue;
|
||||
}
|
||||
if (exprStr.slice(col, col+2) === "?=") {
|
||||
pushSymbol("?=");
|
||||
continue;
|
||||
}
|
||||
// parse a numeric literal
|
||||
let m;
|
||||
if ((m = /^\d+(?:\.\d*)?/.exec(exprStr.substring(col))) !== null) {
|
||||
|
@ -408,6 +413,23 @@ const compileQueryExpr = (function() {
|
|||
throw new Error('???'); // wtf
|
||||
};
|
||||
}
|
||||
case '?=': {
|
||||
tokens.advance();
|
||||
const right = takeCmpEq(tokens);
|
||||
return (i, ie) => {
|
||||
const a = left(i, ie), b = right(i, ie);
|
||||
if (typeof a !== typeof b) return false;
|
||||
switch (typeof a) {
|
||||
case 'number':
|
||||
return Math.abs(left(i, ie) - right(i, ie)) < 1e-4;
|
||||
case 'boolean':
|
||||
return a === b;
|
||||
case 'string':
|
||||
return a.toLowerCase().includes(b.toLowerCase());
|
||||
}
|
||||
throw new Error('???'); // wtf
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
return left;
|
||||
|
|
Loading…
Reference in a new issue