Skip to content

Add pre-built dictionary of "did you mean..." suggestions #4379

@schlessera

Description

@schlessera

For #3861 we built an algorithm that compares an invalid parameter to all possible parameters based on Levenshtein distance and makes suggestions if the Levenshtein distance is below or equal a set threshold (currently 2).

We still need to add a dictionary of pre-built "invalid parameter" => "suggestion" mappings so that we can provide meaningful suggestions that more drastically deviate from what was typed, without the need to bump the threshold higher. A too high threshold will show more meaningless suggestions.

The dictionary should just be an associative array that takes precedence over the calculated suggestion:

function get_suggestion( $target, array $options, $threshold = 2 ) {
   $suggestion_map = array(
      'dbpassword' => 'dbpass',
      // [...]
   );

   if ( array_key_exists( $target, $suggestion_map ) ) {
      return $suggestion_map[ $target ];
   }

   // [...]
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions