Sort By Created Date and Metadata Date Field


(Nick Papadatos) #1

Matrix Version: 5.3

Hi squiz folk,
Is there way to sort by Created Date and a Metadata Date field values form a single search asset?

I essentially have an Search asset pointing to two locations. 1 broad news and 2 faculty news
1 - faculty news managed via the %asset_published_readabledate% keyword
2 - broad news has the %asset_metadata_pub_date% keyword

The search asset default format %asset_contents_paint_xxxx% the paint layout sorts the layout between the two locations via conditions.

When I change the date via the metadata to one of the root node assets (to a date earlier from the other root node assets) the order doesn’t change.

14%20pm

Has anyone been able to get around this?

I hope I have given enough info
Cheers
N


(Emily) #2

Hi Nicky,

Not sure I 100% understand what your current setup is, but hopefully the info I can give will help. :slight_smile:

Is there way to sort by Created Date and a Metadata Date field values form a single search asset?

You can set the “sort by” options (including the default sort) on the “Asset Sorting” screen - as a Backend editor. There are options for both “when the asset was created” (first dropdown box, in my 5.5 version), and “By metadata field value”.

For news items, I usually have a Metadata field for “published date”, which defaults to the created date unless altered in the metadata. This allows Simple Edit / Edit+ editors to update the metadata field to change the Published date (e.g. if creating the article in advance of publication, and setting a Future Status to go Live).

These “Sort by” rules will apply to all assets in the search results (i.e. all root node locations).

Did this help?
Any other info you needed?


(Nick Papadatos) #3

Thanks Emily

I’m pretty familiar with what you proposed. The issue is that the “broader news” doesn’t have a metadata date field (legacy too late to change) but the specific faculty news does. My paint layout has the following condition:

    %begin_Scitech%
     .
     .
    <time class="news-list__pubdate dt-published">%asset_metadata_pub_date%</time>
      %else_Scitech%
   %begin_News%
    .
    .
    <time class="news-list__pubdate dt-published">%asset_published_readabledate%</time>
     %end_News%
  %end_Scitech%

So when I change the metadata date field from the faculty news item to a date older than the created date the sorting doesn’t work:

When I try and sort by metadata date field it screws up the boarder news etc

Thanks
N


(Emily) #4

Ah, I think I understand more now. So it is more the issue of combining the 2 different “sort by” into one singular list?

Can a metadata field (text field) be cascaded onto the older news items, with a default value of %asset_published_readabledate%, and then the faculty-news root node have this same field cascaded down with the keyword %asset_metadata_pub_date% ?
Or are the news stories intertwined under the same root node(s)?

i.e. you will end up with a single metadata field to “sort by” in the Search (or asset listings), but the value that it holds will be set depending on whether its the older/broader news, or the faculty news.

This is just off the top of my head.
Of course Javascript could be written to manually sort the results after Matrix delivers them, but the beauty of Matrix is that often we can avoid this double-process.

I’ll keep mulling it over while I’m out this evening, and if anything more robust comes to mind I’ll let you know. I’m sure some of the Squiz staff would have some tricks they’ve used before.


(Nick Papadatos) #5

So it is more the issue of combining the 2 different “sort by” into one singular list?

Correct. There’s more than one root node and this request is more of an isolated one. So not worth the effort to add the metadata date field but would in the near future if we’re going to update the news section. Is’ a shame the search and asst listings assets don’t have multiple sort by i.e readabledate and or other.

Cheers
N


(Bart Banda) #6

Have you tried using the Sort By Asset Keyword Value field and putting a keyword there that prints the metadata field if it has one, if not, prints the published date?

Something like: asset_metadata_date^empty:{asset_published_date}}

Might have to make the keywords output in ISO format or as a timestamp as the search page will only sort by alphabetical order on that field, it doesn’t know anything about dates.


(Nick Papadatos) #7

Thanks Bart

the sort by keyword logic seems sound:
asset_metadata_pub_date^empty:{asset_published_date}

But I’m still getting some weird sorting happening.

Regards
Nick


(Peter McLeod) #8

Hi
Could maybe trying changing the sort date formats to a timestamp format so the sorting is just happening on a numeric value? eg:

asset_metadata_pub_date_U^empty:{asset_published_U}

Thanks
Peter


(Nick Papadatos) #9

Thanks Peter,
That didn’t work either.

Regards
N


(Bart Banda) #10

It may be a limitation of that version of Matrix, as it’s quite old now and I have feeling it might have been fixed since then.

The only other thing I can think of is to add that extra metadata text field to both assets that tries to reference the other metadata field and if it doesn’t exist, print the published date, something like:

%metadata-F_^empty:{asset_published_U}%

Not sure if that will work though again in that version, or if Matrix will complain and throw errors if you use %metadata-F_% on a metadata screen where that field ID def doesn’t exist.


(Nick Papadatos) #11

I’ll try this on our test instance version 5.5

Thanks
Nick