search from english, fix #467
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user