aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--conf/clog.conf15
-rw-r--r--src/clog.c14
-rw-r--r--src/queries.h23
3 files changed, 34 insertions, 18 deletions
diff --git a/conf/clog.conf b/conf/clog.conf
index e305ca4..89e9880 100644
--- a/conf/clog.conf
+++ b/conf/clog.conf
@@ -35,11 +35,21 @@ domain * {
methods get
}
+ route ^/entries/search$ {
+ handler search_entries
+ methods get
+ }
+
route ^/entries/[a-z0-9\-]+$ {
handler get_entry
methods get
}
+ route ^/entries/[a-z0-9\-]+/edit$ {
+ handler edit_entry
+ methods get
+ }
+
route ^/entries/[a-z0-9\-]+$ {
handler update_entry
methods post
@@ -49,11 +59,6 @@ domain * {
validate post body v_text
}
- route ^/entries/[a-z0-9\-]+/edit$ {
- handler edit_entry
- methods get
- }
-
route ^/.*$ {
handler redirect
}
diff --git a/src/clog.c b/src/clog.c
index e27db22..feedd98 100644
--- a/src/clog.c
+++ b/src/clog.c
@@ -67,6 +67,7 @@ int get_index(struct http_request *req);
int get_entry(struct http_request *req);
int edit_entry(struct http_request *req);
int update_entry(struct http_request *req);
+int search_entries(struct http_request *req);
int sql_select(struct entry_query *eq);
int sql_update(const char *id, const char *title, const char *body);
@@ -407,6 +408,19 @@ out: ;
return KORE_RESULT_OK;
}
+
+int search_entries(struct http_request *req) {
+ // int err = 0;
+
+ kore_log(LOG_INFO, "search ....");
+
+ http_err_resp(req, HTTP_STATUS_OK);
+
+// out: ;
+
+ return KORE_RESULT_OK;
+}
+
int sql_select(struct entry_query *eq) {
int err = KORE_RESULT_OK;
diff --git a/src/queries.h b/src/queries.h
index f406434..a55fafb 100644
--- a/src/queries.h
+++ b/src/queries.h
@@ -8,19 +8,16 @@ const char *q_select_entries =
"FROM entries "
"ORDER BY updated_at DESC;";
-// const char *q_insert_entry =
-// "INSERT INTO entries "
-// "(title, body) "
-// "VALUES "
-// "($1, $2) "
-// "RETURNING id;";
-
-// const char *q_insert_entry_with_id =
-// "INSERT INTO entries "
-// "(id, title, body) "
-// "VALUES "
-// "($1, $2, $3) "
-// "RETURNING id;";
+const char *q_search_entries =
+"WITH query AS "
+"( "
+" SELECT id, title, created_at::DATE, updated_at::DATE, "
+" TS_RANK(search_vector, TO_TSQUERY('english', $1)) AS rank "
+" FROM entries "
+" WHERE search_vector @@ TO_TSQUERY('english', $2) "
+" ORDER BY rank DESC "
+") "
+"SELECT id, title, created_at::DATE, updated_at::DATE FROM query;";
const char *q_update_entry =
"UPDATE entries "