I just tried the D8 version of the module at http://simplytest.me/project/views_natural_sort and it does not seem to work...

<strong>SORT
</strong>Content: Title
Order
  Sort ascending
  Sort descending
* Sort ascending naturally
  Sort descending naturally

RESULT:

É title
d title
zzz title
Ðeres title
a title
å title

EXPECTED:

a title
d title
Ðeres title
É title
zzz title
å title

A README.txt with instructions for setting up the module would be nice, since I am not sure if I am missing something ...

I managed to fix the major part of the issue by changing the collation of the database table with ALTER TABLE node_field_data CONVERT TO CHARACTER SET utf8 COLLATE utf8_danish_ci;, so that "a" is now the first letter and "å" the last in the list.

Comments

ressa created an issue. See original summary.

generalredneck’s picture

Project: Drupal 8 Contrib Porting Tracker » Views Natural Sort
Version: 8.x-0.x-dev » 8.x-2.x-dev
Component: Module » Code

Moving this to views natural sort. The author added this to the wrong issue queue.

The Drupal 8 Contrib Porting Tracker issue queue is meant for tracking the porting of modules to drupal 8.

malcomio’s picture

I'm seeing a similar problem. For example, I have a list of about 500 nodes - here are the first ones, using standard views sorting:

  1. A&D Gallery
  2. Ackermann and Johnson
  3. Adam Gallery
  4. Aicon Gallery
  5. Aktis Gallery
  6. Alan Cristea Gallery
  7. Alan Kluckow Fine Art
  8. Alan Wheatley Art
  9. Albany Gallery
  10. Albemarle Gallery
  11. Albion
  12. Alexandra Art Gallery
  13. Alexia Goethe Gallery
  14. Alison Jacques Gallery
  15. All Visual Arts
  16. Alma Enterprises
  17. Alon Zakaim
  18. Amberden Art Gallery

With natural sort, the order seems slightly random:

  1. Arcade Fine Arts
  2. Arcade Cardiff
  3. Ackermann and Johnson
  4. Auto-Italia South East
  5. Archgallery
  6. Albany Gallery
  7. Adam Gallery
  8. Avivson
  9. Aristao Gallery
  10. Art Pistol
  11. Aicon Gallery
  12. Artisan Fine Art
  13. Art First
  14. A&D Gallery
  15. Alan Cristea Gallery
  16. Albion
  17. Art On The Underground
  18. Apart Gallery
  19. W8
malcomio’s picture

Digging into the code, it looks like the views_natural_sort table is only populated by calls to views_natural_sort_store_multiple(), and this is called from implementations of hook_entity_insert and hook_entity_update.

When I tested at first, the nodes already existed when the module was enabled.

After updating the nodes, the views_natural_sort table gets populated, and sorting seems to work as expected.

Perhaps it is necessary to do something in the install hook to cover the scenario where nodes exist before the module is enabled?

generalredneck’s picture

Ok... yeah so in my first pass in translati n g the functionality over I didn't make the batch process (or any of the admin features) that were in d7. With that said this is alpha so I expected it to be pretty barebones. Here is the line in d7. We need to replicate that functionality. Several people have had reservations about batch processes on install... but I still think that's the best way to handle this since the module doesn't work without the transformed string...
http://cgit.drupalcode.org/views_natural_sort/tree/views_natural_sort.in...

generalredneck’s picture

Ok So I accidentally left the admin include from the d7 version in the repo as well. You took care of the .info file in your other ticket. AFAIK that code doesn't translate directly and would require me to create a controller and what not which I haven't done yet. The first steps though would be to create a batch process that would work based off that code. You can see the d7 code checked into the d8 branch here: http://cgit.drupalcode.org/views_natural_sort/tree/views_natural_sort.ad...

Sorry about the mess. I was seriously trying to get something "usable" up as quickly as I could in the time I had available since so many people were waiting on it. If you would take a stab at it I would appreciate it... otherwise I'll see what I can get up between now and the Christmas break.

ressa’s picture

I see there has been a few commits for Drupal 8, are they ready to be rolled into a fresh dev-release, for testing?

generalredneck’s picture

Negative. The branch there are commits to is a non-working WIP branch so that 1) it shows I'm working on it. 2) I can share the love with more than one person/machine via git since the changes are so vast. I'll for sure have a release this month as I've finally tangled some willing help and sponsorship.

ressa’s picture

Sounds great, I am ready to test the new release when it arrives. Thanks for working on it.

generalredneck’s picture

Ok, I've got a new dev release. Give it a shot... For now you will have to manually run the batch process if you have existing content as I haven't been able to get that to work on install. Simply log in to your site and navigate to admin/structure/views/settings/views_natural_sort and hit "save" or the In Case of Emergency -> Reindex. Both will reindex the site... just the ICE Reindex button bypasses any changes you might have put in the settings form...

This still only works on Node Titles, but should work for views with a sort handler on it... (exposed or not exposed).

generalredneck’s picture

Status: Active » Needs review
generalredneck’s picture

Ok had to make a quick fix to the batch operation as it was running the full queue on the first operation always. This fix should make it respect the batch limit that is set in configuration.

ressa’s picture

With the latest dev-version from March 13th, the result of Sort ascending naturally on Title after running "Rebuild index":

RESULT

å title
d title
É title
a title
zzz title
Ðeres title

EXPECTED

a title
d title
Ðeres title
É title
zzz title
å title
generalredneck’s picture

So here's the thing... What's going to happen is it's going to collate the letters based on common typically. What I would have actually expected would have been something alone the lines of

a title
å title
d title
Ðeres title
É title
zzz title

With that said, I'm kinda at the mercy of what the database collation sets the weight of characters currently.

What you can do is send me what the conversion came out to in the views_natural_sort table. Additionally, a recounting of the steps you took to test this would be helpful. I would like to know for example if you enabled VNS and then created the content or did you create the content, enable the module, and then hit the Reindex button?

If you enabled the module after the content was created and then did not hit the reindex button... then that's a possible issue as explained in above comments.

ressa’s picture

Here are the steps I went through:

  1. Went to https://simplytest.me/project/views_natural_sort/8.x-2.x and downloaded the module
  2. Created the content
  3. Enabled the module (It said something like 6 nodes updated)
  4. Reindexed to make sure (again, it said something like 6 nodes updated)
  5. The sort order (Sort ascending naturally) in my View was not as expected ...
generalredneck’s picture

Status: Needs review » Closed (works as designed)

@ressa,
Views Natural Sort is sorting as expected given Drupal's standard Collations.

I however have fixed the issue in #3. Beyond that, the D8 and D7 both sort exactly the same using the Default Collation that Drupal installs with. I also don't have a plan to support Locale any time soon as that is a major undertaking which is partly what this ticket is suggesting with changing collation to "Danish". I'm assuming these are Danish letters therefore the expectation of the sorting. Please change your collation at your own risk as I haven't a great idea of the consequences of doing so.

You will also notice that the architecture of the module currently isn't set up to handle different translations either unless each translation is in a different node...