Improve search relevance and artist transliteration
This commit is contained in:
1 parent
db4548b115
commit
82f3eed9a0
10 files changed
+212
-12
No files matched your search
@@ -0,0 +1,55 @@
|
||||
//go:build integration
|
||||
|
||||
package search
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// Use a private index: never replace a running application's search indexes.
|
||||
func TestArtistSearchRelevance(t *testing.T) {
|
||||
url := os.Getenv("TEST_MEILI_URL")
|
||||
if url == "" {
|
||||
t.Skip("TEST_MEILI_URL is not set")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
defer cancel()
|
||||
m := NewMeili(url, os.Getenv("TEST_MEILI_KEY"))
|
||||
index := "search_test_" + uuid.New().String()
|
||||
require.NoError(t, m.call(ctx, http.MethodPost, "/indexes", map[string]any{"uid": index, "primaryKey": "id"}))
|
||||
t.Cleanup(func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
defer cancel()
|
||||
require.NoError(t, m.deleteIndexIfExists(ctx, index))
|
||||
})
|
||||
require.NoError(t, m.call(ctx, http.MethodPatch, "/indexes/"+index+"/settings", specs[0].settings))
|
||||
var docs []map[string]any
|
||||
for id, name := range map[string]string{
|
||||
"exact": "BOULEVARD DEPO", "collaboration": "Boulevard Depo X 161",
|
||||
"reversed": "Depo Boulevard", "unrelated": "Thoma Bulwer",
|
||||
"partial": "Станция бульвар малина",
|
||||
} {
|
||||
docs = append(docs, map[string]any{"id": id, "name": name, "name_translit": TranslitVariants(name), "popularity": 0})
|
||||
}
|
||||
require.NoError(t, m.call(ctx, http.MethodPost, "/indexes/"+index+"/documents", docs))
|
||||
for _, query := range []string{"boulevard depo", "бульвар депо", "боулевард депо"} {
|
||||
t.Run(query, func(t *testing.T) {
|
||||
results, err := m.MultiSearch(ctx, []MultiQuery{{IndexUID: index, Q: query, Limit: 10,
|
||||
MatchingStrategy: "all", AttributesToRetrieve: []string{"id", "name", "name_translit"}}})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, results, 1)
|
||||
require.NotEmpty(t, results[0].IDs)
|
||||
require.Equal(t, "exact", results[0].IDs[0])
|
||||
require.NotContains(t, results[0].IDs, "unrelated")
|
||||
require.NotContains(t, results[0].IDs, "partial")
|
||||
require.Contains(t, results[0].ExactIDs, "exact")
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user