Add ability to search for Community by its description (or title only). (#5044)

- This changes the post_title_only for Search to title_only, since its
  also used in the community query now.
- Fixes #4785
This commit is contained in:
Dessalines 2024-09-24 13:24:28 -04:00 committed by GitHub
parent a65be776e3
commit 0fab5bed24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 12 deletions

View File

@ -78,7 +78,7 @@ pub struct Search {
pub listing_type: Option<ListingType>,
pub page: Option<i64>,
pub limit: Option<i64>,
pub post_title_only: Option<bool>,
pub title_only: Option<bool>,
pub post_url_only: Option<bool>,
pub saved_only: Option<bool>,
pub liked_only: Option<bool>,

View File

@ -47,7 +47,7 @@ pub async fn search(
listing_type,
page,
limit,
post_title_only,
title_only,
post_url_only,
saved_only,
liked_only,
@ -78,7 +78,7 @@ pub async fn search(
search_term: Some(q.clone()),
page,
limit,
title_only: post_title_only,
title_only,
url_only: post_url_only,
liked_only,
disliked_only,
@ -105,6 +105,7 @@ pub async fn search(
sort,
listing_type,
search_term: Some(q.clone()),
title_only,
local_user,
is_mod_or_admin: is_admin,
page,

View File

@ -394,14 +394,12 @@ fn queries<'a>() -> Queries<
query = query.filter(post::url.eq(search_term));
} else {
let searcher = fuzzy_search(search_term);
let name_filter = post::name.ilike(searcher.clone());
let body_filter = post::body.ilike(searcher.clone());
query = if options.title_only.unwrap_or_default() {
query.filter(post::name.ilike(searcher))
query.filter(name_filter)
} else {
query.filter(
post::name
.ilike(searcher.clone())
.or(post::body.ilike(searcher)),
)
query.filter(name_filter.or(body_filter))
}
.filter(not(post::removed.or(post::deleted)));
}

View File

@ -112,9 +112,14 @@ fn queries<'a>() -> Queries<
if let Some(search_term) = options.search_term {
let searcher = fuzzy_search(&search_term);
query = query
.filter(community::name.ilike(searcher.clone()))
.or_filter(community::title.ilike(searcher))
let name_filter = community::name.ilike(searcher.clone());
let title_filter = community::title.ilike(searcher.clone());
let description_filter = community::description.ilike(searcher.clone());
query = if options.title_only.unwrap_or_default() {
query.filter(name_filter.or(title_filter))
} else {
query.filter(name_filter.or(title_filter.or(description_filter)))
}
}
// Hide deleted and removed for non-admins or mods
@ -229,6 +234,7 @@ pub struct CommunityQuery<'a> {
pub sort: Option<PostSortType>,
pub local_user: Option<&'a LocalUser>,
pub search_term: Option<String>,
pub title_only: Option<bool>,
pub is_mod_or_admin: bool,
pub show_nsfw: bool,
pub page: Option<i64>,