MyCoRe-Org/mir-alias-plugin

alias relatedItem match priority is incomplete

Closed this issue · 0 comments

We have the alias publikationen/kultgep-colloquien/3/schroeder-kadar_harfenisten/file-4

The document is found by alias, then the following search is executed:
https://perspectivia.net/servlets/solr/select?q=mods.relatedItem:repper_mods_00000836&fl=id,alias&XSL.Style=xml

It results in:

<doc>
<str name="id">pnet_mods_00003924</str>
<str name="alias">9</str>
</doc>
<doc>
<str name="id">pnet_mods_00001163</str>
<str name="alias">8</str>
</doc>
<doc>
<str name="id">pnet_mods_00000879</str>
<str name="alias">7</str>
</doc>
<doc>
<str name="id">ploneimport_mods_00010432</str>
<str name="alias">4</str>
</doc>
<doc>
<str name="id">ploneimport_mods_00010441</str>
<str name="alias">5</str>
</doc>
<doc>
<str name="id">ploneimport_mods_00010456</str>
<str name="alias">6</str>
</doc>
<doc>
<str name="id">ploneimport_mods_00010398</str>
<str name="alias">2</str>
</doc>
<doc>
<str name="id">ploneimport_mods_00010418</str>
<str name="alias">3</str>
</doc>
<doc>
<str name="id">ploneimport_mods_00010380</str>
<str name="alias">1-2014</str>
</doc>

The alias-plugin now gets a mismatch while resolving:
3/schroeder-kadar_harfenisten/file-4

I would expect that this will be resolved to new relatedItem: ploneimport_mods_00010418

schroeder-kadar_harfenisten/file-4

but instead it will be resolved to new relatedItem: ploneimport_mods_00010432

3/schroeder-kadar_harfenisten/file-
2021-07-22T10:10:58,183 INFO  administrator MCRAliasContentServlet: Check if alias path context 3/schroeder-kadar_harfenisten/file-4 exists for document/derivate relations on repper_mods_00000836
2021-07-22T10:10:58,184 DEBUG administrator MCRAliasContentServlet: Process Alias Path Context: Try to shrink Alias Path Context 3/schroeder-kadar_harfenisten/file-4
2021-07-22T10:10:58,184 DEBUG administrator MCRAliasContentServlet: ---- Process Alias Path Context: 4 found in 3/schroeder-kadar_harfenisten/file-4. Shrink aliasPathContext into 3/schroeder-kadar_harfenisten/file-
2021-07-22T10:10:58,184 DEBUG administrator MCRAliasContentServlet: Process Alias Path Context: Alias Path Context 3/schroeder-kadar_harfenisten/file-4 found in Document ploneimport_mods_00010432
2021-07-22T10:10:58,185 DEBUG administrator MCRAliasContentServlet: Process Alias Path Context:  New Alias Path Context is [3/schroeder-kadar_harfenisten/file-]

The code which produces the error is:

                    for (SolrDocument relatedDocument : relatedDocuments) {

                        String currentAliasOrig = (String) relatedDocument.getFieldValue(ALIAS);

                        if (currentAliasOrig != null) {
                            String currentAlias = currentAliasOrig.toLowerCase();
                            String possibleAliasPathContextAfter = aliasPathContext.replaceFirst(currentAlias, "");
                            
                            if (nextAliasPathContextAfter.length() > possibleAliasPathContextAfter.length()) {
                                nextAliasPathContextAfter = possibleAliasPathContextAfter;       
                                relatedObjectId = (String) relatedDocument.getFieldValue(OBJECT_ID);
                                
                                LOGGER.debug("---- Process Alias Path Context: " + currentAlias + " found in " + aliasPathContext + ". Shrink aliasPathContext into " + nextAliasPathContextAfter);
                            }
                        }
                    }

This Code assumes that the longest alias is the right one but there should be a second priority if the length is the same.

/schroeder-kadar_harfenisten/file-4
vs.
3/schroeder-kadar_harfenisten/file-

The seconds priority should be the position of the alias. If the position is lower, then it should be the next alias.

Then i also like to question if this mechanism should use startsWith() and substring instead of replace, or is there a valid case where alias is cut at the end?