Commit 65e92abe authored by Richard Mansfield's avatar Richard Mansfield Committed by Nigel McNie
Browse files

Admin user search can use solr plugin

parent 15a78e42
......@@ -179,8 +179,7 @@ function build_admin_user_search_results($search) {
function admin_user_search($searchparams) {
$plugin = 'internal'; // No admin search with solr yet.
//$plugin = get_config('searchplugin');
$plugin = get_config('searchplugin');
safe_require('search', $plugin);
return call_static_method(generate_class_name('search', $plugin), 'admin_search_user', $searchparams);
}
......
......@@ -163,9 +163,7 @@ END;
set_config_plugin('search', 'solr', 'solrurl', $values['solrurl']);
}
public static function search_user($query_string, $limit, $offset = 0) {
$results = self::send_query($query_string, $limit, $offset, array('type' => 'user'));
private static function remove_key_prefix($results) {
if (is_array($results['data'])) {
foreach ($results['data'] as &$result) {
$new_result = array();
......@@ -188,13 +186,46 @@ END;
$result = $new_result;
}
}
}
public static function search_user($query_string, $limit, $offset = 0) {
if (!empty($query_string)) {
$query_string .= '*';
}
$results = self::send_query($query_string, $limit, $offset, array('type' => 'user'));
self::remove_key_prefix(&$results);
return $results;
}
public static function admin_search_user($s) {
//$results = self::send_query($query_string, $limit, $offset, array('type' => 'user'));
return array();
if (!empty($s->expr['or'])) {
$op = 'or';
} else if (!empty($s->expr['and'])) {
$op = 'and';
} else {
$q = '';
}
if (!empty($op)) {
$solrfields = array(
'id' => 'id',
'institution' => 'ref_institution',
'email' => 'index_email',
'username' => 'index_username',
'firstname' => 'index_firstname',
'lastname' => 'index_lastname'
);
$terms = array();
foreach ($s->expr[$op] as $f) {
$terms[] = $solrfields[$f['field']] . ':' . strtolower($f['string'])
. ($f['type'] != 'equals' ? '*' : '');
}
$q = join(' '.strtoupper($op).' ', $terms);
}
$results = self::send_query($q, $s->limit, $s->offset, array('type' => 'user'));
self::remove_key_prefix(&$results);
return $results;
}
......@@ -396,10 +427,14 @@ END;
'type' => 'user',
'index_name' => $user['preferredname'],
'ref_institution' => $user['institution'],
'index_email' => $user['email'],
'store_email' => $user['email'],
'index_username' => $user['username'],
'store_username' => $user['username'],
'store_preferredname' => $user['preferredname'],
'index_firstname' => $user['firstname'],
'store_firstname' => $user['firstname'],
'index_lastname' => $user['lastname'],
'store_lastname' => $user['lastname'],
);
if (empty($doc['index_name'])) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment