@@ -10,6 +10,7 @@ import (
10
10
"net/http"
11
11
"net/url"
12
12
"strconv"
13
+ "strings"
13
14
"time"
14
15
15
16
"github.com/go-chi/chi/v5"
@@ -60,9 +61,13 @@ func NewClient(serverURL string) *Client {
60
61
return & Client {client : client , serverURL : serverURL }
61
62
}
62
63
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 ) {
64
65
// 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 ())
66
71
67
72
// Create request
68
73
req , err := http .NewRequest ("GET" , urlStr , nil )
@@ -149,7 +154,18 @@ func searchHandler(dbPath string) http.HandlerFunc {
149
154
hosts = append (hosts , host )
150
155
}
151
156
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 )
153
169
if err != nil {
154
170
statusJSON (http .StatusInternalServerError , err , w , r )
155
171
return
0 commit comments