Commit 5fdf13c9 authored by Nigel McNie's avatar Nigel McNie Committed by Penny Leach
Browse files

Implemented community searching.

parent 29709b46
......@@ -108,4 +108,43 @@ function search_group($query_string, $limit, $offset = 0) {
return call_static_method(generate_class_name('search', $plugin), 'search_group', $query_string, $limit, $offset);
}
/**
* Given a query string and limits, return an array of matching communities using the
* search plugin defined in config.php
*
* @param string The query string
* @param integer How many results to return
* @param integer What result to start at (0 == first result)
* @return array A data structure containing results looking like ...
* $results = array(
* count => integer, // total number of results
* limit => integer, // how many results are returned
* offset => integer, // starting from which result
* results => array( // the result records
* array(
* id => integer,
* name => string,
* owner => integer,
* description => string,
* ctime => string,
* mtime => string,
* ),
* array(
* id => integer,
* name => string,
* owner => integer,
* description => string,
* ctime => string,
* mtime => string,
* ),
* array(...),
* ),
* );
*/
function search_community($query_string, $limit, $offset = 0) {
$plugin = get_config('searchplugin');
safe_require('search', $plugin);
return call_static_method(generate_class_name('search', $plugin), 'search_community', $query_string, $limit, $offset);
}
?>
......@@ -103,9 +103,7 @@ class PluginSearchInternal extends PluginSearch {
OR email ILIKE '%' || ? || '%'
)
",
array($query_string, $query_string, $query_string, $query_string),
$offset,
$limit
array($query_string, $query_string, $query_string, $query_string)
);
}
// TODO
......@@ -189,16 +187,95 @@ class PluginSearchInternal extends PluginSearch {
OR description ILIKE '%' || ? || '%'
)
",
array($USER->get('id'), $query_string, $query_string),
array($USER->get('id'), $query_string, $query_string)
);
}
// TODO
// else if ( is_mysql() ) {
// }
else {
throw new SQLException('search_group() is not implemented for your database engine (' . get_config('dbtype') . ')');
}
return array(
'count' => $count,
'limit' => $limit,
'offset' => $offset,
'data' => $data,
);
}
/**
* Implement community searching with SQL
*
* @param string The query string
* @param integer How many results to return
* @param integer What result to start at (0 == first result)
* @return array A data structure containing results looking like ...
* $results = array(
* count => integer, // total number of results
* limit => integer, // how many results are returned
* offset => integer, // starting from which result
* data => array( // the result records
* array(
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* preferredname => string,
* email => string,
* ),
* array(
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* preferredname => string,
* email => string,
* ),
* array(...),
* ),
* );
*/
public static function search_community($query_string, $limit, $offset = 0) {
global $USER;
if ( is_postgres() ) {
$data = get_records_sql_array("
SELECT
id, name, description, jointype, owner, ctime, mtime
FROM
" . get_config('dbprefix') . "community
WHERE
name ILIKE '%' || ? || '%'
OR description ILIKE '%' || ? || '%'
",
array($query_string, $query_string),
$offset,
$limit
);
$count = get_field_sql("
SELECT
COUNT(*)
FROM
" . get_config('dbprefix') . "usr_group u
WHERE
owner = ?
AND (
name ILIKE '%' || ? || '%'
OR description ILIKE '%' || ? || '%'
)
",
array($query_string, $query_string)
);
}
// TODO
// else if ( is_mysql() ) {
// }
else {
throw new SQLException('search_group() is not implemented for your database engine (' . get_config('dbtype') . ')');
throw new SQLException('search_community() is not implemented for your database engine (' . get_config('dbtype') . ')');
}
return array(
......
......@@ -44,6 +44,9 @@ switch ($type) {
case 'group':
$data = get_group_results($query, $limit, $offset);
break;
case 'community':
$data = get_community_results($query, $limit, $offset);
break;
}
json_headers();
......@@ -82,4 +85,15 @@ function get_group_results($query, $limit, $offset) {
return $data;
}
function get_community_results($query, $limit, $offset) {
$data = search_community($query, $limit, $offset);
if ($data['data']) {
foreach ($data['data'] as &$result) {
}
}
return $data;
}
?>
Markdown is supported
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