@@ -10,6 +10,7 @@ import (
1010 "net/http"
1111 "net/url"
1212 "strconv"
13+ "strings"
1314 "time"
1415
1516 "github.com/go-chi/chi/v5"
@@ -60,9 +61,13 @@ func NewClient(serverURL string) *Client {
6061 return & Client {client : client , serverURL : serverURL }
6162}
6263
63- func (c * Client ) Search (query string ) ([]* types.FileResult , error ) {
64+ func (c * Client ) Search (query string , exts [] string , hosts [] string , limit int ) ([]* types.FileResult , error ) {
6465 // Build the URL with query parameters
65- urlStr := fmt .Sprintf ("%s/search?q=%s" , c .serverURL , url .QueryEscape (query ))
66+ params := url.Values {}
67+ params .Set ("ext" , strings .Join (exts , "," ))
68+ params .Set ("host" , strings .Join (hosts , "," ))
69+ params .Set ("limit" , strconv .Itoa (limit ))
70+ urlStr := fmt .Sprintf ("%s/search?q=%s&%s" , c .serverURL , url .QueryEscape (query ), params .Encode ())
6671
6772 // Create request
6873 req , err := http .NewRequest ("GET" , urlStr , nil )
@@ -149,7 +154,18 @@ func searchHandler(dbPath string) http.HandlerFunc {
149154 hosts = append (hosts , host )
150155 }
151156
152- results , err := hsdb .Search (db , query , exts , hosts , 100 )
157+ limit := r .URL .Query ().Get ("limit" )
158+ if limit == "" {
159+ limit = "100"
160+ }
161+
162+ ilimit , err := strconv .Atoi (limit )
163+ if err != nil {
164+ statusJSON (http .StatusBadRequest , errors .New ("invalid limit parameter" ), w , r )
165+ return
166+ }
167+
168+ results , err := hsdb .Search (db , query , exts , hosts , ilimit )
153169 if err != nil {
154170 statusJSON (http .StatusInternalServerError , err , w , r )
155171 return
0 commit comments