#877: YearValueBridge.kt

projectforge-business/src/main/kotlin/org/projectforge/business/common/YearValueBridge.kt Type: Hibernate Search ValueBridge · Purpose: Date → year integer bridge · Source: projectforge-business/src/main/kotlin/org/projectforge/business/common/YearValueBridge.kt 34 lines · 9 code · 22 comments · 3 blank
A minimal Hibernate Search ValueBridge<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.

Bridge Signature

class YearValueBridge : ValueBridge<LocalDate, Int>

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.

Use Case

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:

This 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.

Design Rationale

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.

Git History

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