mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-02 03:48:37 +08:00
12951f0abb
relate: https://github.com/milvus-io/milvus/issues/35853 --------- Signed-off-by: aoiasd <zhicheng.yue@zilliz.com>
38 lines
920 B
Go
38 lines
920 B
Go
package ctokenizer
|
|
|
|
/*
|
|
#cgo pkg-config: milvus_core
|
|
#include <stdlib.h> // free
|
|
#include "segcore/tokenizer_c.h"
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"fmt"
|
|
"unsafe"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
|
"github.com/milvus-io/milvus/pkg/util/typeutil"
|
|
)
|
|
|
|
func ValidateTextSchema(fieldSchema *schemapb.FieldSchema, EnableBM25 bool) error {
|
|
h := typeutil.CreateFieldSchemaHelper(fieldSchema)
|
|
if !h.EnableMatch() && !EnableBM25 {
|
|
return nil
|
|
}
|
|
|
|
if !h.EnableAnalyzer() {
|
|
return fmt.Errorf("field %s is set to enable match or bm25 function but not enable analyzer", fieldSchema.Name)
|
|
}
|
|
|
|
bs, err := proto.Marshal(fieldSchema)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to marshal field schema: %w", err)
|
|
}
|
|
|
|
status := C.validate_text_schema((*C.uint8_t)(unsafe.Pointer(&bs[0])), (C.uint64_t)(len(bs)))
|
|
return HandleCStatus(&status, "failed to validate text schema")
|
|
}
|