Add text field to search queries

This commit is contained in:
Zed 2019-09-13 13:20:08 +02:00
parent 12695b393e
commit 0c1b8b0190
3 changed files with 10 additions and 3 deletions

View file

@ -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, ""))

View file

@ -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("&") & "&"

View file

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