WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 10 months ago

#36420 new enhancement

A more forgiving redirect guesser

Reported by: gorillum Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Canonical Keywords: dev-feedback 2nd-opinion
Focuses: Cc:

Description

I would like the redirect guesser to be more forgiving using SOUNDS LIKE . Here's a small suggestion:

function redirect_guess_404_permalink() {
        global $wpdb;

        if ( get_query_var('name') ) {
                $where = $wpdb->prepare("(post_name SOUNDS LIKE %s", $wpdb->esc_like( get_query_var('name') ) );
                $where .= $wpdb->prepare(" OR post_name LIKE %s)", $wpdb->esc_like( get_query_var('name') ) . '%');

....

It would be even better if it could be implemented using levenstein distance if that is not too heavy on resources.

https://github.com/fza/mysql-doctrine-levenshtein-function

Change History (3)

#1 @Presskopp
2 years ago

While this sounds like a good idea, I have some notes:

MySQL SOUNDS LIKE is used as SOUNDEX(expr) = SOUNDEX(expr) to retrieve strings sounds similar. Soundex is a phonetic algorithm for indexing names after English pronunciation of sound. http://www.w3resource.com/mysql/string-functions/mysql-sounds_like-function.php

Not everyone uses an english environment, so this would be exclusive for the english..

The LIKE operator is commonly used to select data based on patterns. Using the LIKE operator in the right way is essential to increase the query performance. http://www.mysqltutorial.org/mysql-like

Hmm. Do we want to be performant here?

And if i understand it right, the Damerau–Levenshtein distance would fit even better? https://samjlevy.com/mysql-levenshtein-and-damerau-levenshtein-udfs/ https://github.com/Oefenweb/damerau-levenshtein/releases

That's all I can say, please tell me if I'm wrong somewhere

Last edited 2 years ago by Presskopp (previous) (diff)

#2 @Presskopp
2 years ago

  • Keywords dev-feedback 2nd-opinion added

This ticket was mentioned in Slack in #core by presskopp. View the logs.


10 months ago

Note: See TracTickets for help on using tickets.