From: Banana Date: Mon, 30 Dec 2019 22:42:59 +0000 (+0100) Subject: fixing search for non links X-Git-Tag: 2.4_2020-02-16~14 X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=0d9ee2eb20bfadcf76ec170295e2d9ded76fbabd;p=insipid.git fixing search for non links --- diff --git a/ChangeLog b/ChangeLog index 1a5426f..b81e2a1 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ version x.x - Seven Portals (tba) + Now including update instructions + + Fixed the search for words. See update instructions how to correct your data version 2.3 - Guardian of Steel (2019-12-30) diff --git a/documentation/update.txt b/documentation/update.txt index a50826e..0ee461d 100644 --- a/documentation/update.txt +++ b/documentation/update.txt @@ -1,3 +1,7 @@ -If you are updating from a previous version: +If you are updating from a previous version make sure every update info from the version +your are updating from is done. -2.3 -> x.x \ No newline at end of file +x.x ++ Run (after authentication) at /index.php?p=stats the "Search index update" to make the +search work again correctly. At success, there is no confirmation. To validate you can now search +for single words case-insensitive. \ No newline at end of file diff --git a/documentation/usage.txt b/documentation/usage.txt index 5d1ea16..92e165b 100644 --- a/documentation/usage.txt +++ b/documentation/usage.txt @@ -11,10 +11,15 @@ http(s)://your.domain.tld/path/to/insipid/index.php?m=auth If successful you can now manage your items. Edit buttons are visible now. Moderation and more overview can be access from the stats overview page. -HowToAdd a new link: +# HowToAdd a new link: There is no special "add a new link" option. Just paste the link into the search bar. If the link is already in your database the edit option will be shown. If not the add field will be shown and the possibility to safe the new link. -Usage of the email-importer can be found in the email-importer.txt file \ No newline at end of file +Usage of the email-importer can be found in the email-importer.txt file. + +# Search +The search is based on the link, description, tags and categories. +Technology behind is a mysql fulltext search in BOOLEAN MODE: https://dev.mysql.com/doc/refman/8.0/en/fulltext-boolean.html +Which means you can use special operators like +- or * \ No newline at end of file diff --git a/webroot/index.php b/webroot/index.php index 7a3013c..4150334 100644 --- a/webroot/index.php +++ b/webroot/index.php @@ -32,7 +32,7 @@ ini_set('error_reporting',-1); // E_ALL & E_STRICT # time settings date_default_timezone_set('Europe/Berlin'); -define('DEBUG',false); +define('DEBUG',true); ## check request $_urlToParse = filter_var($_SERVER['QUERY_STRING'],FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); diff --git a/webroot/job/email-import.php b/webroot/job/email-import.php index 8c68988..f48b586 100644 --- a/webroot/job/email-import.php +++ b/webroot/job/email-import.php @@ -181,6 +181,7 @@ if(!empty($emails)) { $newdata['search'] .= ' '.implode(" ",$newdata['tagArr']); $newdata['search'] .= ' '.implode(" ",$newdata['catArr']); $newdata['search'] = trim($newdata['search']); + $newdata['search'] = strtolower($newdata['search']); if(DEBUG === true) var_dump($newdata); diff --git a/webroot/lib/link.class.php b/webroot/lib/link.class.php index 1045b66..2ef8ce8 100644 --- a/webroot/lib/link.class.php +++ b/webroot/lib/link.class.php @@ -135,11 +135,12 @@ class Link { $this->load($this->_data['hash']); } - /** - * create a new link with the given data - * @param array $data - * @return boolean|int - */ + /** + * create a new link with the given data + * @param array $data + * @param bool $returnId + * @return boolean|int + */ public function create($data, $returnId = false) { $ret = false; @@ -181,9 +182,11 @@ class Link { $tagArr = Summoner::prepareTagOrCategoryStr($data['tag']); $search = $data['title']; - $search .= ' ' . $data['description']; - $search .= ' ' . implode(" ", $tagArr); - $search .= ' ' . implode(" ", $catArr); + $search .= ' '.$data['description']; + $search .= ' '.implode(" ", $tagArr); + $search .= ' '.implode(" ", $catArr); + $search = trim($search); + $search = strtolower($search); $this->DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE); diff --git a/webroot/lib/management.class.php b/webroot/lib/management.class.php index 3067800..df0c57a 100644 --- a/webroot/lib/management.class.php +++ b/webroot/lib/management.class.php @@ -463,7 +463,7 @@ class Management { MATCH (`search`) AGAINST ('".$this->DB->real_escape_string($searchStr)."' IN BOOLEAN MODE) AS score FROM `".DB_PREFIX."_link` AS t WHERE MATCH (`search`) AGAINST ('".$this->DB->real_escape_string($searchStr)."' IN BOOLEAN MODE)"; - $queryStr .= " WHERE ".$this->_decideLinkTypeForQuery(); + $queryStr .= " AND ".$this->_decideLinkTypeForQuery(); $queryStr .= " ORDER BY score DESC"; $query = $this->DB->query($queryStr); @@ -652,7 +652,9 @@ class Management { * for simpler management we have the search data in a separate column * it is not fancy or even technical nice but it damn works */ - private function _updateSearchIndex() { + public function updateSearchIndex() { + $ret = false; + $allLinks = array(); $queryStr = "SELECT hash FROM `".DB_PREFIX."_link`"; $query = $this->DB->query($queryStr); @@ -667,12 +669,10 @@ class Management { $searchStr = $l['title']; $searchStr .= ' '.$l['description']; - foreach($l['tags'] as $t) { - $searchStr .= ' '.$t['tag']; - } - foreach($l['categories'] as $c) { - $searchStr .= ' '.$c['category']; - } + $searchStr .= ' '.implode(' ',$l['tags']); + $searchStr .= ' '.implode(' ',$l['categories']); + $searchStr = trim($searchStr); + $searchStr = strtolower($searchStr); # now update the search string $queryStr = "UPDATE `".DB_PREFIX."_link` @@ -683,7 +683,11 @@ class Management { unset($LinkObj,$l,$searchStr,$t,$c,$queryStr); } + + $ret = true; } + + return $ret; } /** diff --git a/webroot/view/home.inc.php b/webroot/view/home.inc.php index 9ba58d5..a3619a0 100644 --- a/webroot/view/home.inc.php +++ b/webroot/view/home.inc.php @@ -54,6 +54,7 @@ if((isset($_POST['password']) && !empty($_POST['password'])) || (isset($_POST['u # search or new one. if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['submitsearch']) && $honeypotCheck === false) { $searchValue = trim($_POST['data']['searchfield']); + $searchValue = strtolower($searchValue); $isUrl = Summoner::validate($searchValue,'url'); if($isUrl === true) { # search for URL @@ -129,6 +130,7 @@ if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['addnewone']) $search .= ' '.implode(" ",$tagArr); $search .= ' '.implode(" ",$catArr); $search .= trim($search); + $search = strtolower($search); $DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE); diff --git a/webroot/view/stats.inc.php b/webroot/view/stats.inc.php index 271a6b0..c8bfd22 100644 --- a/webroot/view/stats.inc.php +++ b/webroot/view/stats.inc.php @@ -56,6 +56,19 @@ if(isset($_POST['statsCreateDBBackup'])) { exit(); } +if(isset($_POST['statsUpdateSearchIndex'])) { + + if($Management->updateSearchIndex() === true) { + $TemplateData['refresh'] = 'index.php?p=stats'; + } + else { + $submitFeedback['message'] = 'Something went wrong while search index update'; + $submitFeedback['status'] = 'error'; + } +} + + + $linkAmount = $Management->linkAmount(); $tagAmount = $Management->tagAmount(); $categoryAmount = $Management->categoryAmount(); diff --git a/webroot/view/stats.php b/webroot/view/stats.php index 97046df..7b6772b 100644 --- a/webroot/view/stats.php +++ b/webroot/view/stats.php @@ -86,6 +86,13 @@
+ +
+

Search index

+

Update search index

+
+ +