From cd02bfea7a4b6830a4a41e89b8dfc80caf5a7026 Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 22 Feb 2021 02:16:47 +0100 Subject: [PATCH] better path/name search syntax --- copyparty/u2idx.py | 39 +++++++++++++++++++-------------------- copyparty/web/browser.js | 11 ++++++----- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/copyparty/u2idx.py b/copyparty/u2idx.py index aa34c839..adef5b5a 100644 --- a/copyparty/u2idx.py +++ b/copyparty/u2idx.py @@ -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) diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 9cfb24e3..2d434cb9 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -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('
' + sconf[a][0] + ''); for (var b = 1; b < 3; b++) { var hn = "srch_" + sconf[a][b][0]; + var csp = (sconf[a].length == 2) ? 2 : 1; html.push( - '\n' + + '\n' + '\n' + '
'); + if (csp == 2) + break; } html.push(''); }