<commit_before><?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:output indent="yes" omit-xml-declaration="no"
       media-type="application/xml" encoding="UTF-8" />

  <!-- 
       Parameters passed by Carrot2 and corresponding to Solr -> Carrot2 field mappings.
   -->
  <xsl:param name="solr.title-field">title</xsl:param>
  <xsl:param name="solr.summary-field">description</xsl:param>
  <xsl:param name="solr.url-field">url</xsl:param>
  <xsl:param name="solr.id-field"></xsl:param>
  <xsl:param name="solr.use-highlighter-output">true</xsl:param>

  <xsl:key name="highlighter"  match="/response/lst[@name='highlighting']/lst" use="@name" />

  <xsl:template match="/">
    <searchresult>
      <!-- Query hint -->
      <query><xsl:value-of select="/response/lst[@name='responseHeader']/lst[@name='params']/str[@name='q']" /></query>

      <!-- Emit documents. -->
      <xsl:for-each select="/response/result/doc">
        <xsl:variable name="docid" select="*[@name = $solr.id-field]" />
        <document>
          <xsl:if test="$solr.id-field != ''">
            <xsl:attribute name="id">
                <xsl:value-of select="$docid" />
            </xsl:attribute>
          </xsl:if>

          <url><xsl:value-of select="*[@name=$solr.url-field]" /></url>
          <title><xsl:value-of select="*[@name=$solr.title-field]" /></title>
          <snippet>
            <xsl:variable name="fragment" select="key('highlighter', $docid)/arr[@name=$solr.summary-field]" />
            <xsl:choose>
              <xsl:when test="$solr.use-highlighter-output = 'true' and $fragment">
                <xsl:for-each select="$fragment/str">
                  ... <xsl:value-of select="." />
                </xsl:for-each>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="*[@name=$solr.summary-field]" />
              </xsl:otherwise>
            </xsl:choose>
          </snippet>
        </document>
      </xsl:for-each>

      <!-- Extract Solr-generated clusters if any. -->
      <xsl:if test="$solr.id-field != '' and /response/arr[@name='clusters']">
        <xsl:comment>Clusters from Solr</xsl:comment>

        <xsl:for-each select="/response/arr[@name = 'clusters']/lst">
          <xsl:call-template name="cluster-adapter" />
        </xsl:for-each>
      </xsl:if>

      <!-- Extra attributes. -->
      <xsl:if test="/response/result/@numFound">
        <attribute key="results-total">
          <value type="java.lang.Long" value="{/response/result/@numFound}" />
        </attribute>
      </xsl:if>
    </searchresult>
  </xsl:template>

  <!-- Solr to Carrot2 cluster adapter. -->  
  <xsl:template name="cluster-adapter">
    <group>
      <xsl:if test="double[@name = 'score']">
        <xsl:attribute name="score"><xsl:value-of select="double[@name = 'score']"/></xsl:attribute>
      </xsl:if>

      <title>
        <xsl:for-each select="arr[@name = 'labels']/str">
          <phrase><xsl:value-of select="." /></phrase>
        </xsl:for-each>
      </title>
      
      <xsl:if test="bool[@name = 'other-topics'] = 'true'">
        <attribute key="other-topics"><value value="true"/></attribute>
      </xsl:if>

      <xsl:for-each select="arr[@name = 'docs']/str">
        <document refid="{.}" />
      </xsl:for-each>
<commit_msg>CARROT-1007: put a " . " separator between multi-value Solr fields<commit_after><?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:output indent="yes" omit-xml-declaration="no"
       media-type="application/xml" encoding="UTF-8" />

  <!-- 
       Parameters passed by Carrot2 and corresponding to Solr -> Carrot2 field mappings.
   -->
  <xsl:param name="solr.title-field">title</xsl:param>
  <xsl:param name="solr.summary-field">description</xsl:param>
  <xsl:param name="solr.url-field">url</xsl:param>
  <xsl:param name="solr.id-field"></xsl:param>
  <xsl:param name="solr.use-highlighter-output">true</xsl:param>

  <xsl:key name="highlighter"  match="/response/lst[@name='highlighting']/lst" use="@name" />

  <xsl:template match="/">
    <searchresult>
      <!-- Query hint -->
      <query><xsl:value-of select="/response/lst[@name='responseHeader']/lst[@name='params']/str[@name='q']" /></query>

      <!-- Emit documents. -->
      <xsl:for-each select="/response/result/doc">
        <xsl:variable name="docid" select="*[@name = $solr.id-field]" />
        <document>
          <xsl:if test="$solr.id-field != ''">
            <xsl:attribute name="id">
                <xsl:value-of select="$docid" />
            </xsl:attribute>
          </xsl:if>

          <url><xsl:value-of select="*[@name=$solr.url-field]" /></url>
          <title><xsl:value-of select="*[@name=$solr.title-field]" /></title>
          <snippet>
            <xsl:variable name="fragment" select="key('highlighter', $docid)/arr[@name=$solr.summary-field]" />
            <xsl:choose>
              <xsl:when test="$solr.use-highlighter-output = 'true' and $fragment">
                <xsl:for-each select="$fragment/str">
                  ... <xsl:value-of select="." />
                </xsl:for-each>
              </xsl:when>
              <xsl:otherwise>
                <xsl:apply-templates select="*[@name=$solr.summary-field]" />
              </xsl:otherwise>
            </xsl:choose>
          </snippet>
        </document>
      </xsl:for-each>

      <!-- Extract Solr-generated clusters if any. -->
      <xsl:if test="$solr.id-field != '' and /response/arr[@name='clusters']">
        <xsl:comment>Clusters from Solr</xsl:comment>

        <xsl:for-each select="/response/arr[@name = 'clusters']/lst">
          <xsl:call-template name="cluster-adapter" />
        </xsl:for-each>
      </xsl:if>

      <!-- Extra attributes. -->
      <xsl:if test="/response/result/@numFound">
        <attribute key="results-total">
          <value type="java.lang.Long" value="{/response/result/@numFound}" />
        </attribute>
      </xsl:if>
    </searchresult>
  </xsl:template>
  
  <xsl:template match="arr/str">
    <xsl:apply-templates />
    <xsl:if test="not(position() = last())">
      <xsl:value-of select="' . '" />
    </xsl:if>
  </xsl:template>

  <!-- Solr to Carrot2 cluster adapter. -->  
  <xsl:template name="cluster-adapter">
    <group>
      <xsl:if test="double[@name = 'score']">
        <xsl:attribute name="score"><xsl:value-of select="double[@name = 'score']"/></xsl:attribute>
      </xsl:if>

      <title>
        <xsl:for-each select="arr[@name = 'labels']/str">
          <phrase><xsl:value-of select="." /></phrase>
        </xsl:for-each>
      </title>
      
      <xsl:if test="bool[@name = 'other-topics'] = 'true'">
        <attribute key="other-topics"><value value="true"/></attribute>
      </xsl:if>

      <xsl:for-each select="arr[@name = 'docs']/str">
        <document refid="{.}" />
      </xsl:for-each>

{'fraction_non_alphanumeric': 0.20971648382960537, 'fraction_numerical': 0.0045590539962957685, 'mean_word_length': 2.5311871227364184, 'pattern_counts': {'":': 0, '<': 189, '<?xml version=': 2, '>': 191, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1463700', 'n_tokens_mistral': 2459, 'n_tokens_neox': 2238, 'n_words': 343}