Merge pull request #1174 from LemmyNet/add_community_name_search

Adding optional community_name field to search. Fixes #1057
pull/1176/head
Nutomic 2020-10-05 15:55:33 +00:00 committed by GitHub
commit dc18ec533e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 12 deletions

View File

@ -12,9 +12,9 @@
"devDependencies": {
"@types/jest": "^26.0.14",
"jest": "^26.4.2",
"lemmy-js-client": "^1.0.13",
"lemmy-js-client": "^1.0.14",
"node-fetch": "^2.6.1",
"ts-jest": "^26.4.0",
"ts-jest": "^26.4.1",
"typescript": "^4.0.3"
}
}

View File

@ -2360,10 +2360,10 @@ kleur@^3.0.3:
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
lemmy-js-client@^1.0.13:
version "1.0.13"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-1.0.13.tgz#d0e1246129ade295faeec1fb4b2c7397d6947a19"
integrity sha512-Xz87cCswi/2pbDdApw9JIy8bDWRFGiGWO6IhehTytOAzf36dr4GYgsjTQTLjBX+s+BNYr8hE0+Sz4g9c+ynoJg==
lemmy-js-client@^1.0.14:
version "1.0.14"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-1.0.14.tgz#81a847dd0c7d97c83913f198717498c223dc371e"
integrity sha512-hiGxAnAD5RFmE8qHMBtYNNYD/UrfCZ5JzmVEH/i5Vg/v5i/ZVmebx20uWtRMmdSSy6s4GbW0w4niszLW6SaJ3Q==
leven@^3.1.0:
version "3.1.0"
@ -3382,10 +3382,10 @@ tr46@^2.0.2:
dependencies:
punycode "^2.1.1"
ts-jest@^26.4.0:
version "26.4.0"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-26.4.0.tgz#903c7827f3d3bc33efc2f91be294b164400c32e3"
integrity sha512-ofBzoCqf6Nv/PoWb/ByV3VNKy2KJSikamOBxvR3E6eVdIw10GwAXoyvMWXXjZJK2s6S27ZE8fI+JBTnGaovl6Q==
ts-jest@^26.4.1:
version "26.4.1"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-26.4.1.tgz#08ec0d3fc2c3a39e4a46eae5610b69fafa6babd0"
integrity sha512-F4aFq01aS6mnAAa0DljNmKr/Kk9y4HVZ1m6/rtJ0ED56cuxINGq3Q9eVAh+z5vcYKe5qnTMvv90vE8vUMFxomg==
dependencies:
"@types/jest" "26.x"
bs-logger "0.x"

View File

@ -921,6 +921,7 @@ Search types are `All, Comments, Posts, Communities, Users, Url`
q: String,
type_: String,
community_id: Option<i32>,
community_name: Option<String>,
sort: String,
page: Option<i64>,
limit: Option<i64>,

View File

@ -357,6 +357,7 @@ impl Perform for Search {
let limit = data.limit;
let sort = SortType::from_str(&data.sort)?;
let community_id = data.community_id;
let community_name = data.community_name.to_owned();
match type_ {
SearchType::Posts => {
posts = blocking(context.pool(), move |conn| {
@ -364,6 +365,7 @@ impl Perform for Search {
.sort(&sort)
.show_nsfw(true)
.for_community_id(community_id)
.for_community_name(community_name)
.search_term(q)
.my_user_id(user_id)
.page(page)
@ -412,6 +414,7 @@ impl Perform for Search {
.sort(&sort)
.show_nsfw(true)
.for_community_id(community_id)
.for_community_name(community_name)
.search_term(q)
.my_user_id(user_id)
.page(page)
@ -466,6 +469,7 @@ impl Perform for Search {
.sort(&sort)
.show_nsfw(true)
.for_community_id(community_id)
.for_community_name(community_name)
.url_search(q)
.page(page)
.limit(limit)

View File

@ -273,12 +273,10 @@ impl<'a> PostQueryBuilder<'a> {
if let Some(for_community_id) = self.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 {
query = query.filter(community_name.eq(for_community_name));
query = query.then_order_by(stickied.desc());
}
if let Some(url_search) = self.url_search {
@ -292,6 +290,8 @@ impl<'a> PostQueryBuilder<'a> {
.or_filter(body.ilike(searcher));
}
query = query.then_order_by(stickied.desc());
query = match self.sort {
SortType::Active => query
.then_order_by(hot_rank_active.desc())

View File

@ -23,6 +23,7 @@ pub struct Search {
pub q: String,
pub type_: String,
pub community_id: Option<i32>,
pub community_name: Option<String>,
pub sort: String,
pub page: Option<i64>,
pub limit: Option<i64>,