make general search case insensi

This commit is contained in:
Daylin Morgan 2024-08-17 09:13:19 -05:00
parent 62dfd6ff17
commit 52b78b8f60
Signed by: daylin
GPG key ID: 950D13E9719334AD

View file

@ -1,6 +1,6 @@
import std/[strutils, sequtils, dom, uri] import std/[strutils, sequtils, uri]
import karax/[kbase, karax, karaxdsl, vdom, jstrutils, kdom] import karax/[kbase, karax, karaxdsl, vdom, jstrutils]
import ../[packages, style, context] import ../[packages, style, context]
# import ../components/package # import ../components/package
@ -33,6 +33,11 @@ proc parseQuery*(s: kstring): Query =
else: else:
result.all &= part result.all &= part
proc toLowerAscii(ks: kstring): kstring {.inline.} =
($ks).toLowerAscii().kstring
proc genericSearchString(p: NimPackage): kstring =
(@[p.url, p.name, p.description, p.tags.join(" ").kstring].join(" ").kstring).toLowerAscii()
proc searchPackages*(q: Query): seq[NimPackage] = proc searchPackages*(q: Query): seq[NimPackage] =
if q == Query(): if q == Query():
@ -40,11 +45,10 @@ proc searchPackages*(q: Query): seq[NimPackage] =
return return
for name, pkg in ctx.nimpkgs.packages: for name, pkg in ctx.nimpkgs.packages:
let searchStr = ((pkg.url & " " & pkg.name & " " & pkg.description & " " & ( let searchStr = pkg.genericSearchString()
pkg.tags).join(" ").kstring)) if (q.name notin pkg.name) or (q.license notin pkg.license) or
if (q.name notin pkg.name) or (q.tag != "".kstring and (q.tag notin pkg.tags)):
(q.license notin pkg.license) or continue
(q.tag != "".kstring and (q.tag notin pkg.tags)): continue
if q.all in searchStr: if q.all in searchStr:
result.add pkg result.add pkg