#876: NumberToStringValueBridge.kt

projectforge-business/src/main/kotlin/org/projectforge/business/common/NumberToStringValueBridge.kt Type: Hibernate Search ValueBridge · Purpose: Number ↔ String index bridge · Source: projectforge-business/src/main/kotlin/org/projectforge/business/common/NumberToStringValueBridge.kt 42 lines · 15 code · 22 comments · 5 blank
Bidirectional Hibernate Search ValueBridge<Number, String> that converts numeric entity fields to strings for full-text indexing and back to numbers when reading from the index. Enables text-based search queries to match numeric fields.

Bridge Signature

class NumberToStringValueBridge : ValueBridge<Number, String>

Methods

toIndexedValue(value, context): String?

Converts the Number to its string representation via value?.toString(). Returns null for null input.

fromIndexedValue(value, context): Number?

Reconstructs a Number from the indexed string. Tries parsing in this order:

  1. toLongOrNull() — handles integer values (most common case for IDs)
  2. toDoubleOrNull() — handles decimal values
  3. toIntOrNull() — fallback for values that don't fit the above

Returns null if none parse successfully.

toString(): String

Returns "NumberToStringValueBridge" for bridge identification in logs/debug output.

Use Case

Used when entity numeric fields (e.g., invoice numbers, monetary amounts, quantities) need to be searchable via Hibernate Search full-text queries. Without this bridge, numeric fields would need separate range queries or exact-match filters. By converting to strings, users can search for e.g. "100" and match records where amount = 100.0 or invoiceNumber = 100.

Git History

868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
2d324f2bb Finance: incoming invoices fixed.
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