FullTextSearch

class FullTextSearch<T>(items: Iterable<T>, tokenizer: SearchTokenizer = SearchTokenizer.Default, fields: (T) -> Iterable<String>)

多字段、内存全文检索索引

fields 在构建时对每个 item 调用一次并立即复制。索引保存文本快照和原 item 引用; item 后续变更不会自动更新索引,应重新构建。每个输入位置是一个文档;一个文档命中多次 也只返回一次,结果始终按输入顺序排列。SearchOptions.limit 在此顺序上截取。

空字符串查询返回全部文档;其他查询保留空格和标点,不隐式 trim。 词项模式中,非空查询如果分不出词项则返回空列表。

编辑距离与索引位置以 UTF-16 Char 为单位;不做 Unicode 规范化、词干化或相关度排序。

Constructors

Link copied to clipboard
constructor(items: Iterable<T>, tokenizer: SearchTokenizer = SearchTokenizer.Default, fields: (T) -> Iterable<String>)

Properties

Link copied to clipboard
val size: Int

Functions

Link copied to clipboard
fun prepare(vararg modes: SearchMode, ignoreCase: Boolean = true): FullTextSearch<T>

提前构建指定模式的延迟索引,把首次 Exact/宽 Prefix/Fuzzy 的初始化成本放在查询之前。 无模式参数时准备全部模式;ignoreCase 选择前缀词典的大小写方向。 可以在发布索引给查询线程前调用。返回当前实例以便链式使用。

Link copied to clipboard
fun search(text: String, options: SearchOptions): List<T>
fun search(regex: Regex, limit: Int = Int.MAX_VALUE): List<T>
fun search(text: String, ignoreCase: Boolean = true, limit: Int = Int.MAX_VALUE): List<T>
fun search(text: String, maxEditDistance: Int, ignoreCase: Boolean = true, limit: Int = Int.MAX_VALUE): List<T>
fun search(text: String, mode: SearchMode, ignoreCase: Boolean = true, limit: Int = Int.MAX_VALUE): List<T>