Skip to content

Java library that simplifies the process of querying databases by any field, offering convenient pagination support

License

Notifications You must be signed in to change notification settings

lipiridi/hibernate-search-engine

Repository files navigation

Hibernate Search Engine

Maven Central

The Hibernate Search Engine is a powerful Java library designed to simplify the implementation of search functionality, filtering, sorting, and pagination in Java projects using the Hibernate framework. With minimal configuration, developers can seamlessly integrate search capabilities into their applications, enhancing the user experience and improving data retrieval efficiency.

Features

  • Annotation-based Searchable Entities: Simply annotate the fields of your entity classes with @Searchable to enable search functionality.

  • SearchService Integration: Inject the SearchService into your code, and effortlessly perform searches by calling searchService.search(searchRequest, Entity.class)

  • Mapping Support: The library supports mapping search results to another class, such as a Data Transfer Object (DTO), directly within the service. This enables efficient transformation of data for various use cases.

Getting Started

Installation

To include this library in your project, add the following dependency:

Gradle:

implementation("io.github.lipiridi:hibernate-search-engine:1.1.0")

Maven:

<dependency>
    <groupId>io.github.lipiridi</groupId>
    <artifactId>hibernate-search-engine</artifactId>
    <version>1.1.0</version> <!-- Replace with the latest version -->
</dependency>

Configuration

Customize the library's behavior with the help of configuration properties.

  • Max page size - limit the search request in order to prohibit large queries to the database
  • Naming convention - choose how to generate field names that uses client for searching (in case when you use @Searchable annotation)
spring.jpa.hibernate.search-engine.max-page-size=100
spring.jpa.hibernate.search-engine.naming-convention=camel_case

Usage example

@RestController
@RequiredArgsConstructor
public class TestController {

    private final SearchService searchService;
    private final TestMapper testMapper;

    @PostMapping("/search")
    public SearchResponse<TestDto> search(@Valid @RequestBody SearchRequest searchRequest) {
        return searchService.search(searchRequest, TestEntity.class, testMapper::toDto);
    }
}

Sample search request

Here's an example of the search request JSON body output:

{
  "page": "1",
  "size": "100",
  "filters": [
    {
      "field": "description",
      "type": "LIKE",
      "value": [
        "hello"
      ]
    },
    {
      "field": "id",
      "type": "IN",
      "value": [
        "16",
        "25"
      ]
    }
  ],
  "sorts": [
    {
      "field": "createdAt",
      "direction": "ASCENDING"
    },
    {
      "field": "name",
      "direction": "DESCENDING"
    }
  ]
}

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Java library that simplifies the process of querying databases by any field, offering convenient pagination support

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages