Don't search for communities or users when the id is included.

additional_search_filters
Dessalines 2021-04-23 02:09:47 -04:00
parent f8cd6fd445
commit 51e181c529
1 changed files with 31 additions and 20 deletions

View File

@ -227,6 +227,9 @@ impl Perform for Search {
.await??; .await??;
} }
SearchType::All => { SearchType::All => {
// If the community is included, dont search communities or users
let community_included = data.community_id.is_some() || data.community_name.is_some();
posts = blocking(context.pool(), move |conn| { posts = blocking(context.pool(), move |conn| {
PostQueryBuilder::create(conn) PostQueryBuilder::create(conn)
.sort(sort) .sort(sort)
@ -265,29 +268,37 @@ impl Perform for Search {
let q = data.q.to_owned(); let q = data.q.to_owned();
communities = blocking(context.pool(), move |conn| { communities = if community_included {
CommunityQueryBuilder::create(conn) vec![]
.sort(sort) } else {
.listing_type(listing_type) blocking(context.pool(), move |conn| {
.search_term(q) CommunityQueryBuilder::create(conn)
.my_person_id(person_id) .sort(sort)
.page(page) .listing_type(listing_type)
.limit(limit) .search_term(q)
.list() .my_person_id(person_id)
}) .page(page)
.await??; .limit(limit)
.list()
})
.await??
};
let q = data.q.to_owned(); let q = data.q.to_owned();
users = blocking(context.pool(), move |conn| { users = if community_included {
PersonQueryBuilder::create(conn) vec![]
.sort(sort) } else {
.search_term(q) blocking(context.pool(), move |conn| {
.page(page) PersonQueryBuilder::create(conn)
.limit(limit) .sort(sort)
.list() .search_term(q)
}) .page(page)
.await??; .limit(limit)
.list()
})
.await??
};
} }
SearchType::Url => { SearchType::Url => {
posts = blocking(context.pool(), move |conn| { posts = blocking(context.pool(), move |conn| {