YearValueBridge.ktValueBridge<LocalDate, Int> that extracts only the year component from a LocalDate for indexing. Enables year-based search queries (e.g., "2024") against date fields without indexing the full date string.class YearValueBridge : ValueBridge<LocalDate, Int>
LocalDate (the entity date field, nullable)Int (the year as an integer, nullable)toIndexedValue (indexing only, no read-back)toIndexedValue()override fun toIndexedValue(value: LocalDate?, context: ValueBridgeToIndexedValueContext): Int?
Simply returns value?.year — the year as an Int. Returns null if the input date is null.
Applied to entity date fields where filtering or searching by year is the primary use case (e.g., invoice dates, timesheet entries, fiscal year boundaries). By indexing only the year as an integer, Hibernate Search can efficiently handle queries like:
year = 2024year BETWEEN 2020 AND 2024year >= 2024This is more efficient than indexing the full ISO date string and parsing it in queries, and avoids the need for database-level date functions in search predicates.
The bridge is intentionally unidirectional (no fromIndexedValue implementation) because the index does not need to reconstruct a full LocalDate from the stored year. Projection queries that need the original date field can read it directly from the entity rather than from the index.
Using Int as the indexed type (rather than String) allows numeric range queries and comparisons natively in Hibernate Search, which is more performant than string-based range queries.
868d6abb7 2025 -> 2026 63081666f Source file headers: 2024-> 2025. cf00da112 Migration stuff in progress... 4f5a458c9 Migration stuff in progress... b6092df09 Copyright 2023 -> 2024 ab45d51fa Copyright 2001-2022 -> 2001-2023. 5f7ef41b8 Copyright 2021 -> 2022 ceb63e8a1 Source code header: (C) 2001-2021. 0e850ecb2 Plugins don't need to be spring components, ServiceLoader is used again. c526c1bbb I18nEnum, IUserRightId -> Kotlin. 7c79f1922 Copyright of source header -> 2020. dd5ca38ac CopyRight of all java file-header updated or created. 9ebb88522 Initial commit