0

I am trying to do reranking Queries today.

My features.json looks like this:

    [  
    {
        "name" : "documentRecency",
        "class" : "org.apache.solr.ltr.feature.SolrFeature",
        "params" : {
          "q" : "{!func}recip( ms(NOW,timestamp), 3.16e-11, 1, 1)"
        }
      },
      {
        "name" : "textLengthScore",
        "class" : "org.apache.solr.ltr.feature.SolrFeature",
        "params" : {
          "q" : "{!func}recip(rord(scale(textLength, 0, 1)), 1,1000,1000)"
        }
      },
      {
        "name" : "numCategoriesScore",
        "class" : "org.apache.solr.ltr.feature.SolrFeature",
        "params" : {
          "q" : "{!func}recip(rord(scale(numCategories, 0, 1)), 1,1000,1000)"
        }
      },
      {
        "name" : "numSectionsScore",
        "class" : "org.apache.solr.ltr.feature.SolrFeature",
        "params" : {
          "q" : "{!func}recip( rord(scale(numSections, 0, 1)), 1,1000,1000)"
        }
      },
      {
        "name" : "numLinksScore",
        "class" : "org.apache.solr.ltr.feature.SolrFeature",
        "params" : {
          "q" : "{!func}recip( rord(scale(numLinks, 0, 1)), 1,1000,1000)"
        }
      },
      {
        "name" : "originalScore",
        "class" : "org.apache.solr.ltr.feature.OriginalScoreFeature",
        "params" : {}
      }
    ]

My model.json looks like this:

    {
      "class" : "org.apache.solr.ltr.model.LinearModel",
      "name" : "myModel",
      "features" : [
        { "name" : "documentRecency" },
        { "name" : "textLengthScore" },
        { "name" : "numCategoriesScore" },
        { "name" : "numSectionsScore" },
        { "name" : "numLinksScore" },
        { "name" : "originalScore" }
      ],
      "params" : {
        "weights" : {
          "documentRecency" : 0.2,
          "textLengthScore" : 0.5,
          "numCategoriesScore" : 0.3,
          "numSectionsScore": 0.6,
          "numLinksScore" : 0.4,
          "originalScore" : 0.3
        }
      }
    }

When reranking my Results I get the following error:

"java.lang.RuntimeException: Exception from createWeight for SolrFeature [name=textLengthScore, params={q={!func}recip(rord(scale(textLength, 0, 1)), 1,1000,1000)}] Failed to parse feature query."

What is wrong about this query? I'm trying to get a "textLengthScore" by scaling all textLengths from 0,1 and then score them like its done in documentRecency.

Oh yeah, and here's the schema.xml:

<?xml version="1.0" encoding="UTF-8"?>
<schema name="sem" version="1.6">
  <uniqueKey>id</uniqueKey>
  <fieldType name="string" class="solr.StrField"/>
  <fieldType name="longstring" class="solr.TextField">
    <analyzer type="query">
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.SnowballPorterFilterFactory" language="English"/>
      <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true" tokenizerFactory="solr.StandardTokenizerFactory"/>
    </analyzer>
    <similarity class="solr.ClassicSimilarityFactory"/>
  </fieldType>
  <fieldType name="tstamp" class="solr.DatePointField"/>
  <fieldType name="number" class="solr.TrieIntField" precisionStep="0" docValues="true"/>
  <field name="id" type="string" indexed="true" required="true" stored="true"/>
  <field name="title" type="longstring" indexed="true" required="true" stored="true"/>
  <field name="timestamp" type="tstamp" indexed="true" required="true" stored="true"/>
  <field name="categories" type="longstring" indexed="true" multiValued="true" stored="true"/>
  <field name="text" type="longstring" indexed="true" multiValued="true" stored="true"/>
  <field name="fullText" type="longstring" indexed="true" stored="true"/>
  <field name="links" type="longstring" indexed="true" multiValued="true" stored="true"/>
  <field name="textLength" type="number" indexed="true" stored="true"/>
  <field name="numCategories" type="number" indexed="true" stored="true"/>
  <field name="numLinks" type="number" indexed="true" stored="true"/>
  <field name="numSections" type="number" indexed="true" stored="true"/>
</schema>

1 Answers1

1

I think the error comes from rord() expecting only a fieldname as argument.

You don't need to scale the values before using rord() or ord(), scaling won't affect their lexicographic order so each value index will remain the same as without scaling.

In other words "{!func}recip(rord(textLength), 1,1000,1000)" should be fine.

EricLavault
  • 12,130
  • 3
  • 23
  • 45