+30
-2
search/query.go
+30
-2
search/query.go
···
7
7
"fmt"
8
8
"io/ioutil"
9
9
"log/slog"
10
+
"strings"
10
11
11
12
"github.com/bluesky-social/indigo/atproto/identity"
12
13
"github.com/bluesky-social/indigo/atproto/syntax"
···
275
276
276
277
filters := params.Filters()
277
278
278
-
basic := map[string]interface{}{
279
+
fulltext := map[string]interface{}{
279
280
"simple_query_string": map[string]interface{}{
280
281
"query": params.Query,
281
282
"fields": []string{"everything"},
···
285
286
"analyze_wildcard": false,
286
287
},
287
288
}
289
+
primary := fulltext
290
+
291
+
// if the query string is just a single token (after parsing out filter
292
+
// syntax), then have the primary query be an "OR" of the basic fulltext
293
+
// query and the typeahead query
294
+
if len(strings.Split(params.Query, " ")) == 1 {
295
+
typeahead := map[string]interface{}{
296
+
"multi_match": map[string]interface{}{
297
+
"query": params.Query,
298
+
"type": "bool_prefix",
299
+
"operator": "and",
300
+
"fields": []string{
301
+
"typeahead",
302
+
"typeahead._2gram",
303
+
"typeahead._3gram",
304
+
},
305
+
},
306
+
}
307
+
primary = map[string]interface{}{
308
+
"bool": map[string]interface{}{
309
+
"should": []interface{}{
310
+
fulltext,
311
+
typeahead,
312
+
},
313
+
},
314
+
}
315
+
}
288
316
289
317
query := map[string]interface{}{
290
318
"query": map[string]interface{}{
291
319
"bool": map[string]interface{}{
292
-
"must": basic,
320
+
"must": primary,
293
321
"should": []interface{}{
294
322
map[string]interface{}{"term": map[string]interface{}{"has_avatar": true}},
295
323
map[string]interface{}{"term": map[string]interface{}{"has_banner": true}},