From c348e788e4ce6eb0ff06b94d09a59975a5942a86 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 4 Oct 2020 19:57:35 -0500 Subject: [PATCH] Adding optional community_name field to search. Fixes #1057 --- api_tests/package.json | 4 ++-- api_tests/yarn.lock | 16 ++++++++-------- docs/src/contributing_websocket_http_api.md | 1 + lemmy_api/src/site.rs | 4 ++++ lemmy_db/src/post_view.rs | 4 ++-- lemmy_structs/src/site.rs | 1 + 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/api_tests/package.json b/api_tests/package.json index ec16cac6..5c7cd3eb 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -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" } } diff --git a/api_tests/yarn.lock b/api_tests/yarn.lock index e0def58b..e1ee01ac 100644 --- a/api_tests/yarn.lock +++ b/api_tests/yarn.lock @@ -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" diff --git a/docs/src/contributing_websocket_http_api.md b/docs/src/contributing_websocket_http_api.md index ca2cceba..225db0bf 100644 --- a/docs/src/contributing_websocket_http_api.md +++ b/docs/src/contributing_websocket_http_api.md @@ -921,6 +921,7 @@ Search types are `All, Comments, Posts, Communities, Users, Url` q: String, type_: String, community_id: Option, + community_name: Option, sort: String, page: Option, limit: Option, diff --git a/lemmy_api/src/site.rs b/lemmy_api/src/site.rs index 34bdd096..6d504f26 100644 --- a/lemmy_api/src/site.rs +++ b/lemmy_api/src/site.rs @@ -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) diff --git a/lemmy_db/src/post_view.rs b/lemmy_db/src/post_view.rs index 8f606b22..128def96 100644 --- a/lemmy_db/src/post_view.rs +++ b/lemmy_db/src/post_view.rs @@ -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()) diff --git a/lemmy_structs/src/site.rs b/lemmy_structs/src/site.rs index b82b325e..3f185928 100644 --- a/lemmy_structs/src/site.rs +++ b/lemmy_structs/src/site.rs @@ -23,6 +23,7 @@ pub struct Search { pub q: String, pub type_: String, pub community_id: Option, + pub community_name: Option, pub sort: String, pub page: Option, pub limit: Option, -- 2.44.1