diff --git a/sites/all/modules/figli/edlp_search/src/Controller/EdlpSearchController.php b/sites/all/modules/figli/edlp_search/src/Controller/EdlpSearchController.php index c719d4eea..0583df282 100644 --- a/sites/all/modules/figli/edlp_search/src/Controller/EdlpSearchController.php +++ b/sites/all/modules/figli/edlp_search/src/Controller/EdlpSearchController.php @@ -93,6 +93,8 @@ class EdlpSearchController extends ControllerBase { $response = new JsonResponse($this->matches); return $response; + // dpm($this->matches, 'matches'); + // // return array( // "#markup" => "autocomplete" // ); @@ -132,32 +134,45 @@ class EdlpSearchController extends ControllerBase { $query->keys($this->keys); } - // select the field in which search will be performed - $query->setFulltextFields(array($this->field_name)); + + if(null !== $this->field_synonyms){ + // select the taxo field AND the synonym field in which search will be performed + $query->setFulltextFields(array($this->field_name, $this->field_synonyms)); + }else{ + // OR select the unique taxo field in which search will be performed + $query->setFulltextFields(array($this->field_name)); + } $result = $query->execute(); $items = $result->getResultItems(); $this->matches = []; foreach ($items as $item) { + // get the field from item try { /** @var \Drupal\Core\Entity\EntityInterface $entity */ $fields = $item->getField($this->field_name)->getValues(); }catch (SearchApiException $e) { + // if error on getinfg the field, skip item continue; } + // if no fields returned, skip item if (!$fields) { continue; } + // get field content $field_text = $fields[0]->getText(); + // if content already in matches, skip item if( in_array($field_text, $this->matches) ){ continue; } + // add the item to the return list $this->matches[] = $field_text; + // do not return more than 14 items if(count($this->matches) > 14){ break; } @@ -169,8 +184,12 @@ class EdlpSearchController extends ControllerBase { * getRequestArgs */ private function getRequestAutocompleteArgs(){ + // args are provided by form definition with autocomplete_route_parameters // dpm($this->request); $this->field_name = $this->request->query->get('field_name'); + // if($this->request->query->get('field_synonyms')){ + $this->field_synonyms = $this->request->query->get('field_synonyms'); + // } $this->keys = $this->request->query->get('q'); } diff --git a/sites/all/modules/figli/edlp_search/src/Form/EdlpSearchForm.php b/sites/all/modules/figli/edlp_search/src/Form/EdlpSearchForm.php index d4ded32f6..7efc94d09 100644 --- a/sites/all/modules/figli/edlp_search/src/Form/EdlpSearchForm.php +++ b/sites/all/modules/figli/edlp_search/src/Form/EdlpSearchForm.php @@ -54,7 +54,7 @@ class EdlpSearchForm extends FormBase { 'genres' => [ '#type' => 'textfield', '#autocomplete_route_name' => 'edlp_search.edlp_search_controller_autocomplete', - '#autocomplete_route_parameters' => array('field_name' => 'field_genres'), + '#autocomplete_route_parameters' => array('field_name' => 'field_genres', 'field_synonyms' => 'field_synonyms'), '#maxlength' => 20, '#size' => 15, '#weight' => '0', diff --git a/sites/default/config/sync/search_api.index.collection.yml b/sites/default/config/sync/search_api.index.collection.yml index ea6a42754..bcf1eb978 100644 --- a/sites/default/config/sync/search_api.index.collection.yml +++ b/sites/default/config/sync/search_api.index.collection.yml @@ -12,6 +12,7 @@ dependencies: - field.storage.node.field_workflow - field.storage.node.field_genres - field.storage.node.field_langues + - field.storage.taxonomy_term.field_synonyms - search_api.server.edlp_db module: - taxonomy @@ -138,6 +139,17 @@ field_settings: - field.storage.node.field_langues module: - taxonomy + field_synonyms: + label: 'Genre(s) » Taxonomy term » Synonyms' + datasource_id: 'entity:node' + property_path: 'field_genres:entity:field_synonyms' + type: text + dependencies: + config: + - field.storage.node.field_genres + - field.storage.taxonomy_term.field_synonyms + module: + - taxonomy datasource_settings: 'entity:node': bundles: @@ -161,6 +173,7 @@ processor_settings: - name - field_genres - field_langues + - field_synonyms spaces: '' overlap_cjk: 1 minimum_word_size: '3' @@ -200,6 +213,7 @@ processor_settings: - name - field_genres - field_langues + - field_synonyms stopwords: - a - an @@ -251,6 +265,7 @@ processor_settings: - field_workflow - field_genres - field_langues + - field_synonyms weights: preprocess_index: -20 preprocess_query: -20 @@ -266,6 +281,7 @@ processor_settings: - field_workflow - field_genres - field_langues + - field_synonyms weights: preprocess_index: -20 preprocess_query: -20 diff --git a/sites/default/config/sync/views.view.content.yml b/sites/default/config/sync/views.view.content.yml index 70f14c2ec..ddab7e123 100644 --- a/sites/default/config/sync/views.view.content.yml +++ b/sites/default/config/sync/views.view.content.yml @@ -28,6 +28,8 @@ dependencies: - node.type.page - node.type.static - taxonomy.vocabulary.entrees + - taxonomy.vocabulary.genres + - taxonomy.vocabulary.langues - taxonomy.vocabulary.page_type - user.role.admin - user.role.collectionneur @@ -2172,6 +2174,104 @@ display: entity_type: node entity_field: langcode plugin_id: language + field_genres_target_id: + id: field_genres_target_id + table: node__field_genres + field: field_genres_target_id + relationship: none + group_type: group + admin_label: '' + operator: or + value: { } + group: 1 + exposed: true + expose: + operator_id: field_genres_target_id_op + label: 'Genre(s) (field_genres)' + description: '' + use_operator: false + operator: field_genres_target_id_op + identifier: field_genres_target_id + required: false + remember: false + multiple: false + remember_roles: + authenticated: authenticated + anonymous: '0' + collectionneur: '0' + admin: '0' + root: '0' + invite: '0' + user: '0' + reduce: false + is_grouped: false + group_info: + label: '' + description: '' + identifier: '' + optional: true + widget: select + multiple: false + remember: false + default_group: All + default_group_multiple: { } + group_items: { } + reduce_duplicates: false + type: textfield + limit: true + vid: genres + hierarchy: false + error_message: true + plugin_id: taxonomy_index_tid + field_langues_target_id: + id: field_langues_target_id + table: node__field_langues + field: field_langues_target_id + relationship: none + group_type: group + admin_label: '' + operator: or + value: { } + group: 1 + exposed: true + expose: + operator_id: field_langues_target_id_op + label: 'Langue(s) (field_langues)' + description: '' + use_operator: false + operator: field_langues_target_id_op + identifier: field_langues_target_id + required: false + remember: false + multiple: false + remember_roles: + authenticated: authenticated + anonymous: '0' + collectionneur: '0' + admin: '0' + root: '0' + invite: '0' + user: '0' + reduce: false + is_grouped: false + group_info: + label: '' + description: '' + identifier: '' + optional: true + widget: select + multiple: false + remember: false + default_group: All + default_group_multiple: { } + group_items: { } + reduce_duplicates: false + type: textfield + limit: true + vid: langues + hierarchy: false + error_message: true + plugin_id: taxonomy_index_tid defaults: filters: false filter_groups: false diff --git a/sites/default/config/sync/views.view.entree_s_.yml b/sites/default/config/sync/views.view.entree_s_.yml index a772d224c..65801c52c 100644 --- a/sites/default/config/sync/views.view.entree_s_.yml +++ b/sites/default/config/sync/views.view.entree_s_.yml @@ -867,10 +867,12 @@ display: defaults: filters: false filter_groups: false + title: false filter_groups: operator: AND groups: 1: AND + title: Entrees cache_metadata: max-age: -1 contexts: @@ -1069,6 +1071,7 @@ display: fields: false filters: false filter_groups: false + title: false filters: vid: id: vid @@ -1243,6 +1246,7 @@ display: operator: AND groups: 1: AND + title: Genres cache_metadata: max-age: -1 contexts: