Added ability to filter search by topic.

This commit is contained in:
flash 2025-02-11 02:41:49 +00:00
parent e1cb500f99
commit 6b2bfb726f
3 changed files with 15 additions and 4 deletions
public-legacy

View file

@ -33,6 +33,11 @@ Template::addFunction('search_merge_query', function($attrs) use (&$searchQueryE
elseif(!empty($searchQueryEvaluated['after']))
$existing[] = 'after:' . $searchQueryEvaluated['after'];
if(!empty($attrs['topic']))
$existing[] = 'topic:' . $attrs['topic'];
elseif(!empty($searchQueryEvaluated['topic']))
$existing[] = 'topic:' . $searchQueryEvaluated['topic'];
$existing = array_merge($existing, array_unique(array_merge(
$searchQueryEvaluated['query'],
empty($attrs['query']) ? [] : explode(' ', $attrs['query'])
@ -41,7 +46,7 @@ Template::addFunction('search_merge_query', function($attrs) use (&$searchQueryE
return implode(' ', $existing);
});
if(!empty($searchQuery)) {
$searchQueryAttributes = ['type', 'author', 'after'];
$searchQueryAttributes = ['type', 'author', 'after', 'topic'];
$searchQueryParts = explode(' ', $searchQuery);
foreach($searchQueryParts as $queryPart) {
$queryPart = trim($queryPart);
@ -141,8 +146,10 @@ if(!empty($searchQuery)) {
else
$newsCategoryInfos[$categoryId] = $categoryInfo = $msz->news->getCategory(postInfo: $postInfo);
$commentsCount = $postInfo->commentsSectionId !== null
? $msz->comments->countPosts(categoryInfo: $postInfo->commentsSectionId, deleted: false) : 0;
$commentsCount = $msz->commentsCtx->posts->countPosts(
categoryName: $postInfo->commentsCategoryName,
deleted: false,
);
$newsPosts[] = [
'post' => $postInfo,