What is the default sorting logic for the same Metadata tag?

52 views
Skip to first unread message

fa...@selensoft.com

unread,
Apr 8, 2021, 9:52:12 AM4/8/21
to DSpace Community
Hi,
When multiple values are entered in the same metadata tag, what is the sorting method?
For example I input three authors to tag dc.contributor.author like below:
A,name1
B,name2
C,name3

In which order they are shown in both simple item view or full item view seems random. How can I figure it out? Or does anybody have any idea?
Best regards, 

alaw

unread,
Apr 9, 2021, 12:26:08 PM4/9/21
to DSpace Community
In my experience, multiple values for the same field are listed in the order they were submitted. You can change that order by exporting the metadata for that item and changing it in the CSV.

fa...@selensoft.com

unread,
Apr 10, 2021, 5:05:26 AM4/10/21
to DSpace Community
Dear alaw, thank you very much for your comment. 
My tests show that the sorting of different values for a specific tag is completely random. I suspect that the sorting is based on a guid value.
I use REST to insert dspace items. I have a sample item with 9 authors. Every time I run the insert script with postman runner, the order of the authors changes. I tried adding delays between author value inserts, but the randomness still continue. So I believe that it is not based on insert datetime. 

Does anybody have any idea on which part of the code is this behavior related?

Mark H. Wood

unread,
Apr 12, 2021, 9:47:41 AM4/12/21
to dspace-c...@googlegroups.com
On Sat, Apr 10, 2021 at 02:05:26AM -0700, fa...@selensoft.com wrote:
> Dear alaw, thank you very much for your comment.
> My tests show that the sorting of different values for a specific tag is
> completely random. I suspect that the sorting is based on a guid value.
> I use REST to insert dspace items. I have a sample item with 9 authors.
> Every time I run the insert script with postman runner, the order of the
> authors changes. I tried adding delays between author value inserts, but
> the randomness still continue. So I believe that it is not based on insert
> datetime.
>
> Does anybody have any idea on which part of the code is this behavior
> related?

I haven't looked for specific places in the code.

Metadata value entries (in the 'metadatavalue' database table) have a
'place' column which can be used to order multiple values of a given
metadata field of a given object. So, you could look for code which
is aware of the 'place' column.

If it has not been thought that the order of values is significant in
a specific field, that field may not be sorted by DSpace, either in
DSpace code or in database queries. So values might have appropriate
'place' values stored but not used.

If an RDBMS query does not request sorting, the values may be returned
in whatever order is convenient for the RDBMS, and that order may
change over time as the RDBMS reorganizes its data pages.

You mention that you are using REST to insert these Items. The REST
code adds metadata values to the Item one at a time.
(ItemsResource.addItemMetadata) This calls
'DSpaceObjectServiceImpl.addMetadata', which eventually makes an
internal call to 'addMetadata(Context context, T dso, MetadataField
metadataField, String lang, List<String> values, List<String>
authorities, List<Integer> confidences)'. This method sets the
'place' of each new value to the number of values stored for that
field, so the 'place' values in the database should be correct for
order of entry.

But the code which retrieves these values for you may not be using
'place' to sort them. And there is no guaranteed order of retrieval
unless a SORT clause is included in the database query. So, I would
examine the code that formats an Item's metadata for display in
whichever UI you are using.

> On Friday, April 9, 2021 at 7:26:08 PM UTC+3 alaw wrote:
>
> > In my experience, multiple values for the same field are listed in the
> > order they were submitted. You can change that order by exporting the
> > metadata for that item and changing it in the CSV.
> >
> > On Thursday, April 8, 2021 at 9:52:12 AM UTC-4 fa...@selensoft.com wrote:
> >
> >> Hi,
> >> When multiple values are entered in the same metadata tag, what is the
> >> sorting method?
> >> For example I input three authors to tag dc.contributor.author like below:
> >> A,name1
> >> B,name2
> >> C,name3
> >>
> >> In which order they are shown in both simple item view or full item view
> >> seems random. How can I figure it out? Or does anybody have any idea?
> >> Best regards,
> >>
> >
>
> --
> All messages to this mailing list should adhere to the Code of Conduct: https://duraspace.org/about/policies/code-of-conduct/
> ---
> You received this message because you are subscribed to the Google Groups "DSpace Community" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to dspace-communi...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/dspace-community/73ef6355-856a-4261-87ca-54f25aa668dcn%40googlegroups.com.


--
Mark H. Wood
Lead Technology Analyst

University Library
Indiana University - Purdue University Indianapolis
755 W. Michigan Street
Indianapolis, IN 46202
317-274-0749
www.ulib.iupui.edu
signature.asc

fa...@selensoft.com

unread,
Apr 19, 2021, 5:32:48 AM4/19/21
to DSpace Community
Dear Mark,
Firstly thank you very much for your detailed answer. 
I did my tests with the same item and same metadata in 3 methods
1 - Manual submission
2 - csv import
3 - post via REST

When I use method 1 and 2, place field in metadatavalue table got updated in incrementing integers in correct order. This explains alaw's method to reorder metadata values. 

But when I use method 3 (REST) the place field is not updated. It is null for all metadata values of the item. 
We use version 6.3
I want to understand if this problem has ever been spotted before, solved in later releases, and the specific code section if I can do a fix.

What is your advice?
Best regards.

fa...@selensoft.com

unread,
Apr 24, 2021, 11:46:12 AM4/24/21
to DSpace Community
I tested inserting an item with multiple authors using REST in Dspace version 6.4.
Unfortunately, the field place gets static value ("1") for all authors. So this problem still continue in latest version of Dspace 6
Reply all
Reply to author
Forward
0 new messages