X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FSearch%2FIndex.php;h=e0050f405cd4fb873bedf3949c6a6cc509972552;hb=d666b6cb42a1b0d46e9fae914a803fbd5e10e2ab;hp=bf3ae2585b19de398b99ef90f2f9163aa8c35b4c;hpb=398e65d66b929a4931f62477f86ea1df6fe99c9a;p=friendica.git diff --git a/src/Module/Search/Index.php b/src/Module/Search/Index.php index bf3ae2585b..e0050f405c 100644 --- a/src/Module/Search/Index.php +++ b/src/Module/Search/Index.php @@ -34,6 +34,8 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Item; +use Friendica\Model\ItemContent; +use Friendica\Model\Post; use Friendica\Model\Tag; use Friendica\Module\BaseSearch; use Friendica\Network\HTTPException; @@ -131,6 +133,14 @@ class Index extends BaseSearch } } + // Don't perform a fulltext or tag search on search results that look like an URL + // Tags don't look like an URL and the fulltext search does only work with natural words + if (parse_url($search, PHP_URL_SCHEME) && parse_url($search, PHP_URL_HOST)) { + Logger::info('Skipping tag and fulltext search since the search looks like a URL.', ['q' => $search]); + notice(DI::l10n()->t('No results.')); + return $o; + } + $tag = $tag || DI::config()->get('system', 'only_tag_search'); // Here is the way permissions work in the search module... @@ -146,40 +156,37 @@ class Index extends BaseSearch DI::config()->get('system', 'itemspage_network')); } + $last_uriid = isset($_GET['last_uriid']) ? intval($_GET['last_uriid']) : 0; + $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage); if ($tag) { Logger::info('Start tag search.', ['q' => $search]); - $uriids = Tag::getURIIdListByTag($search, local_user(), $pager->getStart(), $pager->getItemsPerPage()); - - if (!empty($uriids)) { - $params = ['order' => ['id' => true], 'group_by' => ['uri-id']]; - $items = Item::selectForUser(local_user(), [], ['uri-id' => $uriids], $params); - $r = Item::inArray($items); - } else { - $r = []; - } + $uriids = Tag::getURIIdListByTag($search, local_user(), $pager->getStart(), $pager->getItemsPerPage(), $last_uriid); + $count = Tag::countByTag($search, local_user()); } else { Logger::info('Start fulltext search.', ['q' => $search]); + $uriids = Post\Content::getURIIdListBySearch($search, local_user(), $pager->getStart(), $pager->getItemsPerPage(), $last_uriid); + $count = Post\Content::countBySearch($search, local_user()); + } - $condition = [ - "(`uid` = 0 OR (`uid` = ? AND NOT `global`)) - AND `body` LIKE CONCAT('%',?,'%')", - local_user(), $search - ]; - $params = [ - 'order' => ['id' => true], - 'limit' => [$pager->getStart(), $pager->getItemsPerPage()] - ]; - $items = Item::selectForUser(local_user(), [], $condition, $params); - $r = Item::inArray($items); + if (!empty($uriids)) { + $params = ['order' => ['id' => true], 'group_by' => ['uri-id']]; + $items = Post::toArray(Post::selectForUser(local_user(), Item::DISPLAY_FIELDLIST, ['uri-id' => $uriids], $params)); } - if (!DBA::isResult($r)) { - notice(DI::l10n()->t('No results.')); + if (empty($items)) { + if (empty($last_uriid)) { + notice(DI::l10n()->t('No results.')); + } return $o; } + if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) { + $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl'); + $o .= Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]); + } + if ($tag) { $title = DI::l10n()->t('Items tagged with: %s', $search); } else { @@ -192,9 +199,14 @@ class Index extends BaseSearch Logger::info('Start Conversation.', ['q' => $search]); - $o .= conversation(DI::app(), $r, 'search', false, false, 'commented', local_user()); + $o .= conversation(DI::app(), $items, 'search', false, false, 'commented', local_user()); + + if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) { + $o .= HTML::scrollLoader(); + } else { + $o .= $pager->renderMinimal($count); + } - $o .= $pager->renderMinimal(count($r)); return $o; } @@ -277,7 +289,7 @@ class Index extends BaseSearch } if (!empty($item_id)) { - $item = Item::selectFirst(['guid'], ['id' => $item_id]); + $item = Post::selectFirst(['guid'], ['id' => $item_id]); if (DBA::isResult($item)) { DI::baseUrl()->redirect('display/' . $item['guid']); }