]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Updated search to allow filtering of results by clicking on submenu items.
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Mon, 9 Nov 2009 20:44:34 +0000 (20:44 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Mon, 9 Nov 2009 20:44:34 +0000 (20:44 +0000)
Fixes #1358: Using raw mysql_query() / fetch() to get ft_min/max vars since they aren't set on some versions of MySQL.

git-svn-id: http://code.elgg.org/elgg/trunk@3645 36083f99-b078-4883-b0ff-0f9b5a30f544

mod/search/index.php
mod/search/search_hooks.php
mod/search/start.php
mod/search/views/default/search/comments/listing.php
mod/search/views/default/search/listing.php

index f9a96a60b781606d682f36d2c92206fee225d065..2927e66166eb13db9d62f95713a5c88a0fa84676 100644 (file)
@@ -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);
 
index 07b9aa37f69341d8a4aa6594ba5afebadd431e67..46a26b5ef8bce04fbbc09f78220538f94ecfe466 100644 (file)
@@ -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
index cad2aab4138464ad9dd682047464bc75bd328a25..02f7da494783f9cc88e5b60237da5d6ad9576c29 100644 (file)
@@ -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 ) {
index 8ba0a22886680db2ebcc7a2da0a5954b7782f340..58353a1106f5fe2eb481d98e247e6d719e596c94 100644 (file)
@@ -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',
        )
 ));
 
index 23a6a44e8497b676c46221c21f63089e478d7d76..37850c9117ee836e56509c6f11cd19e6e0873f68 100644 (file)
@@ -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',
        )
 ));