aboutsummaryrefslogtreecommitdiffstats
path: root/mod/search.php
diff options
context:
space:
mode:
authorOlivier van Helden <olivier@van-helden.net>2014-12-03 17:54:07 -0400
committerOlivier van Helden <olivier@van-helden.net>2014-12-03 17:54:07 -0400
commite523061b7261439a71bdacf8f46d4c614740b356 (patch)
tree1a0577c64197c4289ed154d2c2d5fdf48a7e5192 /mod/search.php
parent13fd91d6f5723774a1b96257f8096acb2873b4ed (diff)
parentb71b45aafc618d32d23c099a4d4db8bad2f09e54 (diff)
downloadvolse-hubzilla-e523061b7261439a71bdacf8f46d4c614740b356.tar.gz
volse-hubzilla-e523061b7261439a71bdacf8f46d4c614740b356.tar.bz2
volse-hubzilla-e523061b7261439a71bdacf8f46d4c614740b356.zip
Merge pull request #1 from friendica/master
Merge master from friendica
Diffstat (limited to 'mod/search.php')
-rw-r--r--mod/search.php36
1 files changed, 22 insertions, 14 deletions
diff --git a/mod/search.php b/mod/search.php
index 15ac71376..612ceb4bc 100644
--- a/mod/search.php
+++ b/mod/search.php
@@ -68,7 +68,8 @@ function search_content(&$a,$update = 0, $load = false) {
);
}
else {
- $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
+ $regstr = db_getfunc('REGEXP');
+ $sql_extra = sprintf(" AND `item`.`body` $regstr '%s' ", dbesc(protect_sprintf(preg_quote($search))));
}
// Here is the way permissions work in the search module...
@@ -123,7 +124,7 @@ function search_content(&$a,$update = 0, $load = false) {
if(($update) && ($load)) {
$itemspage = get_pconfig(local_user(),'system','itemspage');
$a->set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20));
- $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
+ $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval($a->pager['itemspage']), intval($a->pager['start']));
// in case somebody turned off public access to sys channel content with permissions
@@ -132,29 +133,36 @@ function search_content(&$a,$update = 0, $load = false) {
if($load) {
$r = null;
-
+
+ if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
+ $prefix = 'distinct on (created, mid)';
+ $suffix = 'ORDER BY created DESC, mid';
+ } else {
+ $prefix = 'distinct';
+ $suffix = 'group by mid ORDER BY created DESC';
+ }
if(local_user()) {
- $r = q("SELECT distinct mid, item.id as item_id, item.* from item
+ $r = q("SELECT $prefix mid, item.id as item_id, item.* from item
WHERE item_restrict = 0
AND ((( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND item_private = 0 )
OR ( `item`.`uid` = %d )) OR item.owner_xchan = '%s' )
$sql_extra
- group by mid ORDER BY created DESC $pager_sql ",
+ $suffix $pager_sql ",
intval(local_user()),
dbesc($sys['xchan_hash'])
);
}
if($r === null) {
- $r = q("SELECT distinct mid, item.id as item_id, item.* from item
- WHERE item_restrict = 0
- AND (((( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = ''
- AND `item`.`deny_gid` = '' AND item_private = 0 )
- and owner_xchan in ( " . stream_perms_xchans(($observer) ? (PERMS_NETWORK|PERMS_PUBLIC) : PERMS_PUBLIC) . " ))
- $pub_sql ) OR owner_xchan = '%s')
- $sql_extra
- group by mid ORDER BY created DESC $pager_sql",
+ $r = q("SELECT $prefix mid, item.id as item_id, item.* from item
+ WHERE item_restrict = 0
+ AND (((( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = ''
+ AND `item`.`deny_gid` = '' AND item_private = 0 )
+ and owner_xchan in ( " . stream_perms_xchans(($observer) ? (PERMS_NETWORK|PERMS_PUBLIC) : PERMS_PUBLIC) . " ))
+ $pub_sql ) OR owner_xchan = '%s')
+ $sql_extra
+ $suffix $pager_sql",
dbesc($sys['xchan_hash'])
- );
+ );
}
}
else {