diff --git a/README.md b/README.md index 865369a9f..60759bcbf 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,10 @@ This module facilitates indexing data from multiple Drupal sites into a single S On each site included in the federated search, you will need to: -1. Install this module -2. Configure a Search API server to connect to the shared Solr index -3. Configure a Search API index according to the [recommended schema](docs/federated_schema.md) +1. Install Fields Search API Module +2. Install this module +3. Configure a Search API server to connect to the shared Solr index +4. Configure a Search API index according to the [recommended schema](docs/federated_schema.md) In order to display results from the Solr index: @@ -26,7 +27,6 @@ When changes to [federated-search-react](https://github.com/palantirnet/federate ## More information -* [How to use this module](docs/usage.md) * [How to configure a Search API Index for federated search](docs/federated_schema.md) * [How to theme the ReactJS search app](docs/theme.md) * [How to add the search form block](docs/block.md) diff --git a/composer.json b/composer.json index 67293120e..29e3a7f62 100644 --- a/composer.json +++ b/composer.json @@ -9,11 +9,16 @@ { "type": "composer", "url": "https://packages.drupal.org/8" + }, + { + "type": "vcs", + "url": "https://github.com/palantirnet/search_api_field_map.git" } ], "require": { "drupal/core": "^8.0", "drupal/search_api_solr": "^1.2", - "drupal/token": "^1.1" + "drupal/token": "^1.1", + "palantirnet/search_api_field_map": "dev-master" } } diff --git a/docs/images/add_federated_field.png b/docs/images/add_federated_field.png deleted file mode 100644 index d5cfd7a26..000000000 Binary files a/docs/images/add_federated_field.png and /dev/null differ diff --git a/docs/images/add_federated_field_save_settings_2.png b/docs/images/add_federated_field_save_settings_2.png deleted file mode 100644 index 5657d49fe..000000000 Binary files a/docs/images/add_federated_field_save_settings_2.png and /dev/null differ diff --git a/docs/images/add_federated_field_settings_save.png b/docs/images/add_federated_field_settings_save.png deleted file mode 100644 index 35c4c5771..000000000 Binary files a/docs/images/add_federated_field_settings_save.png and /dev/null differ diff --git a/docs/images/add_federated_term_field_label.png b/docs/images/add_federated_term_field_label.png deleted file mode 100644 index a3759839b..000000000 Binary files a/docs/images/add_federated_term_field_label.png and /dev/null differ diff --git a/docs/images/add_federated_term_to_term.png b/docs/images/add_federated_term_to_term.png deleted file mode 100644 index f8bd3b2d9..000000000 Binary files a/docs/images/add_federated_term_to_term.png and /dev/null differ diff --git a/docs/images/add_federated_terms.png b/docs/images/add_federated_terms.png deleted file mode 100644 index 22b6e16c1..000000000 Binary files a/docs/images/add_federated_terms.png and /dev/null differ diff --git a/docs/images/add_federated_terms_to_vocabulary.png b/docs/images/add_federated_terms_to_vocabulary.png deleted file mode 100644 index f6a2d744f..000000000 Binary files a/docs/images/add_federated_terms_to_vocabulary.png and /dev/null differ diff --git a/docs/images/confirmation_added_federated_terms.png b/docs/images/confirmation_added_federated_terms.png deleted file mode 100644 index 4c30073b5..000000000 Binary files a/docs/images/confirmation_added_federated_terms.png and /dev/null differ diff --git a/docs/images/edit_federated_field.png b/docs/images/edit_federated_field.png deleted file mode 100644 index 468ab9091..000000000 Binary files a/docs/images/edit_federated_field.png and /dev/null differ diff --git a/docs/images/save_index_field_config.png b/docs/images/save_index_field_config.png deleted file mode 100644 index 5960af80f..000000000 Binary files a/docs/images/save_index_field_config.png and /dev/null differ diff --git a/docs/usage.md b/docs/usage.md deleted file mode 100644 index 98f7e9e9a..000000000 --- a/docs/usage.md +++ /dev/null @@ -1,46 +0,0 @@ -## About this module - -This module provides new field options on Search API indexes: - -1. The "Federated field" field can be used to aggregate data from different entity types into the same field in the search index. - - This is similar to the "Aggregated field" provided by Search API, but gives more direct, token-based control over the values for different entity types. - - See [Using the "Federated field"](#using-the-federated-field). -1. The "Federated terms" field can be used to assign "federated term" values to any taxonomy term entities within a given site. See [Using the "Federated terms" field](#using-the-federated-terms-field). - -## Using the "Federated field" - -1. Visit the fields list for your index at _Admin > Configuration > Search API > [your index] > Fields_ (path `/admin/config/search/search-api/index/YOUR_INDEX/fields`) -2. Click "Add fields" -3. Click the "Add" button for the "Federated Field": - - - -4. Configure field data for each entity type. This field allows token replacement; enter plain text directly or use the token browser to select tokens. - - - -5. Save your field. -6. Edit the field label, machine name, and type as necessary for your data - -## Using the "Federated terms" field - -1. Visit the fields list for your index at _Admin > Configuration > Search API > [your index] > Fields_ (path `/admin/config/search/search-api/index/YOUR_INDEX/fields`) -1. Click "Add fields" -1. Click the "Add" button for the "Federated terms": - -1. Once you have added the "Federated terms" field to your search index configuration, you can read through the provided instructions and save the field: - -1. Remember to save the index field configuration: - -1. Configuration for federated terms happens within the taxonomy term entity edit UI itself. Browse to a taxonomy vocabulary on your site and add an instance of the "Federated terms" field type (If you plan on sharing this field among your vocabularies, use something like "Federated terms" for the field label). - - -1. Save the field settings - - -1. Edit any terms in the vocabularies to which you've just added a "Federated terms" field instance. On the term edit form, you should now see a "Federated terms" field instance where you can add one or many "federated" terms. - -1. Repeat for each term in each vocabulary which should have a federated term value. -1. Once content which references these terms is indexed, all of their corresponding "federated terms" will appear in the `federated_terms` index property field. diff --git a/search_api_federated_solr.info.yml b/search_api_federated_solr.info.yml index 717aaa1ab..0599f238f 100644 --- a/search_api_federated_solr.info.yml +++ b/search_api_federated_solr.info.yml @@ -4,6 +4,7 @@ description: Allows indexing multiple Drupal sites into a single Solr search ind core: 8.x package: Search dependencies: + - search_api_field_map - search_api_solr - token - field diff --git a/search_api_federated_solr.module b/search_api_federated_solr.module index 54f7162c1..d5a4d69fc 100644 --- a/search_api_federated_solr.module +++ b/search_api_federated_solr.module @@ -88,10 +88,10 @@ function search_api_federated_solr_search_api_solr_field_mapping_alter(\Drupal\s $fields[$key] = $singleFieldsMap[$key]; } - // Map all "federated_field" property fields to their single value in solr. + // Map all "mapped_field" property fields to their single value in solr. $field = $index->getField($key); - if (method_exists($field,'getPropertyPath') && 'federated_field' == $field->getPropertyPath()) { - $fields[$key] = str_replace("m_federated_","s_federated_", $fields[$key]); + if (method_exists($field,'getPropertyPath') && 'mapped_field' == $field->getPropertyPath()) { + $fields[$key] = preg_replace("/^(\w)m_/","$1s_", $fields[$key], 1); } }; } diff --git a/src/Plugin/search_api/processor/FederatedFields.php b/src/Plugin/search_api/processor/FederatedFields.php deleted file mode 100644 index 2cd511a8c..000000000 --- a/src/Plugin/search_api/processor/FederatedFields.php +++ /dev/null @@ -1,84 +0,0 @@ - $this->t('Federated field'), - 'description' => $this->t('Normalize multiple content types into a single federated field.'), - 'type' => 'string', - 'processor_id' => $this->getPluginId(), - ]; - $properties['federated_field'] = new FederatedFieldProperty($definition); - } - - return $properties; - } - - /** - * {@inheritdoc} - */ - public function addFieldValues(ItemInterface $item) { - // Get all of the federated fields on our item. - $federated_fields = $this->getFieldsHelper() - ->filterForPropertyPath($item->getFields(), NULL, 'federated_field'); - - // Get the entity object, bail if there's somehow not one. - $entity = $item->getOriginalObject()->getValue(); - if (!$entity) { - // Apparently we were active for a wrong item. - return; - } - - // Set some helper vars for the entity and bundle type. - $entity_type = $entity->getEntityTypeId(); - $bundle_type = $entity->bundle(); - - // Process and set values for each federated field on the item. - foreach ($federated_fields as $federated_field) { - - // Get configuration for the field. - $configuration = $federated_field->getConfiguration(); - - // If there's a config item for the entity and bundle type we're in, set the value for the field. - if(!empty($configuration['field_data'][$entity_type][$bundle_type])) { - $token = \Drupal::token(); - // If the token replacement produces a value, add to this item. - if ($value = $token->replace($configuration['field_data'][$entity_type][$bundle_type], [$entity_type => $entity], ['clear' => true])) { - // Do not use setValues(), since that doesn't preprocess the values according to their data type. - $federated_field->addValue($value); - } - - } - } - } -} diff --git a/src/Plugin/search_api/processor/Property/FederatedFieldProperty.php b/src/Plugin/search_api/processor/Property/FederatedFieldProperty.php deleted file mode 100644 index 192402671..000000000 --- a/src/Plugin/search_api/processor/Property/FederatedFieldProperty.php +++ /dev/null @@ -1,98 +0,0 @@ - 'union', - 'fields' => [], - ]; - } - - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(FieldInterface $field, array $form, FormStateInterface $form_state) { - $index = $field->getIndex(); - $configuration = $field->getConfiguration(); - - $form['#attached']['library'][] = 'search_api/drupal.search_api.admin_css'; - $form['#tree'] = TRUE; - - $form['field_data'] = [ - '#type' => 'item', - '#title' => $this->t('Federated data'), - '#description' => $this->t('Set the data to be sent to the index for each bundle in the data sources set in your index configuration. Use static values or choose tokens using the picker below.'), - ]; - - foreach ($index->getDatasources() as $datasource_id => $datasource) { - $bundles = $datasource->getBundles(); - $entity_type = $datasource->getEntityTypeId(); - - // Make an array of all the entity types we're working with to pass to token_help. - $entity_types[] = $entity_type; - - foreach ($bundles as $bundle_id => $bundle_label) { - - // Create a config field for each bundle in our enabled datasources. - $form['field_data'][$entity_type][$bundle_id] = [ - '#type' => 'textfield', - '#title' => $this->t('Field data for %datasource ยป %bundle', ['%datasource' => $datasource->label(), '%bundle' => $bundle_label]), - '#element_validate' => array('token_element_validate'), - '#token_types' => array($entity_type), - ]; - - // Set the default value if something already exists in our config. - if (isset($configuration['field_data'][$entity_type][$bundle_id])) { - $form['field_data'][$entity_type][$bundle_id]['#default_value'] = $configuration['field_data'][$entity_type][$bundle_id]; - } - } - } - - // Build the token picker. - $form['token_help'] = [ - '#theme' => 'token_tree_link', - '#token_types' => $entity_types, - ]; - - return $form; - } - - /** - * {@inheritdoc} - */ - public function submitConfigurationForm(FieldInterface $field, array &$form, FormStateInterface $form_state) { - $values = [ - 'field_data' => array_filter($form_state->getValue('field_data')), - ]; - - $field->setConfiguration($values); - } - - - -} diff --git a/src/Plugin/search_api/processor/Property/SiteNameProperty.php b/src/Plugin/search_api/processor/Property/SiteNameProperty.php deleted file mode 100644 index 6383abc6a..000000000 --- a/src/Plugin/search_api/processor/Property/SiteNameProperty.php +++ /dev/null @@ -1,58 +0,0 @@ - \Drupal::config('system.site')->get('name'), - ]; - } - - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(FieldInterface $field, array $form, FormStateInterface $form_state) { - $configuration = $field->getConfiguration(); - - $form['#attached']['library'][] = 'search_api/drupal.search_api.admin_css'; - $form['#tree'] = TRUE; - - $form['site_name'] = [ - '#type' => 'textfield', - '#title' => $this->t('Site Name'), - '#description' => $this->t('The name of the site from which this content originated. This can be useful if indexing multiple sites with a single search index.'), - '#default_value' => $configuration['site_name'], - '#required' => TRUE, - ]; - - return $form; - } - - /** - * {@inheritdoc} - */ - public function submitConfigurationForm(FieldInterface $field, array &$form, FormStateInterface $form_state) { - $values = [ - 'site_name' => $form_state->getValue('site_name'), - ]; - $field->setConfiguration($values); - } - -} diff --git a/src/Plugin/search_api/processor/SiteName.php b/src/Plugin/search_api/processor/SiteName.php deleted file mode 100644 index 0fe9b1fb6..000000000 --- a/src/Plugin/search_api/processor/SiteName.php +++ /dev/null @@ -1,59 +0,0 @@ - $this->t('Site Name'), - 'description' => $this->t('The name of the site from which this content originated.'), - 'type' => 'string', - 'processor_id' => $this->getPluginId(), - ]; - $properties['site_name'] = new SiteNameProperty($definition); - } - - return $properties; - } - - /** - * {@inheritdoc} - */ - public function addFieldValues(ItemInterface $item) { - $fields = $this->getFieldsHelper() - ->filterForPropertyPath($item->getFields(), NULL, 'site_name'); - foreach ($fields as $field) { - $site_name = $field->getConfiguration()['site_name']; - $field->addValue($site_name); - } - } - -} diff --git a/src/Plugin/search_api/processor/SiteNameLink.php b/src/Plugin/search_api/processor/SiteNameLink.php deleted file mode 100644 index d067500b1..000000000 --- a/src/Plugin/search_api/processor/SiteNameLink.php +++ /dev/null @@ -1,61 +0,0 @@ - 'item', - '#description' => $this->t('This processor provides no configuration options.'), - ]; - - return $form; - } - - /** - * {@inheritdoc} - */ - public function postprocessSearchResults(ResultSetInterface $results) { - $query = $results->getQuery(); - if (!$results->getResultCount()) { - return; - } - - $result_items = $results->getResultItems(); - foreach ($result_items as $key => $item) { - $site = $item->getExtraData('search_api_solr_document')['site']; - $url = Url::fromUri($site); - $name = $item->getField('site_name')->getValues()[0]; - $link = Link::fromTextAndUrl(t($name), $url)->toString(); - $item->getField('site_name')->setValues([$link]); - } - } - -}