mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-01 01:36:12 -04:00
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:
parent
a65be776e3
commit
0fab5bed24
@ -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>,
|
||||
|
@ -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,
|
||||
|
@ -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)));
|
||||
}
|
||||
|
@ -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>,
|
||||
|
Loading…
Reference in New Issue
Block a user