From 7246675e32760cb86738b716501243859e1f986c Mon Sep 17 00:00:00 2001 From: Bachir Soussi Chiadmi Date: Tue, 10 Dec 2019 16:27:19 +0100 Subject: [PATCH] search from english, fix #467 --- config/sync/search_api.index.collection.yml | 258 ++++++++++-------- .../assets/dist/scripts/corpus.min.js | 2 +- .../edlp_corpus/assets/scripts/corpus.js | 4 +- .../src/Controller/EdlpSearchController.php | 25 +- 4 files changed, 162 insertions(+), 127 deletions(-) diff --git a/config/sync/search_api.index.collection.yml b/config/sync/search_api.index.collection.yml index 1e776db17..38cc72412 100644 --- a/config/sync/search_api.index.collection.yml +++ b/config/sync/search_api.index.collection.yml @@ -5,31 +5,24 @@ dependencies: config: - field.storage.node.body - field.storage.node.field_description + - field.storage.node.field_entrees + - field.storage.node.field_genres + - field.storage.taxonomy_term.field_synonyms + - field.storage.node.field_langues + - field.storage.node.field_locuteurs - field.storage.node.field_transcript_trad - field.storage.node.field_transcript_vo - - field.storage.node.field_entrees - - field.storage.node.field_locuteurs - 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 - - search_api - node + - search_api id: collection name: Collection description: '' read_only: false field_settings: - node_grants: - label: 'Node access information' - property_path: search_api_node_grants - type: string - indexed_locked: true - type_locked: true - hidden: true body: label: Article datasource_id: 'entity:node' @@ -38,12 +31,6 @@ field_settings: dependencies: config: - field.storage.node.body - title: - label: Title - datasource_id: 'entity:node' - property_path: title - type: text - boost: !!float 3 field_description: label: Description datasource_id: 'entity:node' @@ -53,6 +40,55 @@ field_settings: dependencies: config: - field.storage.node.field_description + field_entrees: + label: Entrée(s) + datasource_id: 'entity:node' + property_path: field_entrees + type: integer + dependencies: + config: + - field.storage.node.field_entrees + field_genres: + label: 'Genre(s) » Taxonomy term » Name' + datasource_id: 'entity:node' + property_path: 'field_genres:entity:name' + type: text + dependencies: + config: + - field.storage.node.field_genres + module: + - taxonomy + - taxonomy + field_langues: + label: 'Langue(s) » Taxonomy term » Name' + datasource_id: 'entity:node' + property_path: 'field_langues:entity:name' + type: text + dependencies: + config: + - field.storage.node.field_langues + module: + - taxonomy + - taxonomy + field_locuteurs: + label: Locuteur(s) + datasource_id: 'entity:node' + property_path: field_locuteurs + type: integer + dependencies: + config: + - field.storage.node.field_locuteurs + 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 field_transcript_trad: label: 'Transcription (Traduction)' datasource_id: 'entity:node' @@ -71,20 +107,26 @@ field_settings: dependencies: config: - field.storage.node.field_transcript_vo - status: - label: status + field_workflow: + label: Workflow datasource_id: 'entity:node' - property_path: status - type: boolean - indexed_locked: true - type_locked: true - uid: - label: uid + property_path: field_workflow + type: string + dependencies: + config: + - field.storage.node.field_workflow + langcode: + label: Langue datasource_id: 'entity:node' - property_path: uid - type: integer - indexed_locked: true - type_locked: true + property_path: langcode + type: string + dependencies: + module: + - node + language_with_fallback: + label: 'Language (with fallback)' + property_path: language_with_fallback + type: string name: label: 'Entrée(s) » Taxonomy term » Name' datasource_id: 'entity:node' @@ -95,61 +137,43 @@ field_settings: - field.storage.node.field_entrees module: - taxonomy - field_entrees: - label: Entrée(s) - datasource_id: 'entity:node' - property_path: field_entrees - type: integer - dependencies: - config: - - field.storage.node.field_entrees - field_locuteurs: - label: Locuteur(s) - datasource_id: 'entity:node' - property_path: field_locuteurs - type: integer - dependencies: - config: - - field.storage.node.field_locuteurs - field_workflow: - label: Workflow - datasource_id: 'entity:node' - property_path: field_workflow + - taxonomy + node_grants: + label: 'Node access information' + property_path: search_api_node_grants type: string - dependencies: - config: - - field.storage.node.field_workflow - field_genres: - label: 'Genre(s) » Taxonomy term » Name' + indexed_locked: true + type_locked: true + hidden: true + status: + label: status datasource_id: 'entity:node' - property_path: 'field_genres:entity:name' - type: text + property_path: status + type: boolean + indexed_locked: true + type_locked: true dependencies: - config: - - field.storage.node.field_genres module: - - taxonomy - field_langues: - label: 'Langue(s) » Taxonomy term » Name' + - node + title: + label: Title datasource_id: 'entity:node' - property_path: 'field_langues:entity:name' + property_path: title type: text + boost: !!float 3 dependencies: - config: - - field.storage.node.field_langues module: - - taxonomy - field_synonyms: - label: 'Genre(s) » Taxonomy term » Synonyms' + - node + uid: + label: uid datasource_id: 'entity:node' - property_path: 'field_genres:entity:field_synonyms' - type: text + property_path: uid + type: integer + indexed_locked: true + type_locked: true dependencies: - config: - - field.storage.node.field_genres - - field.storage.taxonomy_term.field_synonyms module: - - taxonomy + - node datasource_settings: 'entity:node': bundles: @@ -157,31 +181,17 @@ datasource_settings: selected: - enregistrement languages: - default: true - selected: { } + default: false + selected: + - en + - fr processor_settings: - entity_status: { } - rendered_item: { } - tokenizer: - all_fields: true - fields: - - body - - title - - field_description - - field_transcript_trad - - field_transcript_vo - - name - - field_genres - - field_langues - - field_synonyms - spaces: '' - overlap_cjk: 1 - minimum_word_size: '3' - weights: - preprocess_index: -6 - preprocess_query: -6 - aggregated_field: { } add_url: { } + aggregated_field: { } + content_access: + weights: + preprocess_query: -30 + entity_status: { } html_filter: all_fields: false fields: @@ -192,11 +202,11 @@ processor_settings: title: true alt: true tags: + b: 2 h1: 5 h2: 3 h3: 2 strong: 2 - b: 2 weights: preprocess_index: -15 preprocess_query: -15 @@ -204,40 +214,62 @@ processor_settings: all_fields: true fields: - body - - title - field_description - - field_transcript_trad - - field_transcript_vo - - name - - field_workflow - field_genres - field_langues - field_synonyms + - field_transcript_trad + - field_transcript_vo + - field_workflow + - langcode + - language_with_fallback + - name + - title weights: preprocess_index: -20 preprocess_query: -20 + language_with_fallback: { } + rendered_item: { } + reverse_entity_references: { } + tokenizer: + all_fields: true + fields: + - body + - field_description + - field_genres + - field_langues + - field_synonyms + - field_transcript_trad + - field_transcript_vo + - name + - title + spaces: '' + overlap_cjk: 1 + minimum_word_size: '3' + weights: + preprocess_index: -6 + preprocess_query: -6 transliteration: all_fields: true fields: - body - - title - field_description - - field_transcript_trad - - field_transcript_vo - - name - - field_workflow - field_genres - field_langues - field_synonyms + - field_transcript_trad + - field_transcript_vo + - field_workflow + - langcode + - language_with_fallback + - name + - title weights: preprocess_index: -20 preprocess_query: -20 - content_access: - weights: - preprocess_query: -30 tracker_settings: default: - indexing_order: fifo + indexing_order: lifo options: index_directly: true cron_limit: 50 diff --git a/web/modules/custom/edlp_corpus/assets/dist/scripts/corpus.min.js b/web/modules/custom/edlp_corpus/assets/dist/scripts/corpus.min.js index 075e9ade2..a00a4c1a2 100644 --- a/web/modules/custom/edlp_corpus/assets/dist/scripts/corpus.min.js +++ b/web/modules/custom/edlp_corpus/assets/dist/scripts/corpus.min.js @@ -1,5 +1,5 @@ -(function($,Drupal,drupalSettings){EdlpCorpus=function(){var _activated=true;var _$body=$('body');var _$container=_$body;var _$canvas=$('').appendTo(_$container);var _canvas=_$canvas[0];var _ctx=_canvas.getContext('2d');var _dpi=window.devicePixelRatio;var _scene_props={width:window.innerWidth,height:window.innerHeight,'margin_top':75,'margin_right':0,'margin_bottom':65,'margin_left':0};var _evolution_zone={left:_scene_props.width/4,right:_scene_props.width-_scene_props.width/4,center:_scene_props.width/2,};var _physics=new Physics();var _nodes=[];var _articles_nodes=[];var _no_articles_nodes=[];var _nodes_by_entries={};var _nodes_by_nid={};var _nodes_Nid_Id={};var _nodes_centered=[];var _nodes_centered_attractions=[];var _loaded=false;var _playlist=[];var _p_velocity_factor=0.5;var _mouse_in=true;var _m_pos={x:0,y:0};var _node_hover_id=-1;var _node_opened_id=-1;var _$entrees_block=$('#block-edlpentreesblock');var _$entrees_block_termlinks=$('a.term-link',_$entrees_block);var _$articles_link;var _node_pop_up;var _settings=drupalSettings.edlp_corpus;var _ecolors=_settings.colors;var _attracter;var check_parts_colid_frq=2;var check_parts_colid_tick=1;function init(){initCanvas();if(_activated){loadCorpus();}else{_$canvas.addClass('de-activated');}};function initCanvas(){window.addEventListener('resize',onResizeCanvas,false);onResizeCanvas();};function onResizeCanvas(){_scene_props.width=window.innerWidth;_scene_props.height=window.innerHeight;_canvas.style.width=_scene_props.width+'px';_canvas.style.height=_scene_props.height+'px';_canvas.width=_scene_props.width*_dpi;_canvas.height=_scene_props.height*_dpi;_ctx.scale(_dpi,_dpi);moveEvolutionZone();if(_loaded){for(var i=0;i<_nodes.length;i++){_nodes[i].onResizeCanvas();}}};function loadCorpus(){var ajax_path=_settings.load_corpus_ajax_url;var path=window.location.origin+Drupal.url(ajax_path);$.getJSON(path,{}).done(function(data){onCorpusLoaded(data);}).fail(function(jqxhr,textStatus,error){onCorpusLoadError(jqxhr,textStatus,error);});};function onCorpusLoadError(jqxhr,textStatus,error){void 0;};function onCorpusLoaded(data){void 0;initPhysics();buildNodes(data.nodes);initArtilesLink();initNodePopup();initEvents();checkPreOpenedEntry();startAnime();_loaded=true;};function initPhysics(){_attracter=_physics.makeParticle(1000);_attracter.fixed=true;resizePhysics();};function resizePhysics(){if(typeof _attracter!='undefined'){_attracter.position={x:_evolution_zone.center,y:_scene_props.height/2};}};function buildNodes(nodes){var d;for(var i in nodes){d=i<1?true:false;new Node(i,nodes[i],d);_playlist.push({'id':i,'nid':nodes[i].nid,'audio_url':nodes[i].audio_url,'document_url':nodes[i].document_url,});}};function Node(i,node,d){this.id=i;for(key in node) +(function($,Drupal,drupalSettings){EdlpCorpus=function(){var _activated=false;var _$body=$('body');var _$container=_$body;var _$canvas=$('').appendTo(_$container);var _canvas=_$canvas[0];var _ctx=_canvas.getContext('2d');var _dpi=window.devicePixelRatio;var _scene_props={width:window.innerWidth,height:window.innerHeight,'margin_top':75,'margin_right':0,'margin_bottom':65,'margin_left':0};var _evolution_zone={left:_scene_props.width/4,right:_scene_props.width-_scene_props.width/4,center:_scene_props.width/2,};var _physics=new Physics();var _nodes=[];var _articles_nodes=[];var _no_articles_nodes=[];var _nodes_by_entries={};var _nodes_by_nid={};var _nodes_Nid_Id={};var _nodes_centered=[];var _nodes_centered_attractions=[];var _loaded=false;var _playlist=[];var _p_velocity_factor=0.5;var _mouse_in=true;var _m_pos={x:0,y:0};var _node_hover_id=-1;var _node_opened_id=-1;var _$entrees_block=$('#block-edlpentreesblock');var _$entrees_block_termlinks=$('a.term-link',_$entrees_block);var _$articles_link;var _node_pop_up;var _settings=drupalSettings.edlp_corpus;var _ecolors=_settings.colors;var _attracter;var check_parts_colid_frq=2;var check_parts_colid_tick=1;function init(){initCanvas();if(_activated){loadCorpus();}else{_$canvas.addClass('de-activated');}};function initCanvas(){window.addEventListener('resize',onResizeCanvas,false);onResizeCanvas();};function onResizeCanvas(){_scene_props.width=window.innerWidth;_scene_props.height=window.innerHeight;_canvas.style.width=_scene_props.width+'px';_canvas.style.height=_scene_props.height+'px';_canvas.width=_scene_props.width*_dpi;_canvas.height=_scene_props.height*_dpi;_ctx.scale(_dpi,_dpi);moveEvolutionZone();if(_loaded){for(var i=0;i<_nodes.length;i++){_nodes[i].onResizeCanvas();}}};function loadCorpus(){var ajax_path=_settings.load_corpus_ajax_url;var path=window.location.origin+Drupal.url(ajax_path);$.getJSON(path,{}).done(function(data){onCorpusLoaded(data);}).fail(function(jqxhr,textStatus,error){onCorpusLoadError(jqxhr,textStatus,error);});};function onCorpusLoadError(jqxhr,textStatus,error){void 0;};function onCorpusLoaded(data){void 0;initPhysics();buildNodes(data.nodes);initArtilesLink();initNodePopup();initEvents();checkPreOpenedEntry();startAnime();_loaded=true;};function initPhysics(){_attracter=_physics.makeParticle(1000);_attracter.fixed=true;resizePhysics();};function resizePhysics(){if(typeof _attracter!='undefined'){_attracter.position={x:_evolution_zone.center,y:_scene_props.height/2};}};function buildNodes(nodes){var d;for(var i in nodes){d=i<1?true:false;new Node(i,nodes[i],d);_playlist.push({'id':i,'nid':nodes[i].nid,'audio_url':nodes[i].audio_url,'document_url':nodes[i].document_url,});}};function Node(i,node,d){this.id=i;for(key in node) this[key]=node[key];_nodes.push(this);_nodes_by_nid[this.nid]=this;_nodes_Nid_Id[this.nid]=this.id;if(this.has_article==1){_articles_nodes.push(this);}else{_no_articles_nodes.push(this);} for(var j=0;j').appendTo(_$container); @@ -759,7 +759,7 @@ console.log("_scene_props", _scene_props); _evolution_zone.left = left == 0 - ? left+20 + ? left+20 : Math.max(_scene_props.width/5, left+20); _evolution_zone.right = right == 0 diff --git a/web/modules/custom/edlp_search/src/Controller/EdlpSearchController.php b/web/modules/custom/edlp_search/src/Controller/EdlpSearchController.php index 0d6476572..23ae899ce 100644 --- a/web/modules/custom/edlp_search/src/Controller/EdlpSearchController.php +++ b/web/modules/custom/edlp_search/src/Controller/EdlpSearchController.php @@ -150,10 +150,14 @@ class EdlpSearchController extends ControllerBase { $query->addConditionGroup($wf_condition_group); // Search for keys. - if (!empty($this->keys)) { + if (!empty($this->keys)) { // && strlen($this->keys) > 2 // dpm($this->keys); $query->keys($this->keys); } + // else{ + // $this->matches = []; + // return; + // } if(null !== $this->field_synonyms){ @@ -167,6 +171,7 @@ class EdlpSearchController extends ControllerBase { $result = $query->execute(); $items = $result->getResultItems(); // dpm($items); + $this->matches = []; foreach ($items as $item) { // get the field from item @@ -185,6 +190,7 @@ class EdlpSearchController extends ControllerBase { // dpm($fields); // get field content $field_text = $fields[0]->getText(); + // $entity_id = $fields[0]->get('tid'); // if content already in matches, skip item if( in_array($field_text, $this->matches) ){ @@ -192,6 +198,7 @@ class EdlpSearchController extends ControllerBase { } // add the item to the return list + // $matches_names = $field_text . '('.$entity_id.')'; $this->matches[] = $field_text; // do not return more than 14 items @@ -250,7 +257,6 @@ class EdlpSearchController extends ControllerBase { $response = new JsonResponse(); $response->setData([ - 'test'=>'search results', 'keys'=>$this->keys, 'entries' => $this->entries, 'entry_names' => $this->entry_names, @@ -308,8 +314,12 @@ class EdlpSearchController extends ControllerBase { $parse_mode = \Drupal::getContainer() ->get('plugin.manager.search_api.parse_mode') ->createInstance('direct'); + // $parse_mode->setConjunction('AND'); $query->setParseMode($parse_mode); + // search in both languages (if not conditions will not work) + $query->setLanguages(array('fr','en')); + // workflow $wf_condition_group = $query->createConditionGroup('OR'); $wf_condition_group->addCondition('field_workflow', 'corpus_documents_publie', "="); @@ -335,6 +345,8 @@ class EdlpSearchController extends ControllerBase { $query->addCondition('field_genres', $this->genres, "="); } + // TODO: locuteurs + // entries $this->entry_names = []; if (!empty($this->entries)){ @@ -348,15 +360,6 @@ class EdlpSearchController extends ControllerBase { $query->addConditionGroup($entries_condition_group); } - // TODO: locuteurs - - $current_langcode = \Drupal::languageManager()->getCurrentLanguage()->getId(); - $query->setLanguages(array($current_langcode)); - - // $language = \Drupal::languageManager()->getCurrentLanguage()->getId(); - // // $language = \Drupal::languageManager()->getCurrentLanguage()->getName(); - // $query->addCondition('search_api_language', $language); - $result = $query->execute(); $items = $result->getResultItems(); // dpm($items);