From: Banana Date: Sun, 28 Jan 2024 11:48:18 +0000 (+0100) Subject: new combined search field. Implemented as a new system field to be added as a new... X-Git-Tag: 1.6~4 X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=471615376377c653326bc58783b5df79d47e27c6;p=bibliotheca-php.git new combined search field. Implemented as a new system field to be added as a new field. Makes search much better --- diff --git a/TODO b/TODO index 9de748f..b4e81b0 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,5 @@ -* change the search data. Maybe an extra search field in which all the searchable information of an entry will be - saved. +* Better error handling and display while adding / update and delete +** Maybe some message "store" * query optimization and default indexes on columns * make documentation markdown to be nicer * change multiple-attachment to a field which tells it is used for a image gallery @@ -12,10 +12,8 @@ * i18n support * Definition of fields in "card view" * User and groupmanagement: Check where a user or group is used! -* Better error handling and display while adding / update and delete * Export of an entry, collection or everything. Stored on disk. * Import of the export * remove ifset and maybe ifsetvalue from summoner - * Field management: Web interface to configure or even create new ones. diff --git a/documentation/setup/bibliotheca.sql b/documentation/setup/bibliotheca.sql index 1d91030..89d6e03 100644 --- a/documentation/setup/bibliotheca.sql +++ b/documentation/setup/bibliotheca.sql @@ -166,7 +166,8 @@ INSERT INTO `#REPLACEME#_sys_fields` (`id`, `identifier`, `displayname`, `type`, (30, 'sysReq', 'System Requirements', 'text3', 'entryText', '`sysReq` varchar(255) NULL DEFAULT NULL, ADD FULLTEXT (`sysReq`)', '', NULL, 'string 255', '2021-04-25 21:21:54', '2021-04-25 21:21:54', 0, 1, 1, 'rw-r--r--'), (31, 'artist', 'Artist', 'text', 'entrySingleText', '`artist` varchar(128) NULL DEFAULT NULL', '', NULL, 'string 128', '2021-07-09 08:30:11', '2021-07-09 08:38:33', NULL, 1, 1, 'rw-r--r--'), (32, 'artists', 'Artists', 'lookupmultiple', 'tag', NULL, 'allowSpace', NULL, 'string 64', '2021-07-18 11:42:16', '2021-07-18 11:42:16', NULL, 1, 1, 'rw-r--r--'), -(34, 'isbn', 'ISBN', 'text', 'entrySingleText', '`isbn` varchar(32) NULL, ADD INDEX (`isbn`)', '', NULL, 'varchar 32', '2022-10-08 10:47:01', '2023-04-08 08:53:55', NULL, 1, 1, 'rw-r--r--'); +(34, 'isbn', 'ISBN', 'text', 'entrySingleText', '`isbn` varchar(32) NULL, ADD INDEX (`isbn`)', '', NULL, 'varchar 32', '2022-10-08 10:47:01', '2023-04-08 08:53:55', NULL, 1, 1, 'rw-r--r--'), +(35, 'combSearch', 'Combined Search', 'hidden', 'entryText', '`combSearch` text NULL DEFAULT NULL, ADD FULLTEXT (`combSearch`)', '', NULL, 'mysql text - Content will be auto generated from other entry fields', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, NULL, '1', '1', 'rw-r--r--'); -- -------------------------------------------------------- @@ -363,7 +364,7 @@ ALTER TABLE `#REPLACEME#_menu` -- AUTO_INCREMENT for table `#REPLACEME#_sys_fields` -- ALTER TABLE `#REPLACEME#_sys_fields` - MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=35; + MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=36; -- -- AUTO_INCREMENT for table `#REPLACEME#_tool` diff --git a/upgrade/from-version-1.5.txt b/upgrade/from-version-1.5.txt index 4c1f716..760da8d 100644 --- a/upgrade/from-version-1.5.txt +++ b/upgrade/from-version-1.5.txt @@ -1,9 +1,14 @@ # Added a new global search field -As of version 1.6, the field 'Combined Search' provides a much better default search base. -If you want to use it make sure you update its contents for all the existing entries in -your collection. After that and for all new entries the data will be created automatically. -The update and creation of the field is done by using the new option "Update combined search field data" -in collection management. It needs to be done for each if your collections but only once. +As of version 1.6, the field 'Combined Search' provides a much better search base. +How to change and use new field: Run the following sql query. Replace #REPLACEME# with the used DB prefix. +``` +INSERT INTO `#REPLACEME#_sys_fields` (`id`, `identifier`, `displayname`, `type`, `searchtype`, `createstring`, `inputValidation`, `value`, `apiinfo`, `created`, `modified`, `modificationuser`, `owner`, `group`, `rights`) VALUES (NULL, 'combSearch', 'Combined Search', 'hidden', 'entryText', '`combSearch` text NULL DEFAULT NULL, ADD FULLTEXT (`combSearch`)', '', NULL, 'mysql text - Content will be auto generated from other entry fields', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, NULL, '1', '1', 'rw-r--r--'); +``` +Add the new field 'Combined Search' to a collection. +Change the 'Default gloabal seach field' to 'Combined search' and save. +After that check the 'Update combined search field data' option to create the search data +for the selected collection. Do this for every collection. +For all new entries the data will be created automatically. # Added new constants to config.php file. Use config.php.default as a help. The new lines are: diff --git a/webclient/lib/managecollectionfields.class.php b/webclient/lib/managecollectionfields.class.php index a3d1916..eaaafff 100644 --- a/webclient/lib/managecollectionfields.class.php +++ b/webclient/lib/managecollectionfields.class.php @@ -314,7 +314,6 @@ class ManageCollectionFields { // add systemfields $def['created'] = array('identifier' => 'created', 'displayname' => 'Created', 'type' => 'systemfield'); $def['modified'] = array('identifier' => 'modified', 'displayname' => 'Modified', 'type' => 'systemfield'); - $def['search'] = array('identifier' => 'search', 'displayname' => 'Combined Search', 'type' => 'systemfield'); return $def + $ret; } diff --git a/webclient/lib/managecollections.class.php b/webclient/lib/managecollections.class.php index ac52dfa..cd1b7ab 100644 --- a/webclient/lib/managecollections.class.php +++ b/webclient/lib/managecollections.class.php @@ -226,9 +226,7 @@ class ManageCollections { `owner` int NOT NULL, `group` int NOT NULL, `rights` char(9) COLLATE utf8mb4_bin NOT NULL, - `search` text COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - FULLTEXT KEY `search` (`search`) + PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"; if(QUERY_DEBUG) Summoner::sysLog("[QUERY] ".__METHOD__." query: ".Summoner::cleanForLog($queryCollectionEntry)); $this->_DB->query($queryCollectionEntry); @@ -340,17 +338,7 @@ class ManageCollections { // optimize does a recreation and the column collation // is considered $this->_DB->query("OPTIMIZE TABLE `".DB_PREFIX."_collection_entry_".$data['id']."`"); - } elseif($data['defaultSearchField'] === "search") { - // Special case. 1.6 adds the search field. Needs to be checked if there - // It is a new default column which is added at creation of a collection - // but needs to be added manually for existing ones. - // could be removed in future version... - $queryStr = "ALTER TABLE `".DB_PREFIX."_collection_entry_".$data['id']."` - ADD `search` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci - NOT NULL AFTER `rights`, ADD FULLTEXT (`search`)"; - if(QUERY_DEBUG) Summoner::sysLog("[QUERY] ".__METHOD__." query: ".Summoner::cleanForLog($queryStr)); - $this->_DB->query($queryStr); - } + } } catch (Exception $e) { if($e->getCode() == "1061") { // duplicate key message if the index is already there. @@ -466,14 +454,22 @@ class ManageCollections { // Name starts with entry. Here we want only the text fields // Those fields are the data for the combined search field $dataFields = array(); + $_fieldAvailable = false; if(!empty($searchFields)) { foreach($searchFields as $k=>$v) { + if($v['identifier'] == "combSearch") { + $_fieldAvailable = true; + continue; + } if(isset($v['searchtype']) && strpos($v['searchtype'],'Text') !== false) { $dataFields[$k] = $v['identifier']; } } } + // only if the combSearch field is available in the collection + if(!$_fieldAvailable) return $ret; + // get the search data for every entry in the collection $entryData = array(); if(!empty($dataFields)) { @@ -500,7 +496,7 @@ class ManageCollections { $searchData = implode(" ", Summoner::words($searchData)); $queryStr = "UPDATE `".DB_PREFIX."_collection_entry_".$collectionId."` - SET `search` = '".$this->_DB->real_escape_string($searchData)."' + SET `combSearch` = '".$this->_DB->real_escape_string($searchData)."' WHERE `id` = '".$entryid."'"; if(QUERY_DEBUG) Summoner::sysLog("[QUERY] ".__METHOD__." query: ".Summoner::cleanForLog($queryStr)); try { diff --git a/webclient/lib/manageentry.class.php b/webclient/lib/manageentry.class.php index 377e8a3..b219fd3 100644 --- a/webclient/lib/manageentry.class.php +++ b/webclient/lib/manageentry.class.php @@ -91,7 +91,7 @@ class Manageentry { if(!empty($this->_collectionId)) { $queryStr = "SELECT `cf`.`fk_field_id` AS id, `sf`.`type`, `sf`.`displayname`, `sf`.`identifier`, - `sf`.`value`, `sf`.`inputValidation` + `sf`.`value`, `sf`.`inputValidation`, `sf`.`searchtype` FROM `".DB_PREFIX."_collection_fields_".$this->_DB->real_escape_string($this->_collectionId)."` AS cf LEFT JOIN `".DB_PREFIX."_sys_fields` AS sf ON `cf`.`fk_field_id` = `sf`.`id` ORDER BY `cf`.`sort`"; @@ -184,7 +184,7 @@ class Manageentry { if(DEBUG) Summoner::sysLog("[DEBUG] ".__METHOD__." methodname: ".Summoner::cleanForLog($_methodName)); if(DEBUG) Summoner::sysLog("[DEBUG] ".__METHOD__." methodnamespecial: ".Summoner::cleanForLog($_methodNameSpecial)); if(method_exists($this, $_methodNameSpecial)) { - $queryData = $this->$_methodNameSpecial($d, $queryData); + $queryData = $this->$_methodNameSpecial($d, $queryData, $data); } elseif(method_exists($this, $_methodName)) { $queryData = $this->$_methodName($d, $queryData); @@ -604,6 +604,40 @@ class Manageentry { return $this->_saveField_text($data, $queryData); } + /** + * Create part of the insert statement for field type hidden + * + * @param array $data + * @param array $queryData + * @return array + */ + private function _saveField_hidden(array $data, array $queryData): array { + return $this->_saveField_text($data, $queryData); + } + + /** + * Create part of the insert statement for field type hidden and identifier combSearch + * Creates it contents of the other fields as a combined search field. Ignores any input + * + * @see ManageCollections->updateSearchData() + * + * @param array $data + * @param array $queryData + * @param array $allInputData All the POST data if needed + * @return array + */ + private function _saveField_hidden__combSearch(array $data, array $queryData, array $allInputData): array { + $searchData = ''; + foreach($allInputData as $f=>$_d) { + if(isset($_d['searchtype']) && strpos($_d['searchtype'],'Text') !== false) { + $searchData .= " ".$_d['valueToSave']; + } + } + $data['valueToSave'] = implode(" ", Summoner::words($searchData)); + $queryData['init'][] = "`".$data['identifier']."` = '".$this->_DB->real_escape_string($data['valueToSave'])."'"; + return $queryData; + } + /** * Create part of the insert statement for field type year * Uses some simple 4 digit patter to extract the year if the input is @@ -756,9 +790,10 @@ class Manageentry { * * @param array $data * @param array $queryData + * @param array $allInputData All the POST data if needed * @return array */ - private function _saveField_upload__coverimage(array $data, array $queryData): array { + private function _saveField_upload__coverimage(array $data, array $queryData, array $allInputData): array { $queryData = $this->_saveField_upload($data, $queryData); if(!isset($queryData['after']['upload'])) { diff --git a/webclient/lib/mancubus.class.php b/webclient/lib/mancubus.class.php index ac29ef6..1d69963 100644 --- a/webclient/lib/mancubus.class.php +++ b/webclient/lib/mancubus.class.php @@ -351,6 +351,8 @@ class Mancubus { /** * Get entries for loaded collection by looking for the given value in given field + * + * @TODO: unused? * * @param string $fieldId Number ID of the field to search in * @param string $fieldValue Value of the field diff --git a/webclient/lib/trite.class.php b/webclient/lib/trite.class.php index 53bcc1d..31d4d24 100644 --- a/webclient/lib/trite.class.php +++ b/webclient/lib/trite.class.php @@ -255,10 +255,7 @@ class Trite { // add systemfields $def['created'] = array('identifier' => 'created', 'displayname' => 'Created', 'type' => 'systemfield'); $def['modified'] = array('identifier' => 'modified', 'displayname' => 'Modified', 'type' => 'systemfield'); - $def['search'] = array('identifier' => 'search', 'displayname' => 'Combined Search', 'type' => 'systemfield'); - $ret = $def + $ret; - - return $ret; + return $def + $ret; } /** diff --git a/webclient/setup/bibliotheca.sql.default b/webclient/setup/bibliotheca.sql.default index 1d91030..89d6e03 100644 --- a/webclient/setup/bibliotheca.sql.default +++ b/webclient/setup/bibliotheca.sql.default @@ -166,7 +166,8 @@ INSERT INTO `#REPLACEME#_sys_fields` (`id`, `identifier`, `displayname`, `type`, (30, 'sysReq', 'System Requirements', 'text3', 'entryText', '`sysReq` varchar(255) NULL DEFAULT NULL, ADD FULLTEXT (`sysReq`)', '', NULL, 'string 255', '2021-04-25 21:21:54', '2021-04-25 21:21:54', 0, 1, 1, 'rw-r--r--'), (31, 'artist', 'Artist', 'text', 'entrySingleText', '`artist` varchar(128) NULL DEFAULT NULL', '', NULL, 'string 128', '2021-07-09 08:30:11', '2021-07-09 08:38:33', NULL, 1, 1, 'rw-r--r--'), (32, 'artists', 'Artists', 'lookupmultiple', 'tag', NULL, 'allowSpace', NULL, 'string 64', '2021-07-18 11:42:16', '2021-07-18 11:42:16', NULL, 1, 1, 'rw-r--r--'), -(34, 'isbn', 'ISBN', 'text', 'entrySingleText', '`isbn` varchar(32) NULL, ADD INDEX (`isbn`)', '', NULL, 'varchar 32', '2022-10-08 10:47:01', '2023-04-08 08:53:55', NULL, 1, 1, 'rw-r--r--'); +(34, 'isbn', 'ISBN', 'text', 'entrySingleText', '`isbn` varchar(32) NULL, ADD INDEX (`isbn`)', '', NULL, 'varchar 32', '2022-10-08 10:47:01', '2023-04-08 08:53:55', NULL, 1, 1, 'rw-r--r--'), +(35, 'combSearch', 'Combined Search', 'hidden', 'entryText', '`combSearch` text NULL DEFAULT NULL, ADD FULLTEXT (`combSearch`)', '', NULL, 'mysql text - Content will be auto generated from other entry fields', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, NULL, '1', '1', 'rw-r--r--'); -- -------------------------------------------------------- @@ -363,7 +364,7 @@ ALTER TABLE `#REPLACEME#_menu` -- AUTO_INCREMENT for table `#REPLACEME#_sys_fields` -- ALTER TABLE `#REPLACEME#_sys_fields` - MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=35; + MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=36; -- -- AUTO_INCREMENT for table `#REPLACEME#_tool` diff --git a/webclient/view/98/advancedsearch/advancedsearch.html b/webclient/view/98/advancedsearch/advancedsearch.html index 1ce7933..5cd6d10 100644 --- a/webclient/view/98/advancedsearch/advancedsearch.html +++ b/webclient/view/98/advancedsearch/advancedsearch.html @@ -62,7 +62,7 @@

Display result for:
- (Max. result of 60) + (Max. result of 60)

diff --git a/webclient/view/98/managecolletions/managecolletions.html b/webclient/view/98/managecolletions/managecolletions.html index e860bd3..8401f5b 100644 --- a/webclient/view/98/managecolletions/managecolletions.html +++ b/webclient/view/98/managecolletions/managecolletions.html @@ -1,7 +1,7 @@

Manage your collections

Add or modify a collection

- Any default field or any option which needs a field get its content after the fields are configured. + Any default field or any option which needs a field, get its values after the fields are configured.
@@ -30,9 +30,19 @@
+
+ + + This could take some time to complete, depending on the amount of data.
+ Plase do this after you remove fields(text) from your collection. +
- + -
- + + Warning: This will delete ALL the data in this collection!
diff --git a/webclient/view/98/manageentry/manageentry.html b/webclient/view/98/manageentry/manageentry.html index b849aa6..fce3eca 100644 --- a/webclient/view/98/manageentry/manageentry.html +++ b/webclient/view/98/manageentry/manageentry.html @@ -51,7 +51,7 @@ Possible duplicate ?>
- + diff --git a/webclient/view/default/entry/field-hidden.html b/webclient/view/default/entry/field-hidden.html new file mode 100644 index 0000000..b9d1232 --- /dev/null +++ b/webclient/view/default/entry/field-hidden.html @@ -0,0 +1 @@ + diff --git a/webclient/view/default/managecolletions/managecolletions.html b/webclient/view/default/managecolletions/managecolletions.html index 38a1c28..a354667 100644 --- a/webclient/view/default/managecolletions/managecolletions.html +++ b/webclient/view/default/managecolletions/managecolletions.html @@ -4,8 +4,8 @@

Add or modify a collection

- Any default field or any option which needs a field - get its content after the fields are configured. + Any default field or any option which needs a field, + get its values after the fields are configured.

@@ -42,13 +42,13 @@ As of version 1.6, the field 'Combined Search' provides a much better default search base.
- If you want to use it make sure you update its contents (following option) for all the existing entries in - your collection. After that and for all new entries the data will be created automatically. + Select the field and save. Use the option below to created or update the search data + for every entry in this collection.
-
Update combined search field data
+
Update Combined Search field data
diff --git a/webclient/view/default/manageentry/field-hidden.html b/webclient/view/default/manageentry/field-hidden.html new file mode 100644 index 0000000..3a79532 --- /dev/null +++ b/webclient/view/default/manageentry/field-hidden.html @@ -0,0 +1,4 @@ +