Alphabetical sorting ignoring numbers


(Rachel Macdonald) #1

Probably this is not possible, but I have an asset listing that needs to sort in alphabetical order. The problem is that it is based around a list of addresses (eg 4 High Street, 10 Elm Street, etc). Is it possible to somehow get it to ignore the fact that it starts with a number and organise it by street? So:


9 Apple Grove

2 Baby Street



instead of



2 Baby Street

9 Apple Grove


(Greg Sherwood) #2

There is no feature to do that.


Can you store street number and name in different fields?


(Rachel Macdonald) #3

I could have if I'd thought it through better but I've entered all my data now. ;p


Let this be a lesson people, plan plan plan!


(Rachel Macdonald) #4

Okay, so I guess I need to change all my items.


If I put the number and street name in two separate fields, how can I actually make it work? It doesn't seem to me that there is an option on the Asset Sorting screen to choose a secondary sort type. Will it not just list the houses in the same street by some random order rather than by the number in another field?


(Greg Sherwood) #5

I think you'll need to create a 3rd metadata field and include the values of street name and number inside it.
There is a keyword to include the value of one metadata field in another: %metadata_field_XXXX%



So you could create a field called "AddressSortable" and the default value would be: %metadata_field_StreetAddress% %metadata_field_StreetNumber%


(Sandhal) #6

[quote]
Probably this is not possible, but I have an asset listing that needs to sort in alphabetical order. The problem is that it is based around a list of addresses (eg 4 High Street, 10 Elm Street, etc). Is it possible to somehow get it to ignore the fact that it starts with a number and organise it by street? So:



9 Apple Grove

2 Baby Street



instead of



2 Baby Street

9 Apple Grove

[/quote]





Wondering if this is possible in the current version of Matrix? I can't seem to be able to do this in the version we are running (v3.26.3).


(Nic Hubbard) #7

[quote]
Wondering if this is possible in the current version of Matrix? I can't seem to be able to do this in the version we are running (v3.26.3).

[/quote]



If the number and name are in the same field, then no, you can't have it ignore the number and sort by the name. But if they were in separate fields then yes, it would work.


(Cgrist) #8

I'm reluctant to suggest this, because it's a bit messy, but you can actually sort on a keyword, and it will take keyword replacements as well. I dont' know if this will work in older versions, this was tested in 4.8


I created a keyword to sort on with the following value (without quotes):



"asset_name^replace:.*[0-9]:"



Which will strip any characters until the last digit it finds (I think) and sort the remaining string, which in my small test case sorted by the following alphabetical characters. It will fail if you have another digit in the string after the street number, and it might be tricky to get a more complex regular expression as keyword modifiers will only work with basic ones. It may perform poorly too, I only tested with 3 assets.


(Maks) #9

[quote]
I'm reluctant to suggest this, because it's a bit messy, but you can actually sort on a keyword, and it will take keyword replacements as well. I dont' know if this will work in older versions, this was tested in 4.8



I created a keyword to sort on with the following value (without quotes):



"asset_name^replace:.*[0-9]:"



Which will strip any characters until the last digit it finds (I think) and sort the remaining string, which in my small test case sorted by the following alphabetical characters. It will fail if you have another digit in the string after the street number, and it might be tricky to get a more complex regular expression as keyword modifiers will only work with basic ones. It may perform poorly too, I only tested with 3 assets.

[/quote]



Thanks for the excellant tip Chris!



This came in super handy for me using the new Calendar Search Page, where I needed to do a GroupBy on the event assets event_start_date keyword. But of course that doesn't order correctly when you events across months, because the "30th of May" will come before the "3rd of June" !!



Luckily I was able to use asset_attribute_start_date along with the keyword modifier like this:


    asset_attribute_start_date^date_format:Y-m-d


And then I just use a bit of JS to reformat back into a nice user visible format on the page.

Hope this helps someone in the future.
Perhaps it may even be a good thing to add to Squizs Matrix testsuite as its quite a tricky use of both the GroupBy and keyword modifiers in combination.