• Resolved pixeltokig

    (@pixeltokig)


    Hello!

    We are using the plugin “Search and filter pro” together with “Relevanssi” to search coworkers on a site we built. We want Relevanssi to sort titles by alphapetical order. The problem is that the Swedish character “Å” comes directly after “A” which is wrong. “Å” should come after “Z”.

    Is it possible to solve this and how do we do it?

    Thanks in advance!

    Kind regards,
    Christoffer

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • This depends on which collation you’ve got in your database. (So the sorting is usually done by sending a parameter (ORDER BY) with the request to the database.
    Note that it’s not totally trivial to change the collation. If you just change the collation setting for a database, this will affect only tables that are created afterwards. Google for more details.

    Thread Starter pixeltokig

    (@pixeltokig)

    Hmm, but we have utf8mb4 as collation as default for everything in the database which seem to be recommended.

    We used this snippet found here https://www.relevanssi.com/user-manual/relevanssi_hits_filter.

    add_filter('relevanssi_modify_wp_query', 'rlv_sort_by_title');
    function rlv_sort_by_title($q) {
    	$q->set('orderby', 'post_title');
    	$q->set('order', 'asc');
    	return $q;
    }

    Thanks again for helping!

    If you use utf8mb4 as the encoding, then try to use utf8mb4_swedish_cias the collation.

    Plugin Author Mikko Saari

    (@msaari)

    Actually, database collation probably doesn’t affect the sorting of results, because Relevanssi fetches the posts from the database in relevancy order, then resorts them in PHP if some other sorting is required.

    Relevanssi uses strcmp() to sort the results and the strings are converted to uppercase with mb_strtoupper() first.

    I just tested this on my computer, and the sorting method Relevanssi uses sorts “åland” after “zeta”, as it should.

    However, I don’t think that list has anything to do with Relevanssi. It’s not a search result – what’s the search term? Looks like it’s something generated by Search & Filter, and I can’t vouch for how S&F does the sorting. Perhaps it uses a different method that doesn’t understand the intricacies of Swedish language?

    Thread Starter pixeltokig

    (@pixeltokig)

    Now it works!

    I got it to list the posts in the right order now. I noticed that in the WordPress admin all posts were in wrong order also, hence nothing wrong or associated with Relevanssi I think.

    I installed PhpMyAdmin on the server and then inside PhpMyAdmin I found in the settings that I could change the database collation. Which I used to try to change the collation from utf8mb4 to utf8mb4_swedish_ci.

    But because I am running MySQL 5.7 it has strict mode activated and I got error messages when I tried to change the collation inside PhpMyAdmin. When I had disabled strict mode then I was able to change the collation from utf8mb4 to utf8mb4_swedish_ci.

    Thanks Tor-Bjorn Fjellner and Mikko Saari for pointing me in the right direction!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Wrong order with UTF-8 Swedish characters’ is closed to new replies.