Adding listing_type to search.

additional_search_filters
Dessalines 2021-04-09 16:35:51 -04:00
parent a42ac3e58a
commit c86f5472fb
4 changed files with 23 additions and 10 deletions

View File

@ -13,7 +13,7 @@ use lemmy_api_common::{
user_show_nsfw, user_show_nsfw,
}; };
use lemmy_apub::fetcher::search::search_by_apub_id; use lemmy_apub::fetcher::search::search_by_apub_id;
use lemmy_db_queries::{source::site::Site_, Crud, SearchType, SortType}; use lemmy_db_queries::{source::site::Site_, Crud, ListingType, SearchType, SortType};
use lemmy_db_schema::source::{moderator::*, site::Site}; use lemmy_db_schema::source::{moderator::*, site::Site};
use lemmy_db_views::{ use lemmy_db_views::{
comment_view::CommentQueryBuilder, comment_view::CommentQueryBuilder,
@ -144,8 +144,6 @@ impl Perform for Search {
let person_id = local_user_view.map(|u| u.person.id); let person_id = local_user_view.map(|u| u.person.id);
let type_ = SearchType::from_str(&data.type_)?;
let mut posts = Vec::new(); let mut posts = Vec::new();
let mut comments = Vec::new(); let mut comments = Vec::new();
let mut communities = Vec::new(); let mut communities = Vec::new();
@ -157,9 +155,10 @@ impl Perform for Search {
let page = data.page; let page = data.page;
let limit = data.limit; let limit = data.limit;
let sort = SortType::from_str(&data.sort)?; let sort = SortType::from_str(&data.sort)?;
let type_ = SearchType::from_str(&data.type_)?;
let listing_type = ListingType::from_str(&data.listing_type)?;
let community_id = data.community_id; let community_id = data.community_id;
let community_name = data.community_name.to_owned(); let community_name = data.community_name.to_owned();
let community_name_2 = data.community_name.to_owned();
let creator_id = data.creator_id; let creator_id = data.creator_id;
match type_ { match type_ {
SearchType::Posts => { SearchType::Posts => {
@ -168,6 +167,8 @@ impl Perform for Search {
.sort(&sort) .sort(&sort)
.show_nsfw(show_nsfw) .show_nsfw(show_nsfw)
.show_bot_accounts(show_bot_accounts) .show_bot_accounts(show_bot_accounts)
.listing_type(&listing_type)
.show_nsfw(true)
.community_id(community_id) .community_id(community_id)
.community_name(community_name) .community_name(community_name)
.creator_id(creator_id) .creator_id(creator_id)
@ -183,6 +184,7 @@ impl Perform for Search {
comments = blocking(context.pool(), move |conn| { comments = blocking(context.pool(), move |conn| {
CommentQueryBuilder::create(&conn) CommentQueryBuilder::create(&conn)
.sort(&sort) .sort(&sort)
.listing_type(&listing_type)
.search_term(q) .search_term(q)
.show_bot_accounts(show_bot_accounts) .show_bot_accounts(show_bot_accounts)
.community_id(community_id) .community_id(community_id)
@ -199,6 +201,7 @@ impl Perform for Search {
communities = blocking(context.pool(), move |conn| { communities = blocking(context.pool(), move |conn| {
CommunityQueryBuilder::create(conn) CommunityQueryBuilder::create(conn)
.sort(&sort) .sort(&sort)
.listing_type(&listing_type)
.search_term(q) .search_term(q)
.my_person_id(person_id) .my_person_id(person_id)
.page(page) .page(page)
@ -224,6 +227,8 @@ impl Perform for Search {
.sort(&sort) .sort(&sort)
.show_nsfw(show_nsfw) .show_nsfw(show_nsfw)
.show_bot_accounts(show_bot_accounts) .show_bot_accounts(show_bot_accounts)
.listing_type(&listing_type)
.show_nsfw(true)
.community_id(community_id) .community_id(community_id)
.community_name(community_name) .community_name(community_name)
.creator_id(creator_id) .creator_id(creator_id)
@ -237,14 +242,17 @@ impl Perform for Search {
let q = data.q.to_owned(); let q = data.q.to_owned();
let sort = SortType::from_str(&data.sort)?; let sort = SortType::from_str(&data.sort)?;
let listing_type = ListingType::from_str(&data.listing_type)?;
let community_name = data.community_name.to_owned();
comments = blocking(context.pool(), move |conn| { comments = blocking(context.pool(), move |conn| {
CommentQueryBuilder::create(conn) CommentQueryBuilder::create(conn)
.sort(&sort) .sort(&sort)
.listing_type(&listing_type)
.search_term(q) .search_term(q)
.show_bot_accounts(show_bot_accounts) .show_bot_accounts(show_bot_accounts)
.community_id(community_id) .community_id(community_id)
.community_name(community_name_2) .community_name(community_name)
.creator_id(creator_id) .creator_id(creator_id)
.my_person_id(person_id) .my_person_id(person_id)
.page(page) .page(page)
@ -255,10 +263,12 @@ impl Perform for Search {
let q = data.q.to_owned(); let q = data.q.to_owned();
let sort = SortType::from_str(&data.sort)?; let sort = SortType::from_str(&data.sort)?;
let listing_type = ListingType::from_str(&data.listing_type)?;
communities = blocking(context.pool(), move |conn| { communities = blocking(context.pool(), move |conn| {
CommunityQueryBuilder::create(conn) CommunityQueryBuilder::create(conn)
.sort(&sort) .sort(&sort)
.listing_type(&listing_type)
.search_term(q) .search_term(q)
.my_person_id(person_id) .my_person_id(person_id)
.page(page) .page(page)
@ -286,6 +296,8 @@ impl Perform for Search {
.sort(&sort) .sort(&sort)
.show_nsfw(show_nsfw) .show_nsfw(show_nsfw)
.show_bot_accounts(show_bot_accounts) .show_bot_accounts(show_bot_accounts)
.listing_type(&listing_type)
.show_nsfw(true)
.my_person_id(person_id) .my_person_id(person_id)
.community_id(community_id) .community_id(community_id)
.community_name(community_name) .community_name(community_name)

View File

@ -27,6 +27,7 @@ pub struct Search {
pub community_name: Option<String>, pub community_name: Option<String>,
pub creator_id: Option<PersonId>, pub creator_id: Option<PersonId>,
pub sort: String, pub sort: String,
pub listing_type: String,
pub page: Option<i64>, pub page: Option<i64>,
pub limit: Option<i64>, pub limit: Option<i64>,
pub auth: Option<String>, pub auth: Option<String>,

View File

@ -27,7 +27,7 @@ impl PerformCrud for GetComments {
let show_bot_accounts = user_show_bot_accounts(&local_user_view); let show_bot_accounts = user_show_bot_accounts(&local_user_view);
let person_id = local_user_view.map(|u| u.person.id); let person_id = local_user_view.map(|u| u.person.id);
let type_ = ListingType::from_str(&data.type_)?; let listing_type = ListingType::from_str(&data.type_)?;
let sort = SortType::from_str(&data.sort)?; let sort = SortType::from_str(&data.sort)?;
let community_id = data.community_id; let community_id = data.community_id;
@ -37,7 +37,7 @@ impl PerformCrud for GetComments {
let limit = data.limit; let limit = data.limit;
let comments = blocking(context.pool(), move |conn| { let comments = blocking(context.pool(), move |conn| {
CommentQueryBuilder::create(conn) CommentQueryBuilder::create(conn)
.listing_type(type_) .listing_type(&listing_type)
.sort(&sort) .sort(&sort)
.saved_only(saved_only) .saved_only(saved_only)
.community_id(community_id) .community_id(community_id)

View File

@ -172,7 +172,7 @@ impl CommentView {
pub struct CommentQueryBuilder<'a> { pub struct CommentQueryBuilder<'a> {
conn: &'a PgConnection, conn: &'a PgConnection,
listing_type: ListingType, listing_type: &'a ListingType,
sort: &'a SortType, sort: &'a SortType,
community_id: Option<CommunityId>, community_id: Option<CommunityId>,
community_name: Option<String>, community_name: Option<String>,
@ -192,7 +192,7 @@ impl<'a> CommentQueryBuilder<'a> {
pub fn create(conn: &'a PgConnection) -> Self { pub fn create(conn: &'a PgConnection) -> Self {
CommentQueryBuilder { CommentQueryBuilder {
conn, conn,
listing_type: ListingType::All, listing_type: &ListingType::All,
sort: &SortType::New, sort: &SortType::New,
community_id: None, community_id: None,
community_name: None, community_name: None,
@ -209,7 +209,7 @@ impl<'a> CommentQueryBuilder<'a> {
} }
} }
pub fn listing_type(mut self, listing_type: ListingType) -> Self { pub fn listing_type(mut self, listing_type: &'a ListingType) -> Self {
self.listing_type = listing_type; self.listing_type = listing_type;
self self
} }