Skip to content

[CODEC-249] Fix Incorrect transform of CH digraph according Metaphone basic rules#423

Merged
garydgregory merged 3 commits intoapache:masterfrom
Shalujha0907:CODEC-249-METAPHONE-BUG-Fix
Feb 12, 2026
Merged

[CODEC-249] Fix Incorrect transform of CH digraph according Metaphone basic rules#423
garydgregory merged 3 commits intoapache:masterfrom
Shalujha0907:CODEC-249-METAPHONE-BUG-Fix

Conversation

@Shalujha0907
Copy link
Contributor

Incorrect transformation of the CH digraph in the Metaphone algorithm

This PR fixes the above issue.

Previously, we checked whether the character following CH was a vowel; if so, we appended the character "K". I have removed that check so that when "CH" is encountered, the algorithm simply appends "X".

@garydgregory
Copy link
Member

Hello @Shalujha0907

Thank you for the PR!

I see this PR changes the expectation for CHARACTER from KRKT to XRKT, but isn't the correct value XRKTR?

@jhaShalu
Copy link

jhaShalu commented Feb 12, 2026

Hello @Shalujha0907

Thank you for the PR!

I see this PR changes the expectation for CHARACTER from KRKT to XRKT, but isn't the correct value XRKTR?

Hello @garydgregory

Thanks for the review and for calling this out.

XRKTR is the full phonetic sequence, but Metaphone in Commons Codec uses a default maxCodeLen of 4, so the returned value is truncated to XRKT.
That’s why this test expects XRKT (and not XRKTR) unless setMaxCodeLen(...) is increased.

Please let me know if you think we should also add a separate assertion with a higher maxCodeLen to make that behavior explicit.

@garydgregory
Copy link
Member

Hi @Shalujha0907
Ah, yes, you're right 👍
Would you please mind adding a new test for this specific 5 char use case?
Ty!

@jhaShalu
Copy link

5 cha

Hi @Shalujha0907 Ah, yes, you're right 👍 Would you please mind adding a new test for this specific 5 char use case? Ty!

Hi @garydgregory
Pushed the latest change.

Thank you!

@garydgregory garydgregory merged commit e352a9b into apache:master Feb 12, 2026
@garydgregory
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants