Search code examples
sortingsolrlucenexsdsolr-schema

What do I need to do to make a field in SOLR sortable?


I have a field called "title"

<field name="title" type="text_general" indexed="true" stored="true" required="true" omitNorms="false"/>

Here is the file definition:

<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
  <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
  <filter class="solr.LowerCaseFilterFactory"/>
  <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
  <filter class="solr.LowerCaseFilterFactory"/>
  <filter class="solr.PhoneticFilterFactory" encoder="DoubleMetaphone" inject="true"/>
</analyzer>
<analyzer type="query">
 <tokenizer class="solr.StandardTokenizerFactory"/>
   <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
     <filter class="solr.LowerCaseFilterFactory"/>
     <filter class="solr.PhoneticFilterFactory" encoder="DoubleMetaphone" inject="true"/>
  </analyzer>
</fieldType>

I make my query and try to sort by the [title] field. the log says:

INFO: [] webapp=/solr path=/select/ params={sort=title+asc&start=0&q="course"&wt=json&rows=15&version=2.2indent%3Don} hits=244 status=0 QTime=1

Which means my syntax is probably correct:

q="course"&amp;start=0&amp;rows=15&amp;version=2.2indent=true&amp;wt=json&amp;sort=Title%2Basc&sort=title+asc

The problem is, results do not come back sorted by the [title] field. I think I am missing something in the schema.xml file, but what?


Solution

  • In general you can sort on any field that is single-valued (i.e., not tokenized (unless it uses an analyzer that produces a single term) nor multi-valued) and is indexed. So text and text_* fields are right out for sorting.