【问题标题】:In DSpace XMLUI, how can I change the "preview" snippet for search results?在 DSpace XMLUI 中,如何更改搜索结果的“预览”片段?
【发布时间】:2016-03-15 23:25:46
【问题描述】:

当前状态

DSpace XMLUI(以“元数据”为焦点的 Mirage、Mirage 2 主题)默认显示搜索结果列表中的项目如下:

  1. 当在标题/作者/出版商元数据中找到搜索词时,该项目显示为“最近添加”列表(包括摘要的第一部分)。
  2. 当在摘要中找到搜索词时,为项目显示的摘要 sn-p 会“移动”以显示搜索词所在的上下文。
  3. 在提取的全文中找到搜索词时,根本不显示摘要 sn-p。相反,会显示提取的全文的 sn-p 以显示找到搜索词的位置周围的上下文。

在所有三种情况下,搜索词都是粗体的。

这种方法的问题

上述方法会导致用户体验方面的几个问题:

  • 上面的逻辑没有让用户清楚;搜索结果列表可以是显示摘要开头的项目、显示摘要中间部分的项目以及显示全文 sn-p 的项目。
  • 提取的全文可能包含“丑陋”的特殊字符,通常包括文件名、文件大小和其他与用户无关的元数据。
  • 提取的全文可能来自受限制的比特流,预览 sn-p 可能会泄露本应保密的信息(请参阅 this DSpace bug)。

期望的行为

相反,我希望始终为搜索结果列表中的项目显示一个抽象的 sn-p。抽象的 sn-p 可以“转换”以显示搜索词的上下文,但这应该让用户清楚。如果仅在全文文件中找到搜索词,则应显示摘要的开头,并显示属于该项目的全文文件包含搜索词的消息。

【问题讨论】:

    标签: xslt xslt-1.0 user-experience dspace


    【解决方案1】:

    搜索结果列表的摘要/预览 sn-p 部分在 discovery.xml 中生成,例如 starting here 代表 Mirage 2 中文件的当前版本。按如下方式自定义“选择”语句将产生期望的结果(尽管它在 i18n 方面并不稳健):

    <xsl:choose>
      <xsl:when test="dri:list[@n=(concat($handle, ':dc.description.abstract'))]/dri:item/dri:hi">
        <!-- 
            search term found in abstract - show context 
            around search term location(s) 
        -->
        <div class="abstract">
          <strong>Search term found in abstract:</strong>
          <xsl:for-each select="dri:list[@n=(concat($handle, ':dc.description.abstract'))]/dri:item">
            <xsl:text>… </xsl:text><xsl:apply-templates select="."/><xsl:text> …</xsl:text>
            <br/>
          </xsl:for-each>
        </div>
      </xsl:when>
      <xsl:when test="dri:list[@n=(concat($handle, ':dc.description.abstract'))]/dri:item">
        <!-- 
             search term not found in abstract but the item has an abstract 
             - show first part of abstract like in recently added lists 
        -->
        <div class="abstract">
          <xsl:value-of select="util:shortenString(dri:list[@n=(concat($handle, ':dc.description.abstract'))]/dri:item, 220, 10)"/>                       
        </div>
      </xsl:when>
    </xsl:choose>
    <xsl:if test="not(dri:list[@n=(concat($handle, ':dc.description.abstract'))]/dri:item/dri:hi) and dri:list[@n=(concat($handle, ':fulltext'))]">
      <!-- 
          search term not found in abstract but found in fulltext file - 
          show message _instead_ of preview; if there is an abstract 
          then it will already be shown via the choose statement above 
      -->
      <strong>(Search term found in fulltext file)</strong>
    </xsl:if>
    

    【讨论】:

    • 当我尝试实现 util:shortenString 函数时,出现以下错误:org.apache.xpath.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace: util
    • 我通过将其添加到文件开头的 xsl:stylesheet 来修复它:xmlns:util="org.dspace.app.xmlui.utils.XSLUtils" 并且可能还排除了 util 作为结果前缀。
    【解决方案2】:

    感谢 schweerelos!通过您的示例,我们对 discovery.xsl 进行了以下更改:

    首先,我们需要在样式表中添加一个附加项以执行字符串缩短:

    <xsl:stylesheet
        xmlns:util="org.dspace.app.xmlui.utils.XSLUtils"
        ...
        exclude-result-prefixes="xalan encoder i18n dri util ...">
    

    然后我们修改了:fulltext 分支,使其显示摘要的前 220 个字符(只要它存在)。

    <xsl:choose>
        <xsl:when test="dri:list[@n=(concat($handle, ':dc.description.abstract'))]/dri:item/dri:hi">
            <div class="abstract">
                <xsl:for-each select="dri:list[@n=(concat($handle, ':dc.description.abstract'))]/dri:item">
                    <xsl:apply-templates select="."/>
                    <xsl:text>...</xsl:text>
                    <br/>
                </xsl:for-each>
            </div>
        </xsl:when>
    
        <xsl:otherwise> <!-- NEW APPROACH STARTS ON THIS LINE -->
            <div class="abstract">
                <xsl:value-of select="util:shortenString(dri:list[@n=(concat($handle, ':dc.description.abstract'))]/dri:item, 220, 10)"/>
            </div>
        </xsl:otherwise>
    </xsl:choose>
    

    我们发现这是一个可以接受的折衷方案,并提供一致的外观。您可以在记录中提供的 dc.description.abstract 或 dc.description.abstract 的开头看到找到搜索词的位置 (KWIC) 的 Hit Highlighting。

    如果摘要的文本本身目前被禁运(或无限期限制),那么任何原本会在旧演示文稿中显示受限制内容的搜索词只会显示“此项目的摘要受限制...”,因为 dc.description.abstract 字段填充了该文本。

    上述方法(&lt;xsl:otherwise&gt; 部分)替换了以下内容。

    拒绝(交付时)方法:

    <xsl:when test="dri:list[@n=(concat($handle, ':fulltext'))]">
        <div class="abstract">
            <xsl:for-each select="dri:list[@n=(concat($handle, ':fulltext'))]/dri:item">
            <xsl:apply-templates select="."/>
            <xsl:text>...</xsl:text>
            <br/>
            </xsl:for-each>
        </div>
    </xsl:when>
    

    该文件位于意外位置,如果我对开发过程的工作方式有更多了解,我可能会将其放入 OUR 主题文件夹中,但就目前而言,它是在 dri2xhtml-alt 中编辑的主题。我没想到会在那里找到影响此行为的文件,但似乎很清楚它可以在那里更改它。

    \DSpaceRepo\dspace-xmlui\src\main\webapp\themes\dri2xhtml-alt\aspect\artifactbrowser\discovery.xsl

    您应该知道的最后一件事 - 如果您正在编辑此文件并期望更改对您来说很明显,您需要不断清除浏览器历史记录/缓存或执行新的搜索。由于这个原因,编辑过程有点费力(似乎没有反映最新的变化),直到我找到了一个好的工作流程。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-11
      • 1970-01-01
      相关资源
      最近更新 更多