Bug 33217: Allow specifiying sort field and order for authro links

When using the facets for author, i.e. limiting a search, it makes sense to preserve the default sort order for the results (relevance, etc)

When clicking on an author to search the catalog for all works by an author, it would be nice to be able to optionally specify sorting for the listing - i.e. publication date, or title

This patch adds two new system preferences:
AuthorLinkSortBy
AuthorLinkSortOrder

To test:
1 - Do a search in intranet and staff for 'austen'
    or an author you have multiple titles from
2 - Click the linked name
3 - Note a new search is performed, sorted by field from
    defaultSortField  preference
4 - Apply patch, updatedatabase, restart_all
5 - Ensure nothing has changed by searching again
6 - Set AuthorLinkSortBy to 'date of publication' and
    AuthorLinkSortORder to asc
7 - Search again, comfirm links obey sorting specific above
8 - Test other values - confirm links are updated in both staff/opac
    and results/details

Signed-off-by: Andrew Fuerste-Henry <andrewfh@dubcolib.org>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Nick Clemens 2023-03-13 19:45:49 +00:00 committed by Tomas Cohen Arazi
parent 51ef0f688e
commit 4b71a85e13
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
7 changed files with 125 additions and 9 deletions

View file

@ -98,7 +98,8 @@ sub get_xslt_sysprefs {
OPACResultsLibrary OPACShowOpenURL
OpenURLResolverURL OpenURLImageLocation
OPACResultsMaxItems OPACResultsMaxItemsUnavailable OPACResultsUnavailableGroupingBy
OpenURLText OPACShowMusicalInscripts OPACPlayMusicalInscripts ContentWarningField / )
OpenURLText OPACShowMusicalInscripts OPACPlayMusicalInscripts ContentWarningField
AuthorLinkSortBy AuthorLinkSortOrder / )
{
my $sp = C4::Context->preference( $syspref );
next unless defined($sp);

View file

@ -77,6 +77,8 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
('AuthorityXSLTOpacDetailsDisplay','','','Enable XSL stylesheet control over authority details page in the OPAC','Free'),
('AuthorityXSLTOpacResultsDisplay','','','Enable XSL stylesheet control over authority results page in the OPAC','Free'),
('AuthorityXSLTResultsDisplay','','','Enable XSL stylesheet control over authority results page display on intranet','Free'),
('AuthorLinkSortBy','default','call_number|pubdate|acqdate|title','Specify the default field used for sorting when click author links','Choice'),
('AuthorLinkSortOrder','asc','asc|dsc|az|za','Specify the default sort order for author links','Choice'),
('AuthSuccessLog','0',NULL,'If enabled, log successful authentications','YesNo'),
('autoBarcode','OFF','incremental|annual|hbyymmincr|EAN13|OFF','Used to autogenerate a barcode: incremental will be of the form 1, 2, 3; annual of the form 2007-0001, 2007-0002; hbyymmincr of the form HB08010001 where HB=Home Branch','Choice'),
('autoControlNumber','OFF','biblionumber|OFF','Used to autogenerate a Control Number: biblionumber will be as biblionumber, OFF will leave the field as it is;','Choice'),

View file

@ -174,6 +174,23 @@ Searching:
dsc: descending.
az: from A to Z.
za: from Z to A.
-
- By default, sort search results from author links by
- pref: AuthorLinkSortBy
default: default
choices:
default: obey default sort field and order specified in defaultSortField or OPACdefaultSortField
call_number: call number
pubdate: date of publication
acqdate: date added
title: title
- ','
- pref: AuthorLinkSortOrder
choices:
asc: ascending.
dsc: descending.
az: from A to Z.
za: from Z to A.
-
- When limiting search results with a library or library group, limit by the item's
- pref: SearchLimitLibrary

View file

@ -24,6 +24,8 @@
<xsl:variable name="OPACBaseURL" select="marc:sysprefs/marc:syspref[@name='OPACBaseURL']"/>
<xsl:variable name="SubjectModifier"><xsl:if test="marc:sysprefs/marc:syspref[@name='TraceCompleteSubfields']='1'">,complete-subfield</xsl:if></xsl:variable>
<xsl:variable name="UseAuthoritiesForTracings" select="marc:sysprefs/marc:syspref[@name='UseAuthoritiesForTracings']"/>
<xsl:variable name="AuthorLinkSortBy" select="marc:sysprefs/marc:syspref[@name='AuthorLinkSortBy']"/>
<xsl:variable name="AuthorLinkSortOrder" select="marc:sysprefs/marc:syspref[@name='AuthorLinkSortOrder']"/>
<xsl:variable name="TraceSubjectSubdivisions" select="marc:sysprefs/marc:syspref[@name='TraceSubjectSubdivisions']"/>
<xsl:variable name="Show856uAsImage" select="marc:sysprefs/marc:syspref[@name='Display856uAsImage']"/>
<xsl:variable name="DisplayIconsXSLT" select="marc:sysprefs/marc:syspref[@name='DisplayIconsXSLT']"/>
@ -155,12 +157,16 @@
<xsl:call-template name="showAuthor">
<xsl:with-param name="authorfield" select="marc:datafield[@tag=100 or @tag=110 or @tag=111]"/>
<xsl:with-param name="UseAuthoritiesForTracings" select="$UseAuthoritiesForTracings"/>
<xsl:with-param name="AuthorLinkSortOrder" select="$AuthorLinkSortOrder"/>
<xsl:with-param name="AuthorLinkSortBy" select="$AuthorLinkSortBy"/>
</xsl:call-template>
<!-- #13382 Suppress 700$i and 7xx/@ind2=2 -->
<xsl:call-template name="showAuthor">
<xsl:with-param name="authorfield" select="marc:datafield[(@tag=700 or @tag=710 or @tag=711) and not(@ind2=2) and not(marc:subfield[@code='i'])]"/>
<xsl:with-param name="UseAuthoritiesForTracings" select="$UseAuthoritiesForTracings"/>
<xsl:with-param name="AuthorLinkSortOrder" select="$AuthorLinkSortOrder"/>
<xsl:with-param name="AuthorLinkSortBy" select="$AuthorLinkSortBy"/>
</xsl:call-template>
<xsl:if test="$DisplayIconsXSLT!='0' and $materialTypeCode!=''">
@ -1608,6 +1614,8 @@
<xsl:template name="showAuthor">
<xsl:param name="authorfield"/>
<xsl:param name="UseAuthoritiesForTracings"/>
<xsl:param name="AuthorLinkSortBy"/>
<xsl:param name="AuthorLinkSortOrder"/>
<xsl:if test="count($authorfield)&gt;0">
<h5 class="author">
<xsl:for-each select="$authorfield">
@ -1621,10 +1629,29 @@
<a>
<xsl:choose>
<xsl:when test="marc:subfield[@code=9] and $UseAuthoritiesForTracings='1'">
<xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=an:<xsl:value-of select="str:encode-uri(marc:subfield[@code=9], true())"/></xsl:attribute>
<xsl:attribute name="href">
<xsl:text>/cgi-bin/koha/catalogue/search.pl?q=an:</xsl:text>
<xsl:value-of select="str:encode-uri(marc:subfield[@code=9], true())"/>
<xsl:if test="$AuthorLinkSortBy!='default'">
<xsl:text>&amp;sort_by=</xsl:text>
<xsl:value-of select="$AuthorLinkSortBy"/>
<xsl:text>_</xsl:text>
<xsl:value-of select="$AuthorLinkSortOrder"/>
</xsl:if>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=au:"<xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/>"</xsl:attribute>
<xsl:attribute name="href">
<xsl:text>/cgi-bin/koha/catalogue/search.pl?q=au:"</xsl:text>
<xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/>
<xsl:text>"</xsl:text>
<xsl:if test="$AuthorLinkSortBy!='default'">
<xsl:text>&amp;sort_by=</xsl:text>
<xsl:value-of select="$AuthorLinkSortBy"/>
<xsl:text>_</xsl:text>
<xsl:value-of select="$AuthorLinkSortOrder"/>
</xsl:if>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>

View file

@ -24,6 +24,8 @@
<xsl:variable name="AlternateHoldingsSubfields" select="substring(marc:sysprefs/marc:syspref[@name='AlternateHoldingsField'], 4)"/>
<xsl:variable name="AlternateHoldingsSeparator" select="marc:sysprefs/marc:syspref[@name='AlternateHoldingsSeparator']"/>
<xsl:variable name="UseAuthoritiesForTracings" select="marc:sysprefs/marc:syspref[@name='UseAuthoritiesForTracings']"/>
<xsl:variable name="AuthorLinkSortBy" select="marc:sysprefs/marc:syspref[@name='AuthorLinkSortBy']"/>
<xsl:variable name="AuthorLinkSortOrder" select="marc:sysprefs/marc:syspref[@name='AuthorLinkSortOrder']"/>
<xsl:variable name="DisplayIconsXSLT" select="marc:sysprefs/marc:syspref[@name='DisplayIconsXSLT']"/>
<xsl:variable name="IntranetBiblioDefaultView" select="marc:sysprefs/marc:syspref[@name='IntranetBiblioDefaultView']"/>
<xsl:variable name="OpacSuppression" select="marc:sysprefs/marc:syspref[@name='OpacSuppression']"/>
@ -350,10 +352,29 @@
<a>
<xsl:choose>
<xsl:when test="marc:subfield[@code=9] and $UseAuthoritiesForTracings='1'">
<xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=an:<xsl:value-of select="str:encode-uri(marc:subfield[@code=9], true())"/></xsl:attribute>
<xsl:attribute name="href">
<xsl:text>/cgi-bin/koha/catalogue/search.pl?q=an:</xsl:text>
<xsl:value-of select="str:encode-uri(marc:subfield[@code=9], true())"/>
<xsl:if test="$AuthorLinkSortBy!='default'">
<xsl:text>&amp;sort_by=</xsl:text>
<xsl:value-of select="$AuthorLinkSortBy"/>
<xsl:text>_</xsl:text>
<xsl:value-of select="$AuthorLinkSortOrder" />
</xsl:if>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=au:"<xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/>"</xsl:attribute>
<xsl:attribute name="href">
<xsl:text>/cgi-bin/koha/catalogue/search.pl?q=au:"</xsl:text>
<xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/>
<xsl:text>"</xsl:text>
<xsl:if test="$AuthorLinkSortBy!='default'">
<xsl:text>&amp;sort_by=</xsl:text>
<xsl:value-of select="$AuthorLinkSortBy"/>
<xsl:text>_</xsl:text>
<xsl:value-of select="$AuthorLinkSortOrder" />
</xsl:if>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="chopPunctuation">

View file

@ -26,6 +26,8 @@
<xsl:variable name="SubjectModifier"><xsl:if test="marc:sysprefs/marc:syspref[@name='TraceCompleteSubfields']='1'">,complete-subfield</xsl:if></xsl:variable>
<xsl:variable name="UseAuthoritiesForTracings" select="marc:sysprefs/marc:syspref[@name='UseAuthoritiesForTracings']"/>
<xsl:variable name="AuthorLinkSortBy" select="marc:sysprefs/marc:syspref[@name='AuthorLinkSortBy']"/>
<xsl:variable name="AuthorLinkSortOrder" select="marc:sysprefs/marc:syspref[@name='AuthorLinkSortOrder']"/>
<xsl:variable name="TraceSubjectSubdivisions" select="marc:sysprefs/marc:syspref[@name='TraceSubjectSubdivisions']"/>
<xsl:variable name="Show856uAsImage" select="marc:sysprefs/marc:syspref[@name='OPACDisplay856uAsImage']"/>
<xsl:variable name="OPACTrackClicks" select="marc:sysprefs/marc:syspref[@name='TrackClicks']"/>
@ -174,6 +176,8 @@
<xsl:call-template name="showAuthor">
<xsl:with-param name="authorfield" select="marc:datafield[(@tag=100 or @tag=110 or @tag=111)]"/>
<xsl:with-param name="UseAuthoritiesForTracings" select="$UseAuthoritiesForTracings"/>
<xsl:with-param name="AuthorLinkSortOrder" select="$AuthorLinkSortOrder"/>
<xsl:with-param name="AuthorLinkSortBy" select="$AuthorLinkSortBy"/>
<xsl:with-param name="materialTypeLabel" select="$materialTypeLabel"/>
<xsl:with-param name="theme" select="$theme"/>
</xsl:call-template>
@ -182,6 +186,8 @@
<!-- #13382 suppress 700$i and 7xx/@ind2=2 -->
<xsl:with-param name="authorfield" select="marc:datafield[(@tag=700 or @tag=710 or @tag=711) and not(@ind2=2) and not(marc:subfield[@code='i'])]"/>
<xsl:with-param name="UseAuthoritiesForTracings" select="$UseAuthoritiesForTracings"/>
<xsl:with-param name="AuthorLinkSortOrder" select="$AuthorLinkSortOrder"/>
<xsl:with-param name="AuthorLinkSortBy" select="$AuthorLinkSortBy"/>
<xsl:with-param name="materialTypeLabel" select="$materialTypeLabel"/>
<xsl:with-param name="theme" select="$theme"/>
</xsl:call-template>
@ -1802,6 +1808,8 @@
<xsl:template name="showAuthor">
<xsl:param name="authorfield" />
<xsl:param name="UseAuthoritiesForTracings" />
<xsl:param name="AuthorLinkSortBy"/>
<xsl:param name="AuthorLinkSortOrder"/>
<xsl:param name="materialTypeLabel" />
<xsl:param name="theme" />
<xsl:if test="count($authorfield)&gt;0">
@ -1831,10 +1839,29 @@
<a>
<xsl:choose>
<xsl:when test="marc:subfield[@code=9] and $UseAuthoritiesForTracings='1'">
<xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=an:"<xsl:value-of select="str:encode-uri(marc:subfield[@code=9], true())"/>"</xsl:attribute>
<xsl:attribute name="href">
<xsl:text>/cgi-bin/koha/opac-search.pl?q=an:</xsl:text>
<xsl:value-of select="str:encode-uri(marc:subfield[@code=9], true())"/>
<xsl:if test="$AuthorLinkSortBy!='default'">
<xsl:text>&amp;sort_by=</xsl:text>
<xsl:value-of select="$AuthorLinkSortBy"/>
<xsl:text>_</xsl:text>
<xsl:value-of select="$AuthorLinkSortOrder" />
</xsl:if>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=au:"<xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/>"</xsl:attribute>
<xsl:attribute name="href">
<xsl:text>/cgi-bin/koha/opac-search.pl?q=au:"</xsl:text>
<xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/>
<xsl:text>"</xsl:text>
<xsl:if test="$AuthorLinkSortBy!='default'">
<xsl:text>&amp;sort_by=</xsl:text>
<xsl:value-of select="$AuthorLinkSortBy"/>
<xsl:text>_</xsl:text>
<xsl:value-of select="$AuthorLinkSortOrder" />
</xsl:if>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:attribute name="class">contributors</xsl:attribute>

View file

@ -28,6 +28,8 @@
<xsl:variable name="OPACResultsUnavailableGroupingBy" select="marc:sysprefs/marc:syspref[@name='OPACResultsUnavailableGroupingBy']"/>
<xsl:variable name="UseControlNumber" select="marc:sysprefs/marc:syspref[@name='UseControlNumber']"/>
<xsl:variable name="UseAuthoritiesForTracings" select="marc:sysprefs/marc:syspref[@name='UseAuthoritiesForTracings']"/>
<xsl:variable name="AuthorLinkSortBy" select="marc:sysprefs/marc:syspref[@name='AuthorLinkSortBy']"/>
<xsl:variable name="AuthorLinkSortOrder" select="marc:sysprefs/marc:syspref[@name='AuthorLinkSortOrder']"/>
<xsl:variable name="OPACResultsLibrary" select="marc:sysprefs/marc:syspref[@name='OPACResultsLibrary']"/>
<xsl:variable name="hidelostitems" select="marc:sysprefs/marc:syspref[@name='hidelostitems']"/>
<xsl:variable name="DisplayOPACiconsXSLT" select="marc:sysprefs/marc:syspref[@name='DisplayOPACiconsXSLT']"/>
@ -525,10 +527,29 @@
<a>
<xsl:choose>
<xsl:when test="marc:subfield[@code=9] and $UseAuthoritiesForTracings='1'">
<xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=an:<xsl:value-of select="str:encode-uri(marc:subfield[@code=9], true())"/></xsl:attribute>
<xsl:attribute name="href">
<xsl:text>/cgi-bin/koha/opac-search.pl?q=an:</xsl:text>
<xsl:value-of select="str:encode-uri(marc:subfield[@code=9], true())"/>
<xsl:if test="$AuthorLinkSortBy!='default'">
<xsl:text>&amp;sort_by=</xsl:text>
<xsl:value-of select="$AuthorLinkSortBy"/>
<xsl:text>_</xsl:text>
<xsl:value-of select="$AuthorLinkSortOrder" />
</xsl:if>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=au:"<xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/>"</xsl:attribute>
<xsl:attribute name="href">
<xsl:text>/cgi-bin/koha/opac-search.pl?q=au:"</xsl:text>
<xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/>
<xsl:text>"</xsl:text>
<xsl:if test="$AuthorLinkSortBy!='default'">
<xsl:text>&amp;sort_by=</xsl:text>
<xsl:value-of select="$AuthorLinkSortBy"/>
<xsl:text>_</xsl:text>
<xsl:value-of select="$AuthorLinkSortOrder" />
</xsl:if>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="chopPunctuation">