better path/name search syntax

This commit is contained in:
ed 2021-02-22 02:16:47 +01:00
parent 6774bd88f9
commit cd02bfea7a
2 changed files with 25 additions and 25 deletions

View file

@ -50,17 +50,15 @@ class U2idx(object):
_conv_dt(qobj, body, "dt_min", "mt >= ?")
_conv_dt(qobj, body, "dt_max", "mt <= ?")
for seg, dk in [["path", "rd"], ["name", "fn"]]:
for inv in ["no", "yes"]:
jk = "{}_{}".format(seg, inv)
if jk in body:
_conv_txt(qobj, body, jk, dk)
if seg in body:
_conv_txt(qobj, body, seg, dk)
qstr = "select * from up"
qv = []
if qobj:
qk = []
for k, v in sorted(qobj.items()):
qk.append(k)
qk.append(k.split("\n")[0])
qv.append(v)
qstr = " and ".join(qk)
@ -70,8 +68,7 @@ class U2idx(object):
def run_query(self, vols, qstr, qv):
qv = tuple(qv)
# self.log("qs: " + qstr)
# self.log("qv: " + repr(qv))
self.log("qs: {} {}".format(qstr, repr(qv)))
ret = []
lim = 100
@ -128,19 +125,21 @@ def _conv_dt(q, body, k, sql):
def _conv_txt(q, body, k, sql):
v = body[k]
print("[" + v + "]")
for v in body[k].split(" "):
inv = ""
if v.startswith("-"):
inv = "not"
v = v[1:]
head = "'%'||"
if v.startswith("^"):
head = ""
v = v[1:]
head = "'%'||"
if v.startswith("^"):
head = ""
v = v[1:]
tail = "||'%'"
if v.endswith("$"):
tail = ""
v = v[:-1]
tail = "||'%'"
if v.endswith("$"):
tail = ""
v = v[:-1]
inv = "not" if k.endswith("_no") else ""
qk = "{} {} like {}?{}".format(sql, inv, head, tail)
q[qk] = u8safe(v)
qk = "{} {} like {}?{}".format(sql, inv, head, tail)
q[qk + "\n" + v] = u8safe(v)

View file

@ -585,12 +585,10 @@ function autoplay_blocked() {
["dtu", "dt_max", "max. iso8601", ""]
],
["path",
["pn", "path_no", "path NOT contains", "30"],
["py", "path_yes", "path contains", "30"]
["path", "path", "path contains", "46"]
],
["name",
["nn", "name_no", "name NOT contains", "30"],
["ny", "name_yes", "name contains", "30"]
["name", "name", "name contains", "46"]
]
];
var html = [];
@ -599,11 +597,14 @@ function autoplay_blocked() {
html.push('<tr><td><br />' + sconf[a][0] + '</td>');
for (var b = 1; b < 3; b++) {
var hn = "srch_" + sconf[a][b][0];
var csp = (sconf[a].length == 2) ? 2 : 1;
html.push(
'<td><input id="' + hn + 'c" type="checkbox">\n' +
'<td colspan="' + csp + '"><input id="' + hn + 'c" type="checkbox">\n' +
'<label for="' + hn + 'c">' + sconf[a][b][2] + '</label>\n' +
'<br /><input id="' + hn + 'v" type="text" size="' + sconf[a][b][3] +
'" name="' + sconf[a][b][1] + '" /></td>');
if (csp == 2)
break;
}
html.push('</tr>');
}