Browse Source

Updated entity autocomplete and fixed the autocomplete method for solr fields with more than one value.

pull/2/head
mroy 14 years ago
parent
commit
1bc90c3c98
  1. 26
      form_elements/includes/autocomplete.inc

26
form_elements/includes/autocomplete.inc

@ -66,19 +66,19 @@ function ife_autocomplete_person($string) {
} }
} }
if ($name == null && isset($given) && isset($family)) {
$name = (isset($title)?$title.' ':'').$family.', '.$given;
}
$role =null; $role =null;
$roleTerm = $node->getElementsByTagName('roleTerm'); $roleTerm = $node->getElementsByTagName('roleTerm');
if ($roleTerm->length > 0) { if ($roleTerm->length > 0) {
$role=$roleTerm->item(0)->nodeValue; $role=$roleTerm->item(0)->nodeValue;
} }
if (strpos(strtolower($given.$family.$name),$string)!==FALSE) { if (strpos(strtolower($name),$string)!==FALSE) {
switch ($type) $display = $name;
{ $matches[json_encode(array('type'=>trim($type),'name'=>trim($name),'role'=>trim($role),'date'=>trim($date)))]= $display.' - '.$role.' '.$date;
case 'personal': $display = $title.' '.$given.' '.$family; break;
default: $display = $name; break;
}
$matches[json_encode(array('type'=>$type,'title'=>$title,'given'=>$given,'family'=>$family,'name'=>$name,'role'=>$role,'date'=>$date))]= $display;
} }
} }
} }
@ -211,12 +211,20 @@ function ife_autocomplete($field, $collection, $string='') {
} }
$docs = $results->response->docs; $docs = $results->response->docs;
$values = array(); $values = array();
if ($docs != NULL) { if ($docs != NULL) {
foreach ($docs as $doc) { foreach ($docs as $doc) {
$resfield=$doc->getField($field); $resfield=$doc->getField($field);
$values[$resfield['value']]=$resfield['value'];
if (is_array($resfield['value'])) {
foreach ($resfield['value'] as $val) {
if (preg_match('/^'.strtolower($string).'/i',$val)) {
$values[$val]=$val;
}
}
} else {
$values[$resfield['value']]=$resfield['value'];
}
} }
} }

Loading…
Cancel
Save