Adding optional community_name field to search. Fixes #1057
This commit is contained in:
parent
4d0365bca3
commit
c348e788e4
6 changed files with 18 additions and 12 deletions
|
@ -12,9 +12,9 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^26.0.14",
|
"@types/jest": "^26.0.14",
|
||||||
"jest": "^26.4.2",
|
"jest": "^26.4.2",
|
||||||
"lemmy-js-client": "^1.0.13",
|
"lemmy-js-client": "^1.0.14",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
"ts-jest": "^26.4.0",
|
"ts-jest": "^26.4.1",
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2360,10 +2360,10 @@ kleur@^3.0.3:
|
||||||
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
|
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
|
||||||
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
|
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
|
||||||
|
|
||||||
lemmy-js-client@^1.0.13:
|
lemmy-js-client@^1.0.14:
|
||||||
version "1.0.13"
|
version "1.0.14"
|
||||||
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-1.0.13.tgz#d0e1246129ade295faeec1fb4b2c7397d6947a19"
|
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-1.0.14.tgz#81a847dd0c7d97c83913f198717498c223dc371e"
|
||||||
integrity sha512-Xz87cCswi/2pbDdApw9JIy8bDWRFGiGWO6IhehTytOAzf36dr4GYgsjTQTLjBX+s+BNYr8hE0+Sz4g9c+ynoJg==
|
integrity sha512-hiGxAnAD5RFmE8qHMBtYNNYD/UrfCZ5JzmVEH/i5Vg/v5i/ZVmebx20uWtRMmdSSy6s4GbW0w4niszLW6SaJ3Q==
|
||||||
|
|
||||||
leven@^3.1.0:
|
leven@^3.1.0:
|
||||||
version "3.1.0"
|
version "3.1.0"
|
||||||
|
@ -3382,10 +3382,10 @@ tr46@^2.0.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
punycode "^2.1.1"
|
punycode "^2.1.1"
|
||||||
|
|
||||||
ts-jest@^26.4.0:
|
ts-jest@^26.4.1:
|
||||||
version "26.4.0"
|
version "26.4.1"
|
||||||
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-26.4.0.tgz#903c7827f3d3bc33efc2f91be294b164400c32e3"
|
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-26.4.1.tgz#08ec0d3fc2c3a39e4a46eae5610b69fafa6babd0"
|
||||||
integrity sha512-ofBzoCqf6Nv/PoWb/ByV3VNKy2KJSikamOBxvR3E6eVdIw10GwAXoyvMWXXjZJK2s6S27ZE8fI+JBTnGaovl6Q==
|
integrity sha512-F4aFq01aS6mnAAa0DljNmKr/Kk9y4HVZ1m6/rtJ0ED56cuxINGq3Q9eVAh+z5vcYKe5qnTMvv90vE8vUMFxomg==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/jest" "26.x"
|
"@types/jest" "26.x"
|
||||||
bs-logger "0.x"
|
bs-logger "0.x"
|
||||||
|
|
|
@ -921,6 +921,7 @@ Search types are `All, Comments, Posts, Communities, Users, Url`
|
||||||
q: String,
|
q: String,
|
||||||
type_: String,
|
type_: String,
|
||||||
community_id: Option<i32>,
|
community_id: Option<i32>,
|
||||||
|
community_name: Option<String>,
|
||||||
sort: String,
|
sort: String,
|
||||||
page: Option<i64>,
|
page: Option<i64>,
|
||||||
limit: Option<i64>,
|
limit: Option<i64>,
|
||||||
|
|
|
@ -357,6 +357,7 @@ impl Perform for Search {
|
||||||
let limit = data.limit;
|
let limit = data.limit;
|
||||||
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;
|
||||||
|
let community_name = data.community_name.to_owned();
|
||||||
match type_ {
|
match type_ {
|
||||||
SearchType::Posts => {
|
SearchType::Posts => {
|
||||||
posts = blocking(context.pool(), move |conn| {
|
posts = blocking(context.pool(), move |conn| {
|
||||||
|
@ -364,6 +365,7 @@ impl Perform for Search {
|
||||||
.sort(&sort)
|
.sort(&sort)
|
||||||
.show_nsfw(true)
|
.show_nsfw(true)
|
||||||
.for_community_id(community_id)
|
.for_community_id(community_id)
|
||||||
|
.for_community_name(community_name)
|
||||||
.search_term(q)
|
.search_term(q)
|
||||||
.my_user_id(user_id)
|
.my_user_id(user_id)
|
||||||
.page(page)
|
.page(page)
|
||||||
|
@ -412,6 +414,7 @@ impl Perform for Search {
|
||||||
.sort(&sort)
|
.sort(&sort)
|
||||||
.show_nsfw(true)
|
.show_nsfw(true)
|
||||||
.for_community_id(community_id)
|
.for_community_id(community_id)
|
||||||
|
.for_community_name(community_name)
|
||||||
.search_term(q)
|
.search_term(q)
|
||||||
.my_user_id(user_id)
|
.my_user_id(user_id)
|
||||||
.page(page)
|
.page(page)
|
||||||
|
@ -466,6 +469,7 @@ impl Perform for Search {
|
||||||
.sort(&sort)
|
.sort(&sort)
|
||||||
.show_nsfw(true)
|
.show_nsfw(true)
|
||||||
.for_community_id(community_id)
|
.for_community_id(community_id)
|
||||||
|
.for_community_name(community_name)
|
||||||
.url_search(q)
|
.url_search(q)
|
||||||
.page(page)
|
.page(page)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
|
|
@ -273,12 +273,10 @@ impl<'a> PostQueryBuilder<'a> {
|
||||||
|
|
||||||
if let Some(for_community_id) = self.for_community_id {
|
if let Some(for_community_id) = self.for_community_id {
|
||||||
query = query.filter(community_id.eq(for_community_id));
|
query = query.filter(community_id.eq(for_community_id));
|
||||||
query = query.then_order_by(stickied.desc());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(for_community_name) = self.for_community_name {
|
if let Some(for_community_name) = self.for_community_name {
|
||||||
query = query.filter(community_name.eq(for_community_name));
|
query = query.filter(community_name.eq(for_community_name));
|
||||||
query = query.then_order_by(stickied.desc());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(url_search) = self.url_search {
|
if let Some(url_search) = self.url_search {
|
||||||
|
@ -292,6 +290,8 @@ impl<'a> PostQueryBuilder<'a> {
|
||||||
.or_filter(body.ilike(searcher));
|
.or_filter(body.ilike(searcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
query = query.then_order_by(stickied.desc());
|
||||||
|
|
||||||
query = match self.sort {
|
query = match self.sort {
|
||||||
SortType::Active => query
|
SortType::Active => query
|
||||||
.then_order_by(hot_rank_active.desc())
|
.then_order_by(hot_rank_active.desc())
|
||||||
|
|
|
@ -23,6 +23,7 @@ pub struct Search {
|
||||||
pub q: String,
|
pub q: String,
|
||||||
pub type_: String,
|
pub type_: String,
|
||||||
pub community_id: Option<i32>,
|
pub community_id: Option<i32>,
|
||||||
|
pub community_name: Option<String>,
|
||||||
pub sort: String,
|
pub sort: String,
|
||||||
pub page: Option<i64>,
|
pub page: Option<i64>,
|
||||||
pub limit: Option<i64>,
|
pub limit: Option<i64>,
|
||||||
|
|
Loading…
Reference in a new issue