HibernateSimpleQueryUtils { static int getIndexAfterPhraseTerm(int startIndex, String simpleQuery) { var queryCharCount = simpleQuery.length(); if(startIndex >= queryCharCount) { return -1; } var endIndex = getIndexAfterFirstAppearanceOf(startIndex + 1, '"', simpleQuery); if(endIndex > 0 && endIndex < queryCharCount && simpleQuery.charAt(endIndex) == '~') { endIndex = getIndexAfterFirstAppearanceOfAny(endIndex, TERM_DELIMITER, simpleQuery); } return endIndex; }  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);  }
@Test public void getIndexAfterPhraseTermReturnsIndexAfterNearOperator() { var simpleQuery = "\"java\"~10 test"; var startIndex = 0; var expectedIndex = 10; var actualIndex = HibernateSimpleQueryUtils.getIndexAfterPhraseTerm(startIndex, simpleQuery); assertThat(actualIndex).isEqualTo(expectedIndex); }
@Test public void getIndexAfterPhraseTermReturnsIndexAfterSecondQuotationMarks() { var simpleQuery = "\"java\" test"; var startIndex = 0; var expectedIndex = 6; var actualIndex = HibernateSimpleQueryUtils.getIndexAfterPhraseTerm(startIndex, simpleQuery); assertThat(actualIndex).isEqualTo(expectedIndex); }
@Test public void getIndexAfterPhraseTermReturnsMinusOneWhenStartIndexGreaterThanInputLength() { var simpleQuery = "\"java\""; var startIndex = 6; var expectedIndex = -1; var actualIndex = HibernateSimpleQueryUtils.getIndexAfterPhraseTerm(startIndex, simpleQuery); assertThat(actualIndex).isEqualTo(expectedIndex); }
@Test public void getIndexAfterPhraseTermReturnsMinusOneWhenQuotationMarkIsLastCharacter() { var simpleQuery = "\"java\""; var startIndex = 0; var expectedIndex = -1; var actualIndex = HibernateSimpleQueryUtils.getIndexAfterPhraseTerm(startIndex, simpleQuery); assertThat(actualIndex).isEqualTo(expectedIndex); }
@Test public void getIndexAfterPhraseTermReturnsMinusOneWhenQuotationNearOperatorIs() { var simpleQuery = "\"java\""; var startIndex = 0; var expectedIndex = -1; var actualIndex = HibernateSimpleQueryUtils.getIndexAfterPhraseTerm(startIndex, simpleQuery); assertThat(actualIndex).isEqualTo(expectedIndex); }