HibernateSearchService { Query getQuerySearchingForAllIndexedFields(Class<?> entityType, String simpleQueryString) { if(!isIndexedEntity(entityType)) { throw new IllegalArgumentException("Given type is not an entity or is not indexed!"); } var annotatedStringFields = getNamesOfAnnotatedStringFields(entityType); if(annotatedStringFields.isEmpty()) { throw new IllegalArgumentException("No field of type String annotated with @Field!"); } var fuzzyAndPrefixQuery = HibernateSimpleQueryUtils.makeQueryPrefixAndFuzzy(simpleQueryString); var queryBuilder = getQueryBuilder(entityType); return queryBuilder.simpleQueryString() .onFields(annotatedStringFields.get(0), annotatedStringFields.subList(1, annotatedStringFields.size()).toArray(String[]::new)) .withAndAsDefaultOperator() .matching(fuzzyAndPrefixQuery) .createQuery(); } HibernateSearchService(@NotNull Collection<String> statusWithLobConstraint, @NotNull Collection<String> excludedStatus); @SuppressWarnings("unchecked") List<Project> searchProjects(@NonNull String simpleQueryString, String lob); @SuppressWarnings("unchecked") Page<Project> searchProjects(@NonNull String simpleQueryString, @NonNull Pageable pageable, String lob); @SuppressWarnings("unchecked") List<UserData> searchUserData(@NonNull List<User> users, @NonNull String simpleQueryString);  }
@Test public void getQuerySearchingForAllIndexedFieldsThrowsExceptionWhenNotAnEntity() { assertThatThrownBy(() -> hibernateSearchService.getQuerySearchingForAllIndexedFields(String.class, "")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Given type is not an entity or is not indexed!"); }
@Test public void getQuerySearchingForAllIndexedFieldsThrowsExceptionWhenEntityNotIndexed() { assertThatThrownBy(() -> hibernateSearchService.getQuerySearchingForAllIndexedFields(NonIndexedEntity.class, "")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Given type is not an entity or is not indexed!"); }
@Test public void getQuerySearchingForAllIndexedFieldsThrowsExceptionWhenNoStringFieldsAnnotated() { assertThatThrownBy(() -> hibernateSearchService.getQuerySearchingForAllIndexedFields(IndexedEntityWithoutFields.class, "")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("No field of type String annotated with @Field!"); }