Skip to content

Commit

Permalink
fixed full text search to split on non-word character, per default ut…
Browse files Browse the repository at this point in the history
…f8mb4 collation semantics

partly satisfies #379
  • Loading branch information
RocketMan committed Jan 9, 2023
1 parent 5e38813 commit 23ee354
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 12 additions & 8 deletions engine/impl/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zookeeper Online
*
* @author Jim Mason <jmason@ibinx.com>
* @copyright Copyright (C) 1997-2022 Jim Mason <jmason@ibinx.com>
* @copyright Copyright (C) 1997-2023 Jim Mason <jmason@ibinx.com>
* @link https://zookeeper.ibinx.com/
* @license GPL-3.0
*
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions js/playlists.track.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Zookeeper Online
//
// @author Jim Mason <jmason@ibinx.com>
// @copyright Copyright (C) 1997-2022 Jim Mason <jmason@ibinx.com>
// @copyright Copyright (C) 1997-2023 Jim Mason <jmason@ibinx.com>
// @link https://zookeeper.ibinx.com/
// @license GPL-3.0
//
Expand All @@ -20,7 +20,7 @@
// http://www.gnu.org/licenses/
//

/*! Zookeeper Online (C) 1997-2022 Jim Mason <jmason@ibinx.com> | @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 <jmason@ibinx.com> | @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';
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 23ee354

Please sign in to comment.