From 020bfec5149c76929f376cdb1ce93daf08bc00c6 Mon Sep 17 00:00:00 2001 From: Emil Zhai Date: Fri, 2 Dec 2022 09:15:05 +0000 Subject: [PATCH] feat: add fuzzy match to filter --- Access_Core.php | 28 ++++++++++++++++++++++------ page/console.php | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/Access_Core.php b/Access_Core.php index de7123b..ad5bd65 100644 --- a/Access_Core.php +++ b/Access_Core.php @@ -66,6 +66,7 @@ class Access_Core { $type = $this->request->get('type', 1); $filter = $this->request->get('filter', 'all'); + $fuzzy = $this->request->get('fuzzy', ''); $pagenum = $this->request->get('page', 1); $offset = (max(intval($pagenum), 1) - 1) * $this->config->pageSize; $query = $this->db->select()->from('table.access_logs') @@ -87,18 +88,33 @@ class Access_Core switch ($filter) { case 'ip': $ip = $this->request->get('ip', ''); - $query->where('ip = ?', $ip); - $qcount->where('ip = ?', $ip); + if ($fuzzy == '1') { + $query->where('ip LIKE ?', $ip); + $qcount->where('ip LIKE ?', $ip); + } else { + $query->where('ip = ?', $ip); + $qcount->where('ip = ?', $ip); + } break; case 'post': $cid = $this->request->get('cid', ''); - $query->where('content_id = ?', $cid); - $qcount->where('content_id = ?', $cid); + if ($fuzzy == '1') { + $query->where('content_id LIKE ?', $cid); + $qcount->where('content_id LIKE ?', $cid); + } else { + $query->where('content_id = ?', $cid); + $qcount->where('content_id = ?', $cid); + } break; case 'path': $path = $this->request->get('path', ''); - $query->where('path = ?', $path); - $qcount->where('path = ?', $path); + if ($fuzzy == '1') { + $query->where('path LIKE ?', $path); + $qcount->where('path LIKE ?', $path); + } else { + $query->where('path = ?', $path); + $qcount->where('path = ?', $path); + } break; } $list = $this->db->fetchAll($query); diff --git a/page/console.php b/page/console.php index f26a751..a7ccc2f 100644 --- a/page/console.php +++ b/page/console.php @@ -49,6 +49,10 @@ $access = new Access_Core(); +