From 23ee354023272efdca261ee7f52025fe69e15b79 Mon Sep 17 00:00:00 2001 From: Jim Mason Date: Sat, 7 Jan 2023 11:08:52 +0000 Subject: [PATCH] fixed full text search to split on non-word character, per default utf8mb4 collation semantics partly satisfies #379 --- INSTALLATION.md | 2 +- engine/impl/Library.php | 20 ++++++++++++-------- js/playlists.track.js | 6 +++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/INSTALLATION.md b/INSTALLATION.md index 5938546f..ba7b6f22 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -91,7 +91,7 @@ particulars, then read on. may locate and/or name the file differently. In the `[mysqld]` section, add the lines: - ft_min_word_len = 3 + ft_min_word_len = 1 ft_stopword_file = '' If `ft_min_word_len` or `ft_stopword_file` is already in the file, diff --git a/engine/impl/Library.php b/engine/impl/Library.php index 66ca90d5..6d5dc014 100644 --- a/engine/impl/Library.php +++ b/engine/impl/Library.php @@ -3,7 +3,7 @@ * Zookeeper Online * * @author Jim Mason - * @copyright Copyright (C) 1997-2022 Jim Mason + * @copyright Copyright (C) 1997-2023 Jim Mason * @link https://zookeeper.ibinx.com/ * @license GPL-3.0 * @@ -112,6 +112,13 @@ class LibraryImpl extends DBO implements ILibrary { "\"\u{201c}\u{201d}", // double quotation mark ]; + /* + * words to exclude from a full-text search + */ + private static $ftExclude = [ + "a", "an", "and", "or", "the" + ]; + private static function orderBy($sortBy) { if(substr($sortBy, -1) == "-") { $sortBy = substr($sortBy, 0, -1); @@ -839,11 +846,6 @@ public function listLabels($op, $key, $limit) { return $result; } - public static function ftfilter($elt) { - return strlen($elt) > 1 && - $elt != "an" && $elt != "and" && $elt != "or" && $elt != "the"; - } - public function searchFullText($type, $key, $size, $offset) { $retVal = array(); $loggedIn = Engine::session()->isAuth("u"); @@ -856,8 +858,10 @@ public function searchFullText($type, $key, $size, $offset) { if(substr($key, 0, 2) == "\\\"") { $search = $key; } else { - $words = array_filter(explode(" ", $key), array(__CLASS__, "ftfilter")); - $search = "+".implode(" +",$words); + $words = array_filter(preg_split('/\W+/u', $key, 0, PREG_SPLIT_NO_EMPTY), function($word) { + return !in_array($word, self::$ftExclude); + }); + $search = "+" . implode(" +", $words); } // JM 2010-09-26 remove semicolons to thwart injection attacks diff --git a/js/playlists.track.js b/js/playlists.track.js index 4dcf5c3f..dce3bbc9 100644 --- a/js/playlists.track.js +++ b/js/playlists.track.js @@ -2,7 +2,7 @@ // Zookeeper Online // // @author Jim Mason -// @copyright Copyright (C) 1997-2022 Jim Mason +// @copyright Copyright (C) 1997-2023 Jim Mason // @link https://zookeeper.ibinx.com/ // @license GPL-3.0 // @@ -20,7 +20,7 @@ // http://www.gnu.org/licenses/ // -/*! Zookeeper Online (C) 1997-2022 Jim Mason | @source: https://zookeeper.ibinx.com/ | @license: magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3.0 */ +/*! Zookeeper Online (C) 1997-2023 Jim Mason | @source: https://zookeeper.ibinx.com/ | @license: magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3.0 */ $().ready(function(){ const NME_ENTRY='nme-entry'; @@ -718,7 +718,7 @@ $().ready(function(){ }).on('click', function() { $(this).autocomplete('search', this.value); }).autocomplete({ - minLength: 3, + minLength: 1, source: function(rq, rs) { var artist = rq.term;