Skip to main contentSkip to footer

Korean has postpositions, which complicate things for Relevanssi. Fortunately, it’s easy to clean up the most common postpositions from the words. Add this function to your site:

add_filter( 'relevanssi_stemmer', 'relevanssi_korean_plural_stemmer' );
function relevanssi_korean_plural_stemmer( $term ) {
    $len  = strlen( $term );
    $end1 = substr( $term, -1, 1 );
    if ( '은' === $end1 && $len > 2 ) {
        $term = substr( $term, 0, -1 );
    }
    elseif ( '에' === $end1 && $len > 2 ) {
        $term = substr( $term, 0, -1 );
    }
    elseif ( '는' === $end1 && $len > 2 ) {
        $term = substr( $term, 0, -1 );
    }
    elseif ( '이' === $end1 && $len > 2 ) {
        $term = substr( $term, 0, -1 );
    }
    elseif ( '가' === $end1 && $len > 2) {
        $term = substr( $term, 0, -1 );
    }
    elseif ( '을' === $end1 && $len > 2) {
        $term = substr( $term, 0, -1 );
    }
    elseif ( '를' === $end1 && $len > 2) {
        $term = substr( $term, 0, -1 );
    }
    elseif ( '와' === $end1 && $len > 2) {
        $term = substr( $term, 0, -1 );
    }
    elseif ( '과' === $end1 && $len > 2) {
        $term = substr( $term, 0, -1 );
    }
    elseif ( '로' === $end1 && $len > 2) {
        $term = substr( $term, 0, -1 );
    }
    elseif ( '으로' === $end1 && $len > 2) {
        $term = substr( $term, 0, -1 );
    }
    elseif ( '도' === $end1 && $len > 2) {
        $term = substr( $term, 0, -1 );
    }
    elseif ( '만' === $end1 && $len > 2) {
        $term = substr( $term, 0, -1 );
    }
    elseif ( '처럼' === $end1 && $len > 2) {
        $term = substr( $term, 0, -1 );
    }
    elseif ( '의' === $end1 && $len > 2) {
        $term = substr( $term, 0, -1 );
    }
    return $term;
}

After you’ve added this function, rebuild the index. You also need to adjust the minimum word length to 2, as many Korean words are only two characters long.

Cheonmu created this function and posted it at the Relevanssi support forums.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Indexing attachment file names
Relevanssi has been working nicely for the normal usecase. But how does one setup indexing of attachment files. When someone…
Indexing image captions for the posts

…can index it. The image captions for the images in the Media library is stored in the post excerpt, so what needs to be done is to fetch the post excerpts and include them. The actual filter is straightforward: add_filter( ‘relevanssi_content_to_index’, ‘rlv_add_attachment_excerpts’, 10, 2 ); /** * Indexes attachment excerpts…The use case is I run several newspapers, and the “caption” field when uploading media is where the journalists put the photographer credit. We need to be able to index the photographer bylines, but ideally would want to return the story/commentary where their image was used, not the image itself….…If you want to index the image captions for the posts where the images are used, that’s easy if the captions appear on the page: Relevanssi will index those captions as well as the other text from the post. However, if the captions don’t appear on the page, you need…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed