Skip to content

Commit

Permalink
fix: when fuzzy match enabled, strong correlation data first
Browse files Browse the repository at this point in the history
  • Loading branch information
emptyOVO committed Oct 16, 2024
1 parent 6d3cb4f commit e1bf653
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand All @@ -44,7 +45,7 @@ public class TransformFunctionDocServiceImpl implements TransformFunctionDocServ

private final FuzzyScore fuzzyScore = new FuzzyScore(Locale.ENGLISH);

private static final int FUZZY_THRESHOLD = 3;
private static final int FUZZY_THRESHOLD = 5;

@Override
public PageResult<TransformFunctionDocResponse> listByCondition(TransformFunctionDocRequest request) {
Expand Down Expand Up @@ -74,6 +75,12 @@ private List<FunctionInfo> filterFunctionInfos(String type, String name, boolean
.map(n -> fuzzyMatch ? isFuzzyMatch(n, functionInfo.getFunctionName())
: functionInfo.getFunctionName().toLowerCase().contains(n.toLowerCase()))
.orElse(true))
.collect(Collectors.toList()).stream()
.sorted(fuzzyMatch ?
// strong correlation data first
Comparator.comparingInt((FunctionInfo f) -> fuzzyScore.fuzzyScore(f.getFunctionName(), name))
.reversed()
: Comparator.comparing(FunctionInfo::getFunctionName))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,10 @@ public void testTransformFunctionDocByName() {
@Test
public void testTransformFunctionDocByNameFuzzy() {
TransformFunctionDocRequest request = new TransformFunctionDocRequest();
request.setType(FunctionConstant.JSON_TYPE);

// wrong function name
request.setName("json_aray");

PageResult<TransformFunctionDocResponse> functionDocs = transformFunctionDocService.listByCondition(request);

Assertions.assertFalse(functionDocs.getList().isEmpty());
}

Expand Down

0 comments on commit e1bf653

Please sign in to comment.