Speeding up the search for tags.

This commit is contained in:
Michael Vogel 2013-10-15 00:49:13 +02:00
parent 680524f446
commit 1b0b686116
2 changed files with 25 additions and 17 deletions

View File

@ -174,8 +174,6 @@ function network_init(&$a) {
); );
} }
// search terms header // search terms header
if(x($_GET,'search')) { if(x($_GET,'search')) {
$a->page['content'] .= '<h2>' . t('Search Results For:') . ' ' . $search . '</h2>'; $a->page['content'] .= '<h2>' . t('Search Results For:') . ' ' . $search . '</h2>';
@ -225,9 +223,9 @@ function saved_searches($search) {
'selected' => ($search==$rr['term']), 'selected' => ($search==$rr['term']),
); );
} }
} }
$tpl = get_markup_template("saved_searches_aside.tpl"); $tpl = get_markup_template("saved_searches_aside.tpl");
$o = replace_macros($tpl, array( $o = replace_macros($tpl, array(
'$title' => t('Saved Searches'), '$title' => t('Saved Searches'),
@ -235,7 +233,7 @@ function saved_searches($search) {
'$searchbox' => search($search,'netsearch-box',$srchurl,true), '$searchbox' => search($search,'netsearch-box',$srchurl,true),
'$saved' => $saved, '$saved' => $saved,
)); ));
return $o; return $o;
} }
@ -270,15 +268,15 @@ function network_query_get_sel_tab($a) {
|| ($a->argc > 2 && $a->argv[2] === 'new')) { || ($a->argc > 2 && $a->argv[2] === 'new')) {
$new_active = 'active'; $new_active = 'active';
} }
if(x($_GET,'search')) { if(x($_GET,'search')) {
$search_active = 'active'; $search_active = 'active';
} }
if(x($_GET,'star')) { if(x($_GET,'star')) {
$starred_active = 'active'; $starred_active = 'active';
} }
if(x($_GET,'bmark')) { if(x($_GET,'bmark')) {
$bookmarked_active = 'active'; $bookmarked_active = 'active';
} }
@ -291,8 +289,8 @@ function network_query_get_sel_tab($a) {
$spam_active = 'active'; $spam_active = 'active';
} }
if (($new_active == '') if (($new_active == '')
&& ($starred_active == '') && ($starred_active == '')
&& ($bookmarked_active == '') && ($bookmarked_active == '')
@ -308,7 +306,7 @@ function network_query_get_sel_tab($a) {
case 'comment' : $all_active = 'active'; $no_active=''; break; case 'comment' : $all_active = 'active'; $no_active=''; break;
} }
} }
return array($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active); return array($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active);
} }
@ -571,7 +569,6 @@ function network_content(&$a, $update = 0) {
// that belongs to you, hence you can see all of it. We will filter by group if // that belongs to you, hence you can see all of it. We will filter by group if
// desired. // desired.
$sql_options = (($star) ? " and starred = 1 " : ''); $sql_options = (($star) ? " and starred = 1 " : '');
$sql_options .= (($bmark) ? " and bookmark = 1 " : ''); $sql_options .= (($bmark) ? " and bookmark = 1 " : '');
@ -641,6 +638,7 @@ function network_content(&$a, $update = 0) {
$sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` "); $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
$sql_extra3 = (($nouveau) ? '' : $sql_extra3); $sql_extra3 = (($nouveau) ? '' : $sql_extra3);
$sql_order = "`item`.`received`";
$sql_table = "`item`"; $sql_table = "`item`";
if(x($_GET,'search')) { if(x($_GET,'search')) {
@ -675,11 +673,15 @@ function network_content(&$a, $update = 0) {
$sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ", $sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ",
dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG)); dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG));
$sql_table = "`term` LEFT JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` "; $sql_table = "`term` LEFT JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` ";
$sql_order = "`term`.`tid`";
} else { } else {
if (get_config('system','use_fulltext_engine')) if (get_config('system','use_fulltext_engine'))
$sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search))); $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
else else
$sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search)))); $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
$sql_order = "`item`.`received`";
} }
} }
if(strlen($file)) { if(strlen($file)) {
@ -767,7 +769,7 @@ function network_content(&$a, $update = 0) {
$simple_update $simple_update
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
$sql_extra $sql_nets $sql_extra $sql_nets
ORDER BY `item`.`received` DESC $pager_sql ", ORDER BY $sql_order DESC $pager_sql ",
intval($_SESSION['uid']) intval($_SESSION['uid'])
); );
@ -783,6 +785,9 @@ function network_content(&$a, $update = 0) {
else else
$ordering = "`commented`"; $ordering = "`commented`";
if ($sql_order == "")
$sql_order = "`item`.$ordering";
// Fetch a page full of parent items for this page // Fetch a page full of parent items for this page
if($update) { if($update) {
@ -803,7 +808,7 @@ function network_content(&$a, $update = 0) {
AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
AND `item`.`parent` = `item`.`id` AND `item`.`parent` = `item`.`id`
$sql_extra3 $sql_extra $sql_nets $sql_extra3 $sql_extra $sql_nets
ORDER BY `item`.$ordering DESC $pager_sql ", ORDER BY $sql_order DESC $pager_sql ",
intval(local_user()) intval(local_user())
); );
} }
@ -874,7 +879,7 @@ function network_content(&$a, $update = 0) {
$o .= conversation($a,$items,$mode,$update); $o .= conversation($a,$items,$mode,$update);
if(! $update) { if(!$update) {
if( get_config('alt_pager', 'global') || get_pconfig(local_user(),'system','alt_pager') ) { if( get_config('alt_pager', 'global') || get_pconfig(local_user(),'system','alt_pager') ) {
$o .= alt_pager($a,count($items)); $o .= alt_pager($a,count($items));
} }

View File

@ -144,6 +144,8 @@ function search_content(&$a) {
$sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d group by `item`.`uri` ", $sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d group by `item`.`uri` ",
dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG)); dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG));
$sql_table = "`term` LEFT JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` "; $sql_table = "`term` LEFT JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` ";
$sql_order = "`term`.`tid`";
//$sql_order = "`item`.`received`";
//$sql_extra = sprintf(" AND EXISTS (SELECT * FROM `term` WHERE `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d) GROUP BY `item`.`uri` ", //$sql_extra = sprintf(" AND EXISTS (SELECT * FROM `term` WHERE `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d) GROUP BY `item`.`uri` ",
// dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG)); // dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG));
@ -155,6 +157,7 @@ function search_content(&$a) {
$sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search)))); $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
} }
$sql_table = "`item`"; $sql_table = "`item`";
$sql_order = "`item`.`received`";
} }
// Here is the way permissions work in the search module... // Here is the way permissions work in the search module...
@ -195,7 +198,7 @@ function search_content(&$a) {
OR ( `item`.`uid` = %d )) OR ( `item`.`uid` = %d ))
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
$sql_extra $sql_extra
ORDER BY `received` DESC LIMIT %d , %d ", ORDER BY $sql_order DESC LIMIT %d , %d ",
intval(local_user()), intval(local_user()),
intval($a->pager['start']), intval($a->pager['start']),
intval($a->pager['itemspage']) intval($a->pager['itemspage'])
@ -209,7 +212,7 @@ function search_content(&$a) {
} }
if($tag) if($tag)
$o .= '<h2>Items tagged with: ' . $search . '</h2>'; $o .= '<h2>Items tagged with: ' . $search . '</h2>';
else else
$o .= '<h2>Search results for: ' . $search . '</h2>'; $o .= '<h2>Search results for: ' . $search . '</h2>';