搜索算法
SearchMatch 是一个接口,用于匹配 文本 与 模式。匹配结果存储在返回值 SearchMatchResult 中。匹配结果包含有关匹配位置和整体匹配得分的信息。
fzf.
实现
模糊匹配V2搜索
fzf FuzzyMatchV2Search 算法的移植。能够快速进行模糊搜索,擅长迅速查找路径。
ExactMatchNaive
Port of fzf ExactMatchNaive algorithm. Simple exact match works more accurately if you know what to search.
搜索匹配
算法和默认语法被隐藏在受保护的类中,因为我们不想完全公开这些内容直到我们确定API可以长期支持。你需要通过内置构建器构造SearchMatch。
SearchMatch searchMatch = SearchMatch.builder().caseSensitive(false).normalize(false).forward(true).build();
可以配置区分大小写,搜索的方向或在搜索发生前是否应该对文本进行规范化。当不同语言的字符类型有轻微差异时,规范化非常有用。
搜索算法是根据下面表格中所示的搜索语法选定的。
| Tokens | 匹配类型 | 描述 |
|---|---|---|
|
fuzzy-match |
匹配项 |
|
exact-match |
包含 |
示例
SearchMatch searchMatch = SearchMatch.builder().caseSensitive(false).normalize(false).forward(true).build();
SearchMatchResult result = searchMatch.match("foo bar baz", "fbb");
result.getStart();
// 0 - start position inclusive
result.getEnd();
// 9 - end position exclusive
result.getPositions();
// 0,4,8 - positions, inclusive
result.getScore();
// 112 - score
result.getAlgorithm();
// FuzzyMatchV2SearchMatchAlgorithm - resolved algo