milvus/internal/util/ctokenizer/text_schema_validator_test.go
Jiquan Long 89bf226f0b
feat: support keyword text match (#35923)
fix: #35922

---------

Signed-off-by: longjiquan <jiquan.long@zilliz.com>
2024-09-10 15:11:08 +08:00

80 lines
1.5 KiB
Go

package ctokenizer
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
)
func TestValidateTextSchema(t *testing.T) {
type args struct {
fieldSchema *schemapb.FieldSchema
}
tests := []struct {
name string
args args
errIsNil bool
}{
{
args: args{
fieldSchema: &schemapb.FieldSchema{
FieldID: 101,
TypeParams: []*commonpb.KeyValuePair{},
},
},
errIsNil: true,
},
{
// default
args: args{
fieldSchema: &schemapb.FieldSchema{
FieldID: 101,
TypeParams: []*commonpb.KeyValuePair{
{Key: "enable_match", Value: "true"},
},
},
},
errIsNil: true,
},
{
// default
args: args{
fieldSchema: &schemapb.FieldSchema{
FieldID: 101,
TypeParams: []*commonpb.KeyValuePair{
{Key: "enable_match", Value: "true"},
{Key: "analyzer_params", Value: `{"tokenizer": "default"}`},
},
},
},
errIsNil: true,
},
{
// jieba
args: args{
fieldSchema: &schemapb.FieldSchema{
FieldID: 101,
TypeParams: []*commonpb.KeyValuePair{
{Key: "enable_match", Value: "true"},
{Key: "analyzer_params", Value: `{"tokenizer": "jieba"}`},
},
},
},
errIsNil: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := ValidateTextSchema(tt.args.fieldSchema)
if tt.errIsNil {
assert.Nil(t, err)
} else {
assert.NotNil(t, err)
}
})
}
}