mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-29 12:51:03 +00: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
4 changed files with 17 additions and 12 deletions
|
@ -78,7 +78,7 @@ pub struct Search {
|
||||||
pub listing_type: Option<ListingType>,
|
pub listing_type: Option<ListingType>,
|
||||||
pub page: Option<i64>,
|
pub page: Option<i64>,
|
||||||
pub limit: Option<i64>,
|
pub limit: Option<i64>,
|
||||||
pub post_title_only: Option<bool>,
|
pub title_only: Option<bool>,
|
||||||
pub post_url_only: Option<bool>,
|
pub post_url_only: Option<bool>,
|
||||||
pub saved_only: Option<bool>,
|
pub saved_only: Option<bool>,
|
||||||
pub liked_only: Option<bool>,
|
pub liked_only: Option<bool>,
|
||||||
|
|
|
@ -47,7 +47,7 @@ pub async fn search(
|
||||||
listing_type,
|
listing_type,
|
||||||
page,
|
page,
|
||||||
limit,
|
limit,
|
||||||
post_title_only,
|
title_only,
|
||||||
post_url_only,
|
post_url_only,
|
||||||
saved_only,
|
saved_only,
|
||||||
liked_only,
|
liked_only,
|
||||||
|
@ -78,7 +78,7 @@ pub async fn search(
|
||||||
search_term: Some(q.clone()),
|
search_term: Some(q.clone()),
|
||||||
page,
|
page,
|
||||||
limit,
|
limit,
|
||||||
title_only: post_title_only,
|
title_only,
|
||||||
url_only: post_url_only,
|
url_only: post_url_only,
|
||||||
liked_only,
|
liked_only,
|
||||||
disliked_only,
|
disliked_only,
|
||||||
|
@ -105,6 +105,7 @@ pub async fn search(
|
||||||
sort,
|
sort,
|
||||||
listing_type,
|
listing_type,
|
||||||
search_term: Some(q.clone()),
|
search_term: Some(q.clone()),
|
||||||
|
title_only,
|
||||||
local_user,
|
local_user,
|
||||||
is_mod_or_admin: is_admin,
|
is_mod_or_admin: is_admin,
|
||||||
page,
|
page,
|
||||||
|
|
|
@ -394,14 +394,12 @@ fn queries<'a>() -> Queries<
|
||||||
query = query.filter(post::url.eq(search_term));
|
query = query.filter(post::url.eq(search_term));
|
||||||
} else {
|
} else {
|
||||||
let searcher = fuzzy_search(search_term);
|
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 = if options.title_only.unwrap_or_default() {
|
||||||
query.filter(post::name.ilike(searcher))
|
query.filter(name_filter)
|
||||||
} else {
|
} else {
|
||||||
query.filter(
|
query.filter(name_filter.or(body_filter))
|
||||||
post::name
|
|
||||||
.ilike(searcher.clone())
|
|
||||||
.or(post::body.ilike(searcher)),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
.filter(not(post::removed.or(post::deleted)));
|
.filter(not(post::removed.or(post::deleted)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,9 +112,14 @@ fn queries<'a>() -> Queries<
|
||||||
|
|
||||||
if let Some(search_term) = options.search_term {
|
if let Some(search_term) = options.search_term {
|
||||||
let searcher = fuzzy_search(&search_term);
|
let searcher = fuzzy_search(&search_term);
|
||||||
query = query
|
let name_filter = community::name.ilike(searcher.clone());
|
||||||
.filter(community::name.ilike(searcher.clone()))
|
let title_filter = community::title.ilike(searcher.clone());
|
||||||
.or_filter(community::title.ilike(searcher))
|
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
|
// Hide deleted and removed for non-admins or mods
|
||||||
|
@ -229,6 +234,7 @@ pub struct CommunityQuery<'a> {
|
||||||
pub sort: Option<PostSortType>,
|
pub sort: Option<PostSortType>,
|
||||||
pub local_user: Option<&'a LocalUser>,
|
pub local_user: Option<&'a LocalUser>,
|
||||||
pub search_term: Option<String>,
|
pub search_term: Option<String>,
|
||||||
|
pub title_only: Option<bool>,
|
||||||
pub is_mod_or_admin: bool,
|
pub is_mod_or_admin: bool,
|
||||||
pub show_nsfw: bool,
|
pub show_nsfw: bool,
|
||||||
pub page: Option<i64>,
|
pub page: Option<i64>,
|
||||||
|
|
Loading…
Reference in a new issue