此版本仍在开发中,尚未被认为是稳定版。请使用最新稳定版 Spring Shell 4.0.1spring-doc.cadn.net.cn

搜索算法

SearchMatch 是一个接口,用于匹配 文本模式。匹配结果存储在返回值 SearchMatchResult 中。匹配结果包含有关匹配位置和整体匹配得分的信息。spring-doc.cadn.net.cn

实现

模糊匹配V2搜索spring-doc.cadn.net.cn

fzf FuzzyMatchV2Search 算法的移植。能够快速进行模糊搜索,擅长迅速查找路径。spring-doc.cadn.net.cn

ExactMatchNaivespring-doc.cadn.net.cn

Port of fzf ExactMatchNaive algorithm. Simple exact match works more accurately if you know what to search.spring-doc.cadn.net.cn

搜索匹配

算法和默认语法被隐藏在受保护的类中,因为我们不想完全公开这些内容直到我们确定API可以长期支持。你需要通过内置构建器构造SearchMatchspring-doc.cadn.net.cn

SearchMatch searchMatch = SearchMatch.builder().caseSensitive(false).normalize(false).forward(true).build();

可以配置区分大小写,搜索的方向或在搜索发生前是否应该对文本进行规范化。当不同语言的字符类型有轻微差异时,规范化非常有用。spring-doc.cadn.net.cn

搜索算法是根据下面表格中所示的搜索语法选定的。spring-doc.cadn.net.cn

表格1. 搜索语法
Tokens 匹配类型 描述

hellspring-doc.cadn.net.cn

fuzzy-matchspring-doc.cadn.net.cn

匹配项 hellospring-doc.cadn.net.cn

'stuffspring-doc.cadn.net.cn

exact-matchspring-doc.cadn.net.cn

包含stuff的项spring-doc.cadn.net.cn

示例

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