milvus/internal/util/ctokenizer/c_token_stream.go
Jiquan Long 5ea2454fdf
feat: tantivy tokenizer binding (#35801)
fix: #35800

---------

Signed-off-by: longjiquan <jiquan.long@zilliz.com>
2024-09-01 17:13:03 +08:00

41 lines
739 B
Go

package ctokenizer
/*
#cgo pkg-config: milvus_core
#include <stdlib.h> // free
#include "segcore/token_stream_c.h"
*/
import "C"
import (
"unsafe"
"github.com/milvus-io/milvus/internal/util/tokenizerapi"
)
var _ tokenizerapi.TokenStream = (*CTokenStream)(nil)
type CTokenStream struct {
ptr C.CTokenStream
}
func NewCTokenStream(ptr C.CTokenStream) *CTokenStream {
return &CTokenStream{
ptr: ptr,
}
}
func (impl *CTokenStream) Advance() bool {
return bool(C.token_stream_advance(impl.ptr))
}
func (impl *CTokenStream) Token() string {
token := C.token_stream_get_token(impl.ptr)
defer C.free_token(unsafe.Pointer(token))
return C.GoString(token)
}
func (impl *CTokenStream) Destroy() {
C.free_token_stream(impl.ptr)
}