DGraph 全文检索

使用 语法:alloftext(predicate, "space-separated text") and anyoftext(predicate, "space-separated text") alloftext 只有包含所有token的节点会被返回(取交集 Intersect)。 anyoftext 返回包含任意token的节点。 应用带有词干和停用词的全文搜索来查找与所有或任何给定文本匹配的字符串。 实现 DGraph 使用 bleve 进行全文搜索索引。 Tokenizer 分词部分的代码在tok包。 核心的接口:Tokenizer // Tokenizer defines what a tokenizer must provide. type Tokenizer interface { // 分词器的名称.不允许重复. Name() string // Type returns the string representation of the typeID that we care about. Type() string // Tokens return tokens for a given value. The tokens shouldn't be encoded // with the byte identifier. Tokens(interface{}) ([]string, error) // Identifier returns the prefix byte for this token type. This should be // unique. The range 0x80 to 0xff (inclusive) is reserved for user-provided // custom tokenizers. Identifier() byte // IsSortable returns true if the tokenizer can be used for sorting/ordering. IsSortable() bool // IsLossy returns true if we don't store the values directly as index keys // during tokenization. If a predicate is tokenized using an IsLossy() tokenizer, // then we need to fetch the actual value and compare. IsLossy() bool } FullTextTokenizer FullTextTokenizer 类实现了全文检索的分词器。 ...

2024-04-14 · 2 min · 363 words · 车底下的猫