#875: HibernateSearchPhoneNumberBridge.kt

projectforge-business/src/main/kotlin/org/projectforge/business/common/HibernateSearchPhoneNumberBridge.kt Type: Hibernate Search ValueBridge · Purpose: Phone number full-text indexing · Source: projectforge-business/src/main/kotlin/org/projectforge/business/common/HibernateSearchPhoneNumberBridge.kt 46 lines · 16 code · 26 comments · 4 blank
A Hibernate Search ValueBridge<String?, String> that transforms a phone number field into a rich searchable string by combining the original value, a digits-only normalized form, and a formatted extraction. Enables searches like "+49 30 123456", "4930123456", and "030/123456" to all match the same record.

Bridge Signature

class HibernateSearchPhoneNumberBridge : ValueBridge<String?, String>

toIndexedValue()

override fun toIndexedValue(number: String?, context: ValueBridgeToIndexedValueContext): String

Produces a space-separated composite string containing three representations:

  1. Original number: The raw input (e.g. "+49 30 123456-78")
  2. Normalized number: Digits only via StringHelper.removeNonDigits(number) (e.g. "493012345678")
  3. Formatted number: Extracted phone number via NumberHelper.extractPhonenumber(number)

Result example: "+49 30 123456-78 493012345678 030/12345678"

Hibernate Search's default analyzer tokenizes on whitespace, making all three forms independently searchable.

Null input returns an empty string (""), not null. This prevents NPEs in the search index writer.

Design Rationale

Phone numbers are notoriously difficult to search because users enter them in various formats: international (+49 30 123456), local (030/123456), compact (4930123456), or with punctuation. By indexing multiple normalized forms side-by-side in a single field, any user-entered search format can match.

The onlyDigits approach handles the most general case (any format reduces to the same digit sequence), while the extractPhonenumber approach preserves local formatting conventions for exact-match scenarios.

Git History

868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
7798dac85 Migration stuff in progress... (all tests of all packages: OK).
974d70bec Migration stuff in progress...
4f5a458c9 Migration stuff in progress...
c04fb0d51 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.
7c79f1922 Copyright of source header -> 2020.
000ca723d Remove pointless boolean expressions (business)
dd5ca38ac CopyRight of all java file-header updated or created.
9ebb88522 Initial commit