Skip to content

Fuzzy text search: support for Daitch-Mokotoff function #3524

Description

@profet23

I don't seem to see a built in function for:

https://www.postgresql.org/docs/current/fuzzystrmatch.html#FUZZYSTRMATCH-DAITCH-MOKOTOFF

Is it missing? Undocumented? Any reason it isn't supported?

Activity

  1. profet23 commented on Apr 21, 2025

    @profet23
    Author

    There's probably a way to do this on my own until an official method exists. But the documentation feels a bit lacking around Array type mappings. Any help would be appreciated.

    The daitch_mokotoff postgres function takes a text argument, and returns a text[].

    This is not correct:

    		modelBuilder.HasDbFunction(typeof(SqlFunctions)
    			.GetMethod(nameof(DaitchMokotoffSoundex), [typeof(string)])!)
    			.HasTranslation(TranslateDaitchMokotoffSoundex);
    public static string[] DaitchMokotoffSoundex(string source)
    {
    	throw new InvalidOperationException($"{nameof(DaitchMokotoffSoundex)} should be performed on database");
    }
    
    	
    public static SqlExpression TranslateDaitchMokotoffSoundex(IReadOnlyCollection<SqlExpression> args)
    {
    	// Get the source string parameter
    	var source = args.First();
    	
    	var daitchMokotoffExpression = new SqlFunctionExpression(
    		"daitch_mokotoff",
    		new[] { source },
    		true,
    		new[] { true },
    		typeof(string[]),
    		new NpgsqlArrayTypeMapping<string[], string[], string>
    			(new NpgsqlStringTypeMapping("text", NpgsqlDbType.Text)));
    
    	return daitchMokotoffExpression;
    }

    Any help with what I'm doing wrong would be deeply appreciated.

  2. roji commented on Apr 22, 2025

    @roji
    Member

    @profet23 the Daitch-Mokotoff function was added only recently to PG's fuzzystrmatch extensions (in PG 16), which is why there's no translation for it. You're welcome to submit a PR to add support for it, just like the EF.Functions.FuzzyStringMatchSoundex which is already supported.

    Otherwise, in your code sample, rather than trying to instantiate NpgsqlArrayTypeMapping yourself, you can simply look up the type mapping for string[] via the type mapping source of the provider - that should be quite trivial and should work (check out other translators for examples).

    BTW I'm also noticing that we don't actually have documentation for the fuzzy text search translations, submitted #405 npgsql/doc#405 to fix this.

  3. added this to the 10.0.0 milestone on Apr 22, 2025
  4. changed the title [-]Support for Daitch-Mokotoff function[/-] [+]Fuzzy text search: support for Daitch-Mokotoff function[/+] on Apr 22, 2025
  5. profet23 commented on Apr 22, 2025

    @profet23
    Author

    @profet23 the Daitch-Mokotoff function was added only recently to PG's fuzzystrmatch extensions (in PG 16), which is why there's no translation for it. You're welcome to submit a PR to add support for it, just like the EF.Functions.FuzzyStringMatchSoundex which is already supported.

    Otherwise, in your code sample, rather than trying to instantiate NpgsqlArrayTypeMapping yourself, you can simply look up the type mapping for string[] via the type mapping source of the provider - that should be quite trivial and should work (check out other translators for examples).

    BTW I'm also noticing that we don't actually have documentation for the fuzzy text search translations, submitted #405 to fix this.

    Is that the correct issue number? "405" ?

  6. profet23 commented on Apr 22, 2025

    @profet23
    Author

    @roji Thanks.

    I'm REALLY close but I'm still having issues.

    If I define my translation as:

    public static string[] DaitchMokotoffSoundex(string source)
    {
    	throw new InvalidOperationException($"{nameof(DaitchMokotoffSoundex)} should be performed on database");
    }
    
    	
    public static SqlExpression TranslateDaitchMokotoffSoundex(IRelationalTypeMappingSource typeMappingSource, IReadOnlyCollection<SqlExpression> args)
    {
    	// Get the source string parameter
    	var source = args.First();
    	
    	var daitchMokotoffExpression = new SqlFunctionExpression(
    		"daitch_mokotoff",
    		new[] { source },
    		true,
    		new[] { true },
    		typeof(string[]),
    		typeMappingSource.FindMapping(typeof(string[]))
            );
    
    	return daitchMokotoffExpression;
    }

    Then I can execute the function and get a valid result array if I perform it as a select.

    But if I try to do an operation on the result, say an Any operation or an Intersect operation, the expression fails to be translated with an exception:

    could not be translated. Additional information: Translation of method 'System.Linq.Enumerable.Any' failed.

    I understand this isn't a support forum. But any quick tips would be appreciated.

  7. roji commented on Apr 22, 2025

    @roji
    Member

    Is that the correct issue number? "405" ?

    Sorry, wrong repo... The correct link is: npgsql/doc#405

    But if I try to do an operation on the result, say an Any operation or an Intersect operation, the expression fails to be translated with an exception

    Yeah, that's an unfortunate current limitation of EF itself - I opened dotnet/efcore#35980 to track this on the EF side. This is unrelated to Daitch-Mokotoff: it's a general limitation around composing LINQ operators on the return values of function calls in EF.

  8. added theissue type on Jun 14, 2025
  9. modified the milestones: 10.0.0, 11.0.0 on Oct 5, 2025
  10. roji commented on Oct 15, 2026

    @roji
    Member

    AI Triage

    The below is an AI-generated analysis and may contain inaccuracies.

    Classification: Feature request, not a regression. The requested built-in translation is absent from the current fuzzy-string-match API and its translator. PostgreSQL added daitch_mokotoff(text) -> text[] to fuzzystrmatch in PostgreSQL 16. This is PostgreSQL-specific provider functionality, so this is the appropriate repository. The issue type is confirmed as Feature; no bug repro or version-regression comparison was attempted for the missing feature.

    Existing implementation: #3922 is open and explicitly fixes this issue, proposing EF.Functions.FuzzyStringMatchDaitchMokotoff(...) with an array return mapping and PostgreSQL 16+ support. Another implementation issue is unnecessary.

    Related issues / duplicate search: No duplicate Daitch-Mokotoff feature request was found among open or closed issues in dotnet/efcore or npgsql/efcore.pg. The later Any/Intersect composition problem is separately tracked by the still-open dotnet/efcore#35980, which concerns composing LINQ operators over translated method results generally. It is related, not a duplicate of this request, and #3922 explicitly leaves it outside its scope.

    The documentation gap mentioned in the discussion was addressed separately by the merged npgsql/doc#405; that documentation change did not add this translation. Keep this feature request open pending the implementation PR.

  11. added a commit that references this issue on Oct 15, 2026
    0b3aa1c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions