mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-08 02:02:04 +00:00
Backport https://github.com/go-gitea/gitea/pull/29740 (based on #29671 ...) (cherry picked from commit 0cbbcf20e3f83413a88fe3d436451d707639fe55)
This commit is contained in:
parent
655302fc96
commit
a876ac2c79
2 changed files with 29 additions and 1 deletions
|
@ -5,6 +5,7 @@ package meilisearch
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -210,7 +211,11 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
|
|||
|
||||
skip, limit := indexer_internal.ParsePaginator(options.Paginator, maxTotalHits)
|
||||
|
||||
searchRes, err := b.inner.Client.Index(b.inner.VersionedIndexName()).Search(options.Keyword, &meilisearch.SearchRequest{
|
||||
// to make it non fuzzy ("typo tolerance" in meilisearch terms), we have to quote the keyword(s)
|
||||
// https://www.meilisearch.com/docs/reference/api/search#phrase-search
|
||||
keyword := doubleQuoteKeyword(options.Keyword)
|
||||
|
||||
searchRes, err := b.inner.Client.Index(b.inner.VersionedIndexName()).Search(keyword, &meilisearch.SearchRequest{
|
||||
Filter: query.Statement(),
|
||||
Limit: int64(limit),
|
||||
Offset: int64(skip),
|
||||
|
@ -241,3 +246,16 @@ func parseSortBy(sortBy internal.SortBy) string {
|
|||
}
|
||||
return field + ":asc"
|
||||
}
|
||||
|
||||
func doubleQuoteKeyword(k string) string {
|
||||
kp := strings.Split(k, " ")
|
||||
parts := 0
|
||||
for i := range kp {
|
||||
part := strings.Trim(kp[i], "\"")
|
||||
if part != "" {
|
||||
kp[parts] = fmt.Sprintf(`"%s"`, part)
|
||||
parts++
|
||||
}
|
||||
}
|
||||
return strings.Join(kp[:parts], " ")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue