about summary refs log tree commit diff
path: root/src/handlers.rs
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2018-04-14T20·06+0200
committerVincent Ambo <github@tazj.in>2018-04-14T20·21+0200
commit4132869277656437f1f62869a2b1676d4c1c42d7 (patch)
tree6ee6a8302e4712bc8aca47e8c021063ad338b0bf /src/handlers.rs
parentdae97fdaf5a9541895d9719f1f58902cca846e2b (diff)
feat: Implement search result view & enable search
Implements a very simple and currently kinda broken-looking search
result view.
Diffstat (limited to 'src/handlers.rs')
-rw-r--r--src/handlers.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index 33f33deccb87..02ff99394edf 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -176,6 +176,22 @@ pub fn reply_thread(state: State<AppState>,
         .responder()
 }
 
+/// This handler executes a full-text search on the forum database and
+/// displays the results to the user.
+pub fn search_forum(state: State<AppState>,
+                    query: Form<SearchPosts>) -> ConverseResponse {
+    let query_string = query.0.query.clone();
+    state.db.send(query.0)
+        .flatten()
+        .and_then(move |results| state.renderer.send(SearchResultPage {
+            results,
+            query: query_string,
+        }).from_err())
+        .flatten()
+        .map(|res| HttpResponse::Ok().content_type(HTML).body(res))
+        .responder()
+}
+
 /// This handler initiates an OIDC login.
 pub fn login(state: State<AppState>) -> ConverseResponse {
     state.oidc.send(GetLoginUrl)