@@ -5,6 +5,7 @@ package meilisearch
5
5
6
6
import (
7
7
"context"
8
+ "fmt"
8
9
"strconv"
9
10
"strings"
10
11
@@ -210,7 +211,14 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
210
211
211
212
skip , limit := indexer_internal .ParsePaginator (options .Paginator , maxTotalHits )
212
213
213
- searchRes , err := b .inner .Client .Index (b .inner .VersionedIndexName ()).Search (options .Keyword , & meilisearch.SearchRequest {
214
+ keyword := options .Keyword
215
+ if ! options .IsFuzzyKeyword {
216
+ // to make it non fuzzy ("typo tolerance" in meilisearch terms), we have to quote the keyword(s)
217
+ // https://www.meilisearch.com/docs/reference/api/search#phrase-search
218
+ keyword = doubleQuoteKeyword (keyword )
219
+ }
220
+
221
+ searchRes , err := b .inner .Client .Index (b .inner .VersionedIndexName ()).Search (keyword , & meilisearch.SearchRequest {
214
222
Filter : query .Statement (),
215
223
Limit : int64 (limit ),
216
224
Offset : int64 (skip ),
@@ -241,3 +249,16 @@ func parseSortBy(sortBy internal.SortBy) string {
241
249
}
242
250
return field + ":asc"
243
251
}
252
+
253
+ func doubleQuoteKeyword (k string ) string {
254
+ kp := strings .Split (k , " " )
255
+ parts := 0
256
+ for i := range kp {
257
+ part := strings .Trim (kp [i ], "\" " )
258
+ if part != "" {
259
+ kp [parts ] = fmt .Sprintf (`"%s"` , part )
260
+ parts ++
261
+ }
262
+ }
263
+ return strings .Join (kp [:parts ], " " )
264
+ }
0 commit comments