@Test public void getReplaceableTermsOfQueryDoesNotIncludeParentheses() { var simpleQuery = "((test))"; var expectedPair = Pair.of(2, 5); var actualPairs = HibernateSimpleQueryUtils.getReplaceableTermsOfQuery(simpleQuery); assertThat(actualPairs).containsExactly(expectedPair); }
static List<Pair<Integer, Integer>> getReplaceableTermsOfQuery(String simpleQuery) { var termIndexPairs = new ArrayList<Pair<Integer, Integer>>(); var queryCharCount = simpleQuery.length(); var index = 0; while(index >= 0 && index < queryCharCount) { var currentChar = simpleQuery.charAt(index); if(TERM_DELIMITER.contains(currentChar)) { index++; continue; } if(currentChar == '"') { index = getIndexAfterPhraseTerm(index, simpleQuery); continue; } var nextSpecialCharIndex = getIndexOfFirstAppearanceOfAny(index, SPECIAL_CHARACTERS, simpleQuery); var nextTermDelimiterIndex = getIndexOfFirstAppearanceOfAny(index, TERM_DELIMITER, simpleQuery); if(nextTermDelimiterIndex < 0) { nextTermDelimiterIndex = queryCharCount; } var termEndIndex = nextTermDelimiterIndex - 1; var isSimpleTerm = nextSpecialCharIndex < 0 || nextTermDelimiterIndex < nextSpecialCharIndex; if(isSimpleTerm) { termIndexPairs.add(Pair.of(index, termEndIndex)); index = nextTermDelimiterIndex + 1; } else { index = getIndexAfterFirstAppearanceOfAny(nextSpecialCharIndex, TERM_DELIMITER, simpleQuery); } } return termIndexPairs; }
HibernateSimpleQueryUtils { static List<Pair<Integer, Integer>> getReplaceableTermsOfQuery(String simpleQuery) { var termIndexPairs = new ArrayList<Pair<Integer, Integer>>(); var queryCharCount = simpleQuery.length(); var index = 0; while(index >= 0 && index < queryCharCount) { var currentChar = simpleQuery.charAt(index); if(TERM_DELIMITER.contains(currentChar)) { index++; continue; } if(currentChar == '"') { index = getIndexAfterPhraseTerm(index, simpleQuery); continue; } var nextSpecialCharIndex = getIndexOfFirstAppearanceOfAny(index, SPECIAL_CHARACTERS, simpleQuery); var nextTermDelimiterIndex = getIndexOfFirstAppearanceOfAny(index, TERM_DELIMITER, simpleQuery); if(nextTermDelimiterIndex < 0) { nextTermDelimiterIndex = queryCharCount; } var termEndIndex = nextTermDelimiterIndex - 1; var isSimpleTerm = nextSpecialCharIndex < 0 || nextTermDelimiterIndex < nextSpecialCharIndex; if(isSimpleTerm) { termIndexPairs.add(Pair.of(index, termEndIndex)); index = nextTermDelimiterIndex + 1; } else { index = getIndexAfterFirstAppearanceOfAny(nextSpecialCharIndex, TERM_DELIMITER, simpleQuery); } } return termIndexPairs; } }
HibernateSimpleQueryUtils { static List<Pair<Integer, Integer>> getReplaceableTermsOfQuery(String simpleQuery) { var termIndexPairs = new ArrayList<Pair<Integer, Integer>>(); var queryCharCount = simpleQuery.length(); var index = 0; while(index >= 0 && index < queryCharCount) { var currentChar = simpleQuery.charAt(index); if(TERM_DELIMITER.contains(currentChar)) { index++; continue; } if(currentChar == '"') { index = getIndexAfterPhraseTerm(index, simpleQuery); continue; } var nextSpecialCharIndex = getIndexOfFirstAppearanceOfAny(index, SPECIAL_CHARACTERS, simpleQuery); var nextTermDelimiterIndex = getIndexOfFirstAppearanceOfAny(index, TERM_DELIMITER, simpleQuery); if(nextTermDelimiterIndex < 0) { nextTermDelimiterIndex = queryCharCount; } var termEndIndex = nextTermDelimiterIndex - 1; var isSimpleTerm = nextSpecialCharIndex < 0 || nextTermDelimiterIndex < nextSpecialCharIndex; if(isSimpleTerm) { termIndexPairs.add(Pair.of(index, termEndIndex)); index = nextTermDelimiterIndex + 1; } else { index = getIndexAfterFirstAppearanceOfAny(nextSpecialCharIndex, TERM_DELIMITER, simpleQuery); } } return termIndexPairs; }  }
HibernateSimpleQueryUtils { static List<Pair<Integer, Integer>> getReplaceableTermsOfQuery(String simpleQuery) { var termIndexPairs = new ArrayList<Pair<Integer, Integer>>(); var queryCharCount = simpleQuery.length(); var index = 0; while(index >= 0 && index < queryCharCount) { var currentChar = simpleQuery.charAt(index); if(TERM_DELIMITER.contains(currentChar)) { index++; continue; } if(currentChar == '"') { index = getIndexAfterPhraseTerm(index, simpleQuery); continue; } var nextSpecialCharIndex = getIndexOfFirstAppearanceOfAny(index, SPECIAL_CHARACTERS, simpleQuery); var nextTermDelimiterIndex = getIndexOfFirstAppearanceOfAny(index, TERM_DELIMITER, simpleQuery); if(nextTermDelimiterIndex < 0) { nextTermDelimiterIndex = queryCharCount; } var termEndIndex = nextTermDelimiterIndex - 1; var isSimpleTerm = nextSpecialCharIndex < 0 || nextTermDelimiterIndex < nextSpecialCharIndex; if(isSimpleTerm) { termIndexPairs.add(Pair.of(index, termEndIndex)); index = nextTermDelimiterIndex + 1; } else { index = getIndexAfterFirstAppearanceOfAny(nextSpecialCharIndex, TERM_DELIMITER, simpleQuery); } } return termIndexPairs; }  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 { static List<Pair<Integer, Integer>> getReplaceableTermsOfQuery(String simpleQuery) { var termIndexPairs = new ArrayList<Pair<Integer, Integer>>(); var queryCharCount = simpleQuery.length(); var index = 0; while(index >= 0 && index < queryCharCount) { var currentChar = simpleQuery.charAt(index); if(TERM_DELIMITER.contains(currentChar)) { index++; continue; } if(currentChar == '"') { index = getIndexAfterPhraseTerm(index, simpleQuery); continue; } var nextSpecialCharIndex = getIndexOfFirstAppearanceOfAny(index, SPECIAL_CHARACTERS, simpleQuery); var nextTermDelimiterIndex = getIndexOfFirstAppearanceOfAny(index, TERM_DELIMITER, simpleQuery); if(nextTermDelimiterIndex < 0) { nextTermDelimiterIndex = queryCharCount; } var termEndIndex = nextTermDelimiterIndex - 1; var isSimpleTerm = nextSpecialCharIndex < 0 || nextTermDelimiterIndex < nextSpecialCharIndex; if(isSimpleTerm) { termIndexPairs.add(Pair.of(index, termEndIndex)); index = nextTermDelimiterIndex + 1; } else { index = getIndexAfterFirstAppearanceOfAny(nextSpecialCharIndex, TERM_DELIMITER, simpleQuery); } } return termIndexPairs; }  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);  }