]> Untitled Git - lemmy.git/commitdiff
Adding optional community_name field to search. Fixes #1057
authorDessalines <tyhou13@gmx.com>
Mon, 5 Oct 2020 00:57:35 +0000 (19:57 -0500)
committerDessalines <tyhou13@gmx.com>
Mon, 5 Oct 2020 00:57:35 +0000 (19:57 -0500)
api_tests/package.json
api_tests/yarn.lock
docs/src/contributing_websocket_http_api.md
lemmy_api/src/site.rs
lemmy_db/src/post_view.rs
lemmy_structs/src/site.rs

index ec16cac662467835a2a62c8ea506b37dc24d5bbe..5c7cd3eb76b4847d68bfeeb70837853694b2225b 100644 (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"
   }
 }
index e0def58b6ddae06f44826205dcd9e409c532f3a3..e1ee01ac337737d464d54141a62998c222153ca2 100644 (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"
index ca2cceba6c5ee31f51c5b1c729665dffd4d5c9c3..225db0bf739c8c88157048a02ff9bdd89b47c7d5 100644 (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>,
index 34bdd096eb10952fdffce1320d9f70cd46bce7af..6d504f267a3f1992b2a3fdbd8490110314e40479 100644 (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)
index 8f606b2263b496808594d0276048393ca36078ee..128def96d25b55757570b34f85983ff45af541be 100644 (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())
index b82b325e30cbadfc6ea8b72b534b4321651abe26..3f185928b4b2c1fb61322fb8a74da9a96b03f6e4 100644 (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>,