Parcourir la source

Add text field to search queries

Zed il y a 7 ans
Parent
commit
0c1b8b0190
3 fichiers modifiés avec 10 ajouts et 3 suppressions
  1. 1 1
      src/routes/timeline.nim
  2. 8 2
      src/search.nim
  3. 1 0
      src/types.nim

+ 1 - 1
src/routes/timeline.nim

@@ -84,7 +84,7 @@ proc createTimelineRouter*(cfg: Config) =
 
     get "/@name/search":
       cond '.' notin @"name"
-      let query = initQuery(@"filter", @"include", @"not", @"sep", @"name")
+      let query = initQuery(@"filter", @"include", @"not", @"sep", @"text", @"name")
       respTimeline(await showTimeline(@"name", @"after", some(query),
                                       cookiePrefs(), getPath(), cfg.title, ""))
 

+ 8 - 2
src/search.nim

@@ -18,10 +18,12 @@ const
   posPrefix = "thGAVUV0VFVBa"
   posSuffix = "EjUAFQAlAFUAFQAA"
 
-proc initQuery*(filters, includes, excludes, separator: string; name=""): Query =
+proc initQuery*(filters, includes, excludes, separator, text: string;
+                name=""): Query =
   var sep = separator.strip().toUpper()
   Query(
     kind: custom,
+    text: text,
     filters: filters.split(",").filterIt(it in validFilters),
     includes: includes.split(",").filterIt(it in validFilters),
     excludes: excludes.split(",").filterIt(it in validFilters),
@@ -60,7 +62,9 @@ proc genQueryParam*(query: Query): string =
   for e in query.excludes:
     filters.add "-filter:" & e
 
-  return strip(param & filters.join(&" {query.sep} "))
+  result = strip(param & filters.join(&" {query.sep} "))
+  if query.text.len > 0:
+    result &= " " & query.text
 
 proc genQueryUrl*(query: Query): string =
   if query.kind == multi: return "?"
@@ -77,6 +81,8 @@ proc genQueryUrl*(query: Query): string =
     params &= "not=" & query.excludes.join(",")
   if query.sep.len > 0:
     params &= "sep=" & query.sep
+  if query.text.len > 0:
+    params &= "text=" & query.text
   if params.len > 0:
     result &= params.join("&") & "&"
 

+ 1 - 0
src/types.nim

@@ -61,6 +61,7 @@ type
 
   Query* = object
     kind*: QueryKind
+    text*: string
     filters*: seq[string]
     includes*: seq[string]
     excludes*: seq[string]