aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mod/search/index.php123
-rw-r--r--mod/search/search_hooks.php3
-rw-r--r--mod/search/start.php18
-rw-r--r--mod/search/views/default/search/comments/listing.php5
-rw-r--r--mod/search/views/default/search/listing.php5
5 files changed, 130 insertions, 24 deletions
diff --git a/mod/search/index.php b/mod/search/index.php
index f9a96a60b..2927e6616 100644
--- a/mod/search/index.php
+++ b/mod/search/index.php
@@ -4,15 +4,15 @@
$search_type = get_input('search_type', 'all');
// @todo there is a bug in get_input that makes variables have slashes sometimes.
-$query = sanitise_string(stripslashes(get_input('q', get_input('tag', '', FALSE), FALSE)));
+$query = stripslashes(get_input('q', get_input('tag', '', FALSE), FALSE));
// get limit and offset. override if on search dashboard, where only 2
// of each most recent entity types will be shown.
$limit = ($search_type == 'all') ? 2 : get_input('limit', 10);
$offset = ($search_type == 'all') ? 0 : get_input('offset', 0);
-$type = get_input('type', '');
-$subtype = get_input('subtype', '');
+$entity_type = get_input('entity_type', NULL);
+$entity_subtype = get_input('entity_subtype', NULL);
$owner_guid = get_input('owner_guid', NULL);
$friends = (int)get_input('friends', 0);
@@ -22,17 +22,97 @@ $params = array(
'offset' => $offset,
'limit' => $limit,
'search_type' => $search_type,
- 'type' => $type,
- 'subtype' => $subtype,
- 'tag_type' => $tag_type,
+ 'type' => $entity_type,
+ 'subtype' => $entity_subtype,
+// 'tag_type' => $tag_type,
'owner_guid' => $owner_guid,
- 'friends' => $friends
+// 'friends' => $friends
);
$results_html = '';
-if ($search_type == 'entities' || $search_type == 'all') {
- $types = get_registered_entity_types();
+//$results_html .= elgg_view_title(elgg_echo('search:results')) . "<input type=\"text\" value=\"$query\" />";
+$results_html .= elgg_view_title(elgg_echo('search:results'));
+$types = get_registered_entity_types();
+$custom_types = trigger_plugin_hook('search_types', 'get_types', $params, array());
+
+// add submenu items for all and native types
+// @todo should these maintain any existing type / subtype filters or reset?
+$data = http_build_query(array(
+ 'q' => urlencode($query),
+ 'entity_subtype' => urlencode($subtype),
+ 'entity_type' => urlencode($type),
+ 'owner_guid' => urlencode($owner_guid),
+ 'search_type' => 'all',
+ 'friends' => $friends
+));
+$url = "{$CONFIG->wwwroot}pg/search/?$data";
+add_submenu_item(elgg_echo('all'), $url);
+
+foreach ($types as $type => $subtypes) {
+ // @todo when using index table, can include result counts on each of these.
+ if (is_array($subtypes) && count($subtypes)) {
+ foreach ($subtypes as $subtype) {
+ $label = "item:$type:$subtype";
+
+ $data = http_build_query(array(
+ 'q' => urlencode($query),
+ 'entity_subtype' => urlencode($subtype),
+ 'entity_type' => urlencode($type),
+ 'owner_guid' => urlencode($owner_guid),
+ 'search_type' => 'entities',
+ 'friends' => $friends
+ ));
+
+ $url = "{$CONFIG->wwwroot}pg/search/?$data";
+
+ add_submenu_item(elgg_echo($label), $url);
+ }
+ } else {
+ $label = "item:$type";
+
+ $data = http_build_query(array(
+ 'q' => urlencode($query),
+ 'entity_type' => urlencode($type),
+ 'owner_guid' => urlencode($owner_guid),
+ 'search_type' => 'entities',
+ 'friends' => $friends
+ ));
+
+ $url = "{$CONFIG->wwwroot}pg/search/?$data";
+
+ add_submenu_item(elgg_echo($label), $url);
+ }
+}
+
+// add submenu for custom searches
+foreach ($custom_types as $type) {
+ $label = "search_types:$type";
+
+ $data = http_build_query(array(
+ 'q' => urlencode($query),
+ 'entity_subtype' => $entity_subtype,
+ 'entity_type' => urlencode($entity_type),
+ 'owner_guid' => urlencode($owner_guid),
+ 'search_type' => $type,
+ 'friends' => $friends
+ ));
+
+ $url = "{$CONFIG->wwwroot}pg/search/?$data";
+
+ add_submenu_item(elgg_echo($label), $url);
+}
+
+// check that we have an actual query
+if (!$query) {
+ $body .= "No query.";
+ $layout = elgg_view_layout('two_column_left_sidebar', '', $body);
+ page_draw($title, $layout);
+
+ return;
+}
+
+if ($search_type == 'all' || $search_type == 'entities') {
// to pass the correct search type to the views
$params['search_type'] = 'entities';
@@ -41,8 +121,17 @@ if ($search_type == 'entities' || $search_type == 'all') {
// if a plugin returns NULL or '' for subtype, pass to generic type search function.
// if still NULL or '' or empty(array()) no results found. (== don't show??)
foreach ($types as $type => $subtypes) {
+ if ($search_type != 'all' && $entity_type != $type) {
+ continue;
+ }
+
if (is_array($subtypes) && count($subtypes)) {
foreach ($subtypes as $subtype) {
+ // no need to search if we're not interested in these results
+ // @todo when using index table, allow search to get full count.
+ if ($search_type != 'all' && $entity_subtype != $subtype) {
+ continue;
+ }
$params['subtype'] = $subtype;
$params['type'] = $type;
@@ -83,12 +172,16 @@ if ($search_type == 'entities' || $search_type == 'all') {
}
// call custom searches
-if ($search_type == 'all' || $search_type != 'entities') {
+if ($search_type != 'entities' || $search_type == 'all') {
// get custom search types
$types = trigger_plugin_hook('search_types', 'get_types', $params, array());
if (is_array($types)) {
foreach ($types as $type) {
+ if ($search_type != 'all' && $search_type != $type) {
+ continue;
+ }
+
$params['search_type'] = $type;
unset($params['subtype']);
@@ -115,11 +208,15 @@ if ($search_type == 'all' || $search_type != 'entities') {
call search_section_start to display long bar with types and titles
call search
-
-
*/
-$layout = elgg_view_layout('two_column_left_sidebar', '', $results_html);
+if (!$results_html) {
+ $body = elgg_echo('search:no_results');
+} else {
+ $body = $results_html;
+}
+
+$layout = elgg_view_layout('two_column_left_sidebar', '', $body);
page_draw($title, $layout);
diff --git a/mod/search/search_hooks.php b/mod/search/search_hooks.php
index 07b9aa37f..46a26b5ef 100644
--- a/mod/search/search_hooks.php
+++ b/mod/search/search_hooks.php
@@ -277,5 +277,4 @@ function search_comments_hook($hook, $type, $value, $params) {
function search_custom_types_comments_hook($hook, $type, $value, $params) {
$value[] = 'comments';
return $value;
-}
-
+} \ No newline at end of file
diff --git a/mod/search/start.php b/mod/search/start.php
index cad2aab41..02f7da494 100644
--- a/mod/search/start.php
+++ b/mod/search/start.php
@@ -35,11 +35,19 @@ function search_init() {
register_plugin_hook('search', 'comments', 'search_comments_hook');
// get server min and max allowed chars for ft searching
- $word_lens = get_data('SELECT @@ft_min_word_len as min, @@ft_max_word_len as max');
-
$CONFIG->search_info = array();
- $CONFIG->search_info['min_chars'] = $word_lens[0]->min;
- $CONFIG->search_info['max_chars'] = $word_lens[0]->max;
+
+ // can't use get_data() here because some servers don't have these globals set,
+ // which throws a db exception.
+ $r = mysql_query('SELECT @@ft_min_word_len as min, @@ft_max_word_len as max');
+ if ($word_lens = mysql_fetch_assoc($r)) {
+ $CONFIG->search_info['min_chars'] = $word_lens['min'];
+ $CONFIG->search_info['max_chars'] = $word_lens['max'];
+ } else {
+ // uhhh these are good numbers.
+ $CONFIG->search_info['min_chars'] = 4;
+ $CONFIG->search_info['max_chars'] = 90;
+ }
// add in CSS for search elements
extend_view('css', 'search/css');
@@ -331,7 +339,7 @@ function search_get_where_sql($table, $fields, $params) {
}
$likes_str = implode(' OR ', $likes);
//$where = "($table.guid = e.guid AND ($likes_str))";
- $where = "($likes_str))";
+ $where = "($likes_str)";
} else {
// if using advanced or paired "s, switch into boolean mode
if ((isset($params['advanced_search']) && $params['advanced_search']) || substr_count($query, '"') >= 2 ) {
diff --git a/mod/search/views/default/search/comments/listing.php b/mod/search/views/default/search/comments/listing.php
index 8ba0a2288..58353a110 100644
--- a/mod/search/views/default/search/comments/listing.php
+++ b/mod/search/views/default/search/comments/listing.php
@@ -21,10 +21,11 @@ $body = elgg_view_title($title_str);
$query = htmlspecialchars(http_build_query(
array(
'q' => $vars['params']['query'],
- 'type' => $vars['params']['type'],
+ 'entity_type' => $vars['params']['type'],
+ 'entity_subtype' => $vars['params']['subtype'],
'limit' => get_input('limit', 10),
'offset' => get_input('offset', 0),
- 'subtype' => $vars['params']['subtype']
+ 'search_type' => 'comments',
)
));
diff --git a/mod/search/views/default/search/listing.php b/mod/search/views/default/search/listing.php
index 23a6a44e8..37850c911 100644
--- a/mod/search/views/default/search/listing.php
+++ b/mod/search/views/default/search/listing.php
@@ -25,10 +25,11 @@ $body = elgg_view_title($title_str);
$query = htmlspecialchars(http_build_query(
array(
'q' => $vars['params']['query'],
- 'type' => $vars['params']['type'],
+ 'entity_type' => $vars['params']['type'],
+ 'entity_subtype' => $vars['params']['subtype'],
'limit' => get_input('limit', 10),
'offset' => get_input('offset', 0),
- 'subtype' => $vars['params']['subtype']
+ 'search_type' => 'entities',
)
));