|
@@ -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');
|
|
|
}
|
|
|
|