JoomlaPolska / jezyk-J4

Język polski dla Joomla 4
GNU General Public License v2.0
3 stars 5 forks source link

[5.0] Smart Search: Index custom fields #351

Closed joomlapl-bot closed 7 months ago

joomlapl-bot commented 1 year ago

PR w związku ze zmianą oryginału https://github.com/joomla/joomla-cms/pull/38650 Poniżej zmiany w oryginale:

Click to expand the diff! ```diff diff --git a/administrator/components/com_fields/forms/field.xml b/administrator/components/com_fields/forms/field.xml index 98e9d563f01f..ddc79884f7c3 100644 --- a/administrator/components/com_fields/forms/field.xml +++ b/administrator/components/com_fields/forms/field.xml @@ -335,6 +335,20 @@ +
+ + + + + + +
diff --git a/administrator/components/com_fields/src/Model/FieldModel.php b/administrator/components/com_fields/src/Model/FieldModel.php index beacfa288bf1..79a193cb853e 100644 --- a/administrator/components/com_fields/src/Model/FieldModel.php +++ b/administrator/components/com_fields/src/Model/FieldModel.php @@ -115,6 +115,14 @@ public function save($data) $field = $this->getItem($data['id']); } + if ( + (is_null($field) && $data['params']['searchindex'] > 0) + || ($field->params['searchindex'] != $data['params']['searchindex']) + || ($data['params']['searchindex'] > 0 && ($field->state != $data['state'] || $field->access != $data['access'])) + ) { + Factory::getApplication()->enqueueMessage(Text::_('COM_FIELDS_SEARCHINDEX_MIGHT_REQUIRE_REINDEXING'), 'notice'); + } + if (!isset($data['label']) && isset($data['params']['label'])) { $data['label'] = $data['params']['label']; @@ -860,6 +868,31 @@ protected function populateState() $this->setState('params', $params); } + /** + * Method to change the published state of one or more records. + * + * @param array &$pks A list of the primary keys to change. + * @param integer $value The value of the published state. + * + * @return boolean True on success. + * + * @since __DEPLOY_VERSION__ + */ + public function publish(&$pks, $value = 1) + { + foreach ($pks as $pk) { + $item = $this->getItem($pk); + + if ($item->params['searchindex'] > 0) { + Factory::getApplication()->enqueueMessage(Text::_('COM_FIELDS_SEARCHINDEX_MIGHT_REQUIRE_REINDEXING'), 'notice'); + + break; + } + } + + return parent::publish($pks, $value); + } + /** * A protected method to get a set of ordering conditions. * diff --git a/administrator/components/com_fields/tmpl/field/edit.php b/administrator/components/com_fields/tmpl/field/edit.php index 439eb45af151..748011f335d3 100644 --- a/administrator/components/com_fields/tmpl/field/edit.php +++ b/administrator/components/com_fields/tmpl/field/edit.php @@ -80,6 +80,7 @@
+ form->renderField('searchindexing'); ?>
diff --git a/administrator/components/com_finder/src/Indexer/Helper.php b/administrator/components/com_finder/src/Indexer/Helper.php index 2256a006ab13..a8283a688b69 100644 --- a/administrator/components/com_finder/src/Indexer/Helper.php +++ b/administrator/components/com_finder/src/Indexer/Helper.php @@ -16,6 +16,7 @@ use Joomla\CMS\Language\Multilanguage; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Table\Table; +use Joomla\Component\Fields\Administrator\Helper\FieldsHelper; use Joomla\Registry\Registry; use Joomla\String\StringHelper; @@ -30,6 +31,11 @@ */ class Helper { + public const CUSTOMFIELDS_DONT_INDEX = 0; + public const CUSTOMFIELDS_ADD_TO_INDEX = 1; + public const CUSTOMFIELDS_ADD_TO_TAXONOMY = 2; + public const CUSTOMFIELDS_ADD_TO_BOTH = 3; + /** * Method to parse input into plain text. * @@ -385,6 +391,47 @@ public static function getContentExtras(Result $item) return true; } + /** + * Add custom fields for the item to the Result object + * + * @param Result $item Result object to add the custom fields to + * @param string $context Context of the item in the custom fields + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public static function addCustomFields(Result $item, $context) + { + if (!ComponentHelper::getParams(strstr($context, '.', true))->get('custom_fields_enable', 1)) { + return; + } + + $obj = new \stdClass(); + $obj->id = $item->id; + + $fields = FieldsHelper::getFields($context, $obj, true); + + foreach ($fields as $field) { + $searchindex = $field->params->get('searchindex', 0); + + // We want to add this field to the search index + if ($searchindex == self::CUSTOMFIELDS_ADD_TO_INDEX || $searchindex == self::CUSTOMFIELDS_ADD_TO_BOTH) { + $name = 'jsfield_' . $field->name; + $item->$name = $field->value; + $item->addInstruction(Indexer::META_CONTEXT, $name); + } + + // We want to add this field as a taxonomy + if ( + ($searchindex == self::CUSTOMFIELDS_ADD_TO_TAXONOMY || $searchindex == self::CUSTOMFIELDS_ADD_TO_BOTH) + && $field->value + ) { + $item->addTaxonomy($field->title, $field->value, $field->state, $field->access, $field->language); + } + } + } + /** * Method to process content text using the onContentPrepare event trigger. * diff --git a/administrator/language/en-GB/com_fields.ini b/administrator/language/en-GB/com_fields.ini index 3ac2b49794bd..0e8ba00000be 100644 --- a/administrator/language/en-GB/com_fields.ini +++ b/administrator/language/en-GB/com_fields.ini @@ -57,10 +57,16 @@ COM_FIELDS_FIELD_RENDER_CLASS_LABEL="Display Class" COM_FIELDS_FIELD_RENDEROPTIONS_HEADING="Display Options" COM_FIELDS_FIELD_REQUIRED_LABEL="Required" COM_FIELDS_FIELD_SAVE_SUCCESS="Field saved" +COM_FIELDS_FIELD_SEARCHINDEX_BOTH="Make searchable and add as taxonomy" +COM_FIELDS_FIELD_SEARCHINDEX_DONT="Don't make searchable" +COM_FIELDS_FIELD_SEARCHINDEX_LABEL="Search Index" +COM_FIELDS_FIELD_SEARCHINDEX_SEARCHABLE="Make searchable" +COM_FIELDS_FIELD_SEARCHINDEX_TAXONOMY="Add as taxonomy" COM_FIELDS_FIELD_SHOWLABEL_DESC="Show or Hide the label when the field displays." COM_FIELDS_FIELD_SHOWLABEL_LABEL="Label" COM_FIELDS_FIELD_SHOWON_DESC="Conditionally show or hide the field depending on the value of other fields." COM_FIELDS_FIELD_SHOWON_LABEL="Showon Attribute" +COM_FIELDS_FIELD_SMARTSEARCHOPTIONS_HEADING="Smart Search" COM_FIELDS_FIELD_SUFFIX_LABEL="Suffix" COM_FIELDS_FIELD_TYPE_LABEL="Type" COM_FIELDS_FIELD_USE_GLOBAL="Use settings from Plugin" @@ -94,6 +100,7 @@ COM_FIELDS_NO_FIELDS_TO_CREATE_SUBFORM_FIELD_WARNING="You need to create standar COM_FIELDS_ONLY_USE_IN_SUBFORM="- Use in Subform -" COM_FIELDS_ONLY_USE_IN_SUBFORM_ANY="Any Form" COM_FIELDS_ONLY_USE_IN_SUBFORM_SUBFORM="Only in Subform" +COM_FIELDS_SEARCHINDEX_MIGHT_REQUIRE_REINDEXING="Please note, that your changes in the Custom Fields Manager might require you to rebuild the index of Smart Search." COM_FIELDS_SYSTEM_PLUGIN_NOT_ENABLED="The System - Fields plugin is disabled. Custom fields will not display until you enable this plugin." COM_FIELDS_VIEW_FIELD_ADD_TITLE="%s: New Field" COM_FIELDS_VIEW_FIELD_EDIT_TITLE="%s: Edit Field" diff --git a/plugins/finder/contacts/src/Extension/Contacts.php b/plugins/finder/contacts/src/Extension/Contacts.php index 0ee4955acc8c..29315f46cf8f 100644 --- a/plugins/finder/contacts/src/Extension/Contacts.php +++ b/plugins/finder/contacts/src/Extension/Contacts.php @@ -362,6 +362,7 @@ protected function index(Result $item) // Get content extras. Helper::getContentExtras($item); + Helper::addCustomFields($item, 'com_contact.contact'); // Index the item. $this->indexer->index($item); diff --git a/plugins/finder/content/src/Extension/Content.php b/plugins/finder/content/src/Extension/Content.php index b1ca7fd98ce9..9644eb8dbca9 100644 --- a/plugins/finder/content/src/Extension/Content.php +++ b/plugins/finder/content/src/Extension/Content.php @@ -329,6 +329,7 @@ protected function index(Result $item) // Get content extras. Helper::getContentExtras($item); + Helper::addCustomFields($item, 'com_content.article'); // Index the item. $this->indexer->index($item); ```