Commit 55dadeda authored by Richard Mansfield's avatar Richard Mansfield Committed by Nigel McNie
Browse files

Sort by email in solr

parent 56e13fd0
......@@ -142,14 +142,9 @@ function build_admin_user_search_results($search, $offset, $limit, $sortby, $sor
$constraints = array();
if (!empty($search->query)) {
if (strpos($search->query, '@') !== false) {
$terms = preg_split('/[\.@]/', $search->query);
foreach ($terms as $t) {
if (!empty($t)) {
$constraints[] = array('field' => 'email',
'type' => 'contains',
'string' => $t);
}
}
$queries[] = array('field' => 'email',
'type' => 'contains',
'string' => $search->query);
} else {
$queries = array(array('field' => 'firstname',
'type' => 'contains',
......
......@@ -179,7 +179,8 @@ END;
continue;
}
if ($key_parts[0] == 'store' || $key_parts[0] == 'text' || $key == 'ref_institution') {
if ($key_parts[0] == 'store' || $key_parts[0] == 'text' || $key_parts[0] == 'string'
|| $key == 'ref_institution') {
$new_result[$key_parts[1]] = $value;
}
}
......@@ -203,7 +204,7 @@ END;
$solrfields = array(
'id' => 'id',
'institution' => 'ref_institution',
'email' => 'text_email',
'email' => 'string_email',
'username' => 'text_username',
'firstname' => 'text_firstname',
'lastname' => 'text_lastname'
......@@ -211,8 +212,12 @@ END;
if (!empty($queries)) {
$terms = array();
foreach ($queries as $f) {
$terms[] = $solrfields[$f['field']] . ':' . strtolower($f['string'])
. ($f['type'] != 'equals' ? '*' : '');
if ($f['field'] == 'email' && $f['type'] == 'contains' && strpos($f['string'],'@') === 0) {
$terms[] = 'string_emaildomain:' . substr($f['string'], 1) . '*';
} else {
$terms[] = $solrfields[$f['field']] . ':' . strtolower($f['string'])
. ($f['type'] != 'equals' ? '*' : '');
}
}
$q .= '(' . join(' OR ', $terms) . ')';
}
......@@ -228,11 +233,7 @@ END;
$q .= join(' AND ', $terms);
}
if ($sortby != 'email') {
$sort = $solrfields[$sortby] . ' ' . $sortdir;
} else {
$sort = null;
}
$sort = $solrfields[$sortby] . ' ' . $sortdir;
$results = self::send_query($q, $limit, $offset, array('type' => 'user'), '*', false, $sort);
self::remove_key_prefix(&$results);
......@@ -438,7 +439,7 @@ END;
'type' => 'user',
'index_name' => $user['preferredname'],
'ref_institution' => $user['institution'],
'text_email' => $user['email'],
'string_email' => $user['email'],
'text_username' => $user['username'],
'store_preferredname' => $user['preferredname'],
'text_firstname' => $user['firstname'],
......@@ -447,6 +448,12 @@ END;
if (empty($doc['index_name'])) {
$doc['index_name'] = $user['firstname'] . ' ' . $user['lastname'];
}
if ($emailparts = split('@', $user['email'])
and !empty($emailparts[1])) {
$doc['string_emaildomain'] = $emailparts[1];
} else {
$doc['string_emaildomain'] = $user['email'];
}
self::add_document($doc);
}
......
......@@ -107,10 +107,11 @@
<field name="text" type="text" indexed="true" stored="false" multiValued="true" />
<dynamicField name="text_*" type="text" indexed="true" stored="true" />
<dynamicField name="ref_*" type="text" indexed="true" stored="true" />
<dynamicField name="store_*" type="text" indexed="false" stored="true" />
<dynamicField name="index_*" type="text" indexed="true" stored="false" />
<dynamicField name="text_*" type="text" indexed="true" stored="true" />
<dynamicField name="ref_*" type="text" indexed="true" stored="true" />
<dynamicField name="store_*" type="text" indexed="false" stored="true" />
<dynamicField name="index_*" type="text" indexed="true" stored="false" />
<dynamicField name="string_*" type="string" indexed="true" stored="true" />
<!-- Dynamic field definitions. If a field name is not found, dynamicFields
will be used if the name matches any of the patterns.
......
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