Hibernate Search 6 and Spring boot and testing

Are you using the indexes.default intentionally?

From the docs Hibernate Search 7.0.0.Final: Reference Documentation

Index properties
(…)
With the root hibernate.search.backend.indexes.<index name> , they set the value for a specific index, overriding the defaults (if any). The backend and index names must match the names defined in the mapping. For ORM entities, the default index name is the name of the indexed class, without the package: org.mycompany.Book will have Book as its default index name. Index names can be customized in the mapping.

You can look at hibernate-search/integrationtest/showcase/library at main · hibernate/hibernate-search · GitHub for many Tests it currently uses Spring 2.4.0

I’ve also added a very minimal Test to my example project here: Files · master · Peter Müller / spring-hibernate-search-6-demo · GitLab

@SpringBootTest(classes = DemoApplication.class)
@ActiveProfiles("test")
class PersonSearchServiceTest {

    @Autowired
    PersonRepository personRepository;

    @Autowired
    PersonSearchService personSearchService;

    @Test
    void search() {
        Person person = new Person();
        person.setName("Hans");
        Person savedPerson = personRepository.save(person);

        Page<Person> result = personSearchService.search(PageRequest.of(0, 10), "hans");

        Assertions.assertEquals(1, result.getTotalElements(), "The one person should be found");
        Person foundPerson = result.getContent().get(0);
        Assertions.assertEquals(savedPerson.getId(), foundPerson.getId(), "The person should have the correct ID");
        Assertions.assertEquals("Hans", foundPerson.getName(), "The person name should be correct");
    }
}

with


# File: application.yaml
spring:
  jpa.properties:
    hibernate.search:
      backend.directory.root: ./search-index

  jackson:
        serialization.indent_output: true

# File: application-test.yml ( `-test` so that it gets used as the Spring "test" active profile)
spring:
  jpa.properties:
    hibernate.search:
      backend:
        directory.type: local-heap

1 Like