mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-10 06:54:12 +00:00
Removing duplicate Url return type for search (was actually post).
- This now works like the post_title_only filter.
This commit is contained in:
parent
601a0da9fd
commit
d2995d4d5f
7 changed files with 50 additions and 57 deletions
|
@ -79,6 +79,7 @@ pub struct Search {
|
||||||
pub page: Option<i64>,
|
pub page: Option<i64>,
|
||||||
pub limit: Option<i64>,
|
pub limit: Option<i64>,
|
||||||
pub post_title_only: Option<bool>,
|
pub post_title_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>,
|
||||||
pub disliked_only: Option<bool>,
|
pub disliked_only: Option<bool>,
|
||||||
|
|
|
@ -999,6 +999,18 @@ fn limit_expire_time(expires: DateTime<Utc>) -> LemmyResult<Option<DateTime<Utc>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip_all)]
|
||||||
|
pub fn check_conflicting_like_filters(
|
||||||
|
liked_only: Option<bool>,
|
||||||
|
disliked_only: Option<bool>,
|
||||||
|
) -> LemmyResult<()> {
|
||||||
|
if liked_only.unwrap_or_default() && disliked_only.unwrap_or_default() {
|
||||||
|
Err(LemmyErrorType::ContradictingFilters)?
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn process_markdown(
|
pub async fn process_markdown(
|
||||||
text: &str,
|
text: &str,
|
||||||
slur_regex: &Option<Regex>,
|
slur_regex: &Option<Regex>,
|
||||||
|
|
|
@ -91,7 +91,8 @@ pub async fn get_post(
|
||||||
// Fetch the cross_posts
|
// Fetch the cross_posts
|
||||||
let cross_posts = if let Some(url) = &post_view.post.url {
|
let cross_posts = if let Some(url) = &post_view.post.url {
|
||||||
let mut x_posts = PostQuery {
|
let mut x_posts = PostQuery {
|
||||||
url_search: Some(url.inner().as_str().into()),
|
url_only: Some(true),
|
||||||
|
search_term: Some(url.inner().as_str().into()),
|
||||||
local_user: local_user.as_ref(),
|
local_user: local_user.as_ref(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,14 @@ use actix_web::web::{Json, Query};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{GetPosts, GetPostsResponse},
|
post::{GetPosts, GetPostsResponse},
|
||||||
utils::check_private_instance,
|
utils::{check_conflicting_like_filters, check_private_instance},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::community::Community;
|
use lemmy_db_schema::source::community::Community;
|
||||||
use lemmy_db_views::{
|
use lemmy_db_views::{
|
||||||
post_view::PostQuery,
|
post_view::PostQuery,
|
||||||
structs::{LocalUserView, PaginationCursor, SiteView},
|
structs::{LocalUserView, PaginationCursor, SiteView},
|
||||||
};
|
};
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType, LemmyResult};
|
use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
pub async fn list_posts(
|
pub async fn list_posts(
|
||||||
|
@ -45,9 +45,7 @@ pub async fn list_posts(
|
||||||
|
|
||||||
let liked_only = data.liked_only;
|
let liked_only = data.liked_only;
|
||||||
let disliked_only = data.disliked_only;
|
let disliked_only = data.disliked_only;
|
||||||
if liked_only.unwrap_or_default() && disliked_only.unwrap_or_default() {
|
check_conflicting_like_filters(liked_only, disliked_only)?;
|
||||||
return Err(LemmyError::from(LemmyErrorType::ContradictingFilters));
|
|
||||||
}
|
|
||||||
|
|
||||||
let local_user = local_user_view.as_ref().map(|u| &u.local_user);
|
let local_user = local_user_view.as_ref().map(|u| &u.local_user);
|
||||||
let listing_type = Some(listing_type_with_default(
|
let listing_type = Some(listing_type_with_default(
|
||||||
|
|
|
@ -4,7 +4,7 @@ use actix_web::web::{Json, Query};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
site::{Search, SearchResponse},
|
site::{Search, SearchResponse},
|
||||||
utils::{check_private_instance, is_admin},
|
utils::{check_conflicting_like_filters, check_private_instance, is_admin},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{source::community::Community, utils::post_to_comment_sort_type, SearchType};
|
use lemmy_db_schema::{source::community::Community, utils::post_to_comment_sort_type, SearchType};
|
||||||
use lemmy_db_views::{
|
use lemmy_db_views::{
|
||||||
|
@ -13,10 +13,7 @@ use lemmy_db_views::{
|
||||||
structs::{LocalUserView, SiteView},
|
structs::{LocalUserView, SiteView},
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::{community_view::CommunityQuery, person_view::PersonQuery};
|
use lemmy_db_views_actor::{community_view::CommunityQuery, person_view::PersonQuery};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::error::LemmyResult;
|
||||||
error::{LemmyError, LemmyResult},
|
|
||||||
LemmyErrorType,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
pub async fn search(
|
pub async fn search(
|
||||||
|
@ -58,13 +55,12 @@ pub async fn search(
|
||||||
let creator_id = data.creator_id;
|
let creator_id = data.creator_id;
|
||||||
let local_user = local_user_view.as_ref().map(|l| &l.local_user);
|
let local_user = local_user_view.as_ref().map(|l| &l.local_user);
|
||||||
let post_title_only = data.post_title_only;
|
let post_title_only = data.post_title_only;
|
||||||
|
let post_url_only = data.post_url_only;
|
||||||
let saved_only = data.saved_only;
|
let saved_only = data.saved_only;
|
||||||
|
|
||||||
let liked_only = data.liked_only;
|
let liked_only = data.liked_only;
|
||||||
let disliked_only = data.disliked_only;
|
let disliked_only = data.disliked_only;
|
||||||
if liked_only.unwrap_or_default() && disliked_only.unwrap_or_default() {
|
check_conflicting_like_filters(liked_only, disliked_only)?;
|
||||||
return Err(LemmyError::from(LemmyErrorType::ContradictingFilters));
|
|
||||||
}
|
|
||||||
|
|
||||||
let posts_query = PostQuery {
|
let posts_query = PostQuery {
|
||||||
sort,
|
sort,
|
||||||
|
@ -72,10 +68,11 @@ pub async fn search(
|
||||||
community_id,
|
community_id,
|
||||||
creator_id,
|
creator_id,
|
||||||
local_user,
|
local_user,
|
||||||
search_term: (Some(q.clone())),
|
search_term: Some(q.clone()),
|
||||||
page,
|
page,
|
||||||
limit,
|
limit,
|
||||||
title_only: post_title_only,
|
title_only: post_title_only,
|
||||||
|
url_only: post_url_only,
|
||||||
liked_only,
|
liked_only,
|
||||||
disliked_only,
|
disliked_only,
|
||||||
saved_only,
|
saved_only,
|
||||||
|
@ -83,9 +80,9 @@ pub async fn search(
|
||||||
};
|
};
|
||||||
|
|
||||||
let comment_query = CommentQuery {
|
let comment_query = CommentQuery {
|
||||||
sort: (sort.map(post_to_comment_sort_type)),
|
sort: sort.map(post_to_comment_sort_type),
|
||||||
listing_type,
|
listing_type,
|
||||||
search_term: (Some(q.clone())),
|
search_term: Some(q.clone()),
|
||||||
community_id,
|
community_id,
|
||||||
creator_id,
|
creator_id,
|
||||||
local_user,
|
local_user,
|
||||||
|
@ -98,22 +95,22 @@ pub async fn search(
|
||||||
};
|
};
|
||||||
|
|
||||||
let community_query = CommunityQuery {
|
let community_query = CommunityQuery {
|
||||||
sort: (sort),
|
sort,
|
||||||
listing_type: (listing_type),
|
listing_type,
|
||||||
search_term: (Some(q.clone())),
|
search_term: Some(q.clone()),
|
||||||
local_user,
|
local_user,
|
||||||
is_mod_or_admin: (is_admin),
|
is_mod_or_admin: is_admin,
|
||||||
page: (page),
|
page,
|
||||||
limit: (limit),
|
limit,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let person_query = PersonQuery {
|
let person_query = PersonQuery {
|
||||||
sort,
|
sort,
|
||||||
search_term: (Some(q.clone())),
|
search_term: Some(q.clone()),
|
||||||
listing_type: (listing_type),
|
listing_type,
|
||||||
page: (page),
|
page,
|
||||||
limit: (limit),
|
limit,
|
||||||
};
|
};
|
||||||
|
|
||||||
match search_type {
|
match search_type {
|
||||||
|
@ -158,21 +155,6 @@ pub async fn search(
|
||||||
person_query.list(&mut context.pool()).await?
|
person_query.list(&mut context.pool()).await?
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
SearchType::Url => {
|
|
||||||
posts = PostQuery {
|
|
||||||
sort: (sort),
|
|
||||||
listing_type: (listing_type),
|
|
||||||
community_id: (community_id),
|
|
||||||
creator_id: (creator_id),
|
|
||||||
url_search: (Some(q)),
|
|
||||||
local_user,
|
|
||||||
page: (page),
|
|
||||||
limit: (limit),
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
.list(&local_site.site, &mut context.pool())
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
|
|
|
@ -182,7 +182,6 @@ pub enum SearchType {
|
||||||
Posts,
|
Posts,
|
||||||
Communities,
|
Communities,
|
||||||
Users,
|
Users,
|
||||||
Url,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(EnumString, Display, Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy, Hash)]
|
#[derive(EnumString, Display, Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy, Hash)]
|
||||||
|
|
|
@ -382,22 +382,22 @@ fn queries<'a>() -> Queries<
|
||||||
query = query.filter(community::hidden.eq(false));
|
query = query.filter(community::hidden.eq(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(url_search) = &options.url_search {
|
|
||||||
query = query.filter(post::url.eq(url_search));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(search_term) = &options.search_term {
|
if let Some(search_term) = &options.search_term {
|
||||||
let searcher = fuzzy_search(search_term);
|
if options.url_only.unwrap_or_default() {
|
||||||
query = if options.title_only.unwrap_or_default() {
|
query = query.filter(post::url.eq(search_term));
|
||||||
query.filter(post::name.ilike(searcher))
|
|
||||||
} else {
|
} else {
|
||||||
query.filter(
|
let searcher = fuzzy_search(search_term);
|
||||||
post::name
|
query = if options.title_only.unwrap_or_default() {
|
||||||
.ilike(searcher.clone())
|
query.filter(post::name.ilike(searcher))
|
||||||
.or(post::body.ilike(searcher)),
|
} else {
|
||||||
)
|
query.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)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !options
|
if !options
|
||||||
|
@ -617,7 +617,7 @@ pub struct PostQuery<'a> {
|
||||||
pub community_id_just_for_prefetch: bool,
|
pub community_id_just_for_prefetch: bool,
|
||||||
pub local_user: Option<&'a LocalUser>,
|
pub local_user: Option<&'a LocalUser>,
|
||||||
pub search_term: Option<String>,
|
pub search_term: Option<String>,
|
||||||
pub url_search: Option<String>,
|
pub url_only: Option<bool>,
|
||||||
pub saved_only: Option<bool>,
|
pub saved_only: Option<bool>,
|
||||||
pub liked_only: Option<bool>,
|
pub liked_only: Option<bool>,
|
||||||
pub disliked_only: Option<bool>,
|
pub disliked_only: Option<bool>,
|
||||||
|
|
Loading…
Reference in a new issue