@Test public void makeQueryPrefixAndFuzzyReturnsExpectedQuery() { var givenSimpleQuery = "((java | junit) & mockito~2) | spring* | \"kotlin\""; var expectedSimpleQuery = "(((java | java~1 | java*) | (junit | junit~1 | junit*)) & mockito~2) | spring* | \"kotlin\""; var actualQuery = HibernateSimpleQueryUtils.makeQueryPrefixAndFuzzy(givenSimpleQuery); assertThat(actualQuery).isEqualTo(expectedSimpleQuery); }
public static String makeQueryPrefixAndFuzzy(@NonNull String simpleQuery) { var trimmedSimpleQuery = simpleQuery.trim(); var replaceableTermIndexPairs = getReplaceableTermsOfQuery(trimmedSimpleQuery); if(replaceableTermIndexPairs.isEmpty()) { return trimmedSimpleQuery; } var fuzzyAndPrefixQuery = trimmedSimpleQuery; var addedOffsetByReplacingTerms = 0; for(var pair : replaceableTermIndexPairs) { var termStartIndex = pair.getFirst() + addedOffsetByReplacingTerms; var termEndIndex = pair.getSecond() + addedOffsetByReplacingTerms; var termStartEndIndexPair = Pair.of(termStartIndex, termEndIndex); var preReplacementQueryLength = fuzzyAndPrefixQuery.length(); fuzzyAndPrefixQuery = replaceTermWithFuzzyAndPrefixDisjunction(termStartEndIndexPair, fuzzyAndPrefixQuery); var postReplacementQueryLength = fuzzyAndPrefixQuery.length(); addedOffsetByReplacingTerms += postReplacementQueryLength - preReplacementQueryLength; } return fuzzyAndPrefixQuery; }
HibernateSimpleQueryUtils { public static String makeQueryPrefixAndFuzzy(@NonNull String simpleQuery) { var trimmedSimpleQuery = simpleQuery.trim(); var replaceableTermIndexPairs = getReplaceableTermsOfQuery(trimmedSimpleQuery); if(replaceableTermIndexPairs.isEmpty()) { return trimmedSimpleQuery; } var fuzzyAndPrefixQuery = trimmedSimpleQuery; var addedOffsetByReplacingTerms = 0; for(var pair : replaceableTermIndexPairs) { var termStartIndex = pair.getFirst() + addedOffsetByReplacingTerms; var termEndIndex = pair.getSecond() + addedOffsetByReplacingTerms; var termStartEndIndexPair = Pair.of(termStartIndex, termEndIndex); var preReplacementQueryLength = fuzzyAndPrefixQuery.length(); fuzzyAndPrefixQuery = replaceTermWithFuzzyAndPrefixDisjunction(termStartEndIndexPair, fuzzyAndPrefixQuery); var postReplacementQueryLength = fuzzyAndPrefixQuery.length(); addedOffsetByReplacingTerms += postReplacementQueryLength - preReplacementQueryLength; } return fuzzyAndPrefixQuery; } }
HibernateSimpleQueryUtils { public static String makeQueryPrefixAndFuzzy(@NonNull String simpleQuery) { var trimmedSimpleQuery = simpleQuery.trim(); var replaceableTermIndexPairs = getReplaceableTermsOfQuery(trimmedSimpleQuery); if(replaceableTermIndexPairs.isEmpty()) { return trimmedSimpleQuery; } var fuzzyAndPrefixQuery = trimmedSimpleQuery; var addedOffsetByReplacingTerms = 0; for(var pair : replaceableTermIndexPairs) { var termStartIndex = pair.getFirst() + addedOffsetByReplacingTerms; var termEndIndex = pair.getSecond() + addedOffsetByReplacingTerms; var termStartEndIndexPair = Pair.of(termStartIndex, termEndIndex); var preReplacementQueryLength = fuzzyAndPrefixQuery.length(); fuzzyAndPrefixQuery = replaceTermWithFuzzyAndPrefixDisjunction(termStartEndIndexPair, fuzzyAndPrefixQuery); var postReplacementQueryLength = fuzzyAndPrefixQuery.length(); addedOffsetByReplacingTerms += postReplacementQueryLength - preReplacementQueryLength; } return fuzzyAndPrefixQuery; }  }
HibernateSimpleQueryUtils { public static String makeQueryPrefixAndFuzzy(@NonNull String simpleQuery) { var trimmedSimpleQuery = simpleQuery.trim(); var replaceableTermIndexPairs = getReplaceableTermsOfQuery(trimmedSimpleQuery); if(replaceableTermIndexPairs.isEmpty()) { return trimmedSimpleQuery; } var fuzzyAndPrefixQuery = trimmedSimpleQuery; var addedOffsetByReplacingTerms = 0; for(var pair : replaceableTermIndexPairs) { var termStartIndex = pair.getFirst() + addedOffsetByReplacingTerms; var termEndIndex = pair.getSecond() + addedOffsetByReplacingTerms; var termStartEndIndexPair = Pair.of(termStartIndex, termEndIndex); var preReplacementQueryLength = fuzzyAndPrefixQuery.length(); fuzzyAndPrefixQuery = replaceTermWithFuzzyAndPrefixDisjunction(termStartEndIndexPair, fuzzyAndPrefixQuery); var postReplacementQueryLength = fuzzyAndPrefixQuery.length(); addedOffsetByReplacingTerms += postReplacementQueryLength - preReplacementQueryLength; } return fuzzyAndPrefixQuery; }  static String makeQueryPrefixAndFuzzy(@NonNull String simpleQuery); static String createLuceneQueryString(Collection<String> values, String operator,
                                                  Function<String, String> function); static String createLuceneQueryString(Collection<String> values, String operator); }
HibernateSimpleQueryUtils { public static String makeQueryPrefixAndFuzzy(@NonNull String simpleQuery) { var trimmedSimpleQuery = simpleQuery.trim(); var replaceableTermIndexPairs = getReplaceableTermsOfQuery(trimmedSimpleQuery); if(replaceableTermIndexPairs.isEmpty()) { return trimmedSimpleQuery; } var fuzzyAndPrefixQuery = trimmedSimpleQuery; var addedOffsetByReplacingTerms = 0; for(var pair : replaceableTermIndexPairs) { var termStartIndex = pair.getFirst() + addedOffsetByReplacingTerms; var termEndIndex = pair.getSecond() + addedOffsetByReplacingTerms; var termStartEndIndexPair = Pair.of(termStartIndex, termEndIndex); var preReplacementQueryLength = fuzzyAndPrefixQuery.length(); fuzzyAndPrefixQuery = replaceTermWithFuzzyAndPrefixDisjunction(termStartEndIndexPair, fuzzyAndPrefixQuery); var postReplacementQueryLength = fuzzyAndPrefixQuery.length(); addedOffsetByReplacingTerms += postReplacementQueryLength - preReplacementQueryLength; } return fuzzyAndPrefixQuery; }  static String makeQueryPrefixAndFuzzy(@NonNull String simpleQuery); static String createLuceneQueryString(Collection<String> values, String operator,
                                                  Function<String, String> function); static String createLuceneQueryString(Collection<String> values, String operator);  }