12

I have "text_general" field in schema.xml

<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/><filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
</fieldType>

I have stored documents:

document1:
   spell = "contro un indice generale dei prezzi salito del 2, 1%. Rincari ben piщ evidenti, tra i prodotti da bar"
   testata = "Mattino di Padova (Il)"

document2:
   spell="con i prodotti di qualitа vinco la crisi dei consumi Farinetti: con"
   testata = "Italia Oggi"

document3
   spell = "convenienza Il 2008 porta i primi aumenti nei pre zi L'Ipercoop cresce il listino"
   testata = "Nuova Ferrara (La)"

"spell" and "testata" fields has a "text_general" type.

Searching working fine for me:

http://localhost:8080/solr/select?q={!type=edismax qf=spell v='co*'}

But with sorting exists some problem:

http://localhost:8080/solr/select?q={!type=edismax qf=spell v='co*'}&sort=testata desc

It returns me this result:

    document1:
       spell = "contro un indice generale dei prezzi salito del 2, 1%. Rincari ben piщ evidenti, tra i prodotti da bar"
       testata = "Mattino di Padova (Il)"

    document2:
       spell="con i prodotti di qualitа vinco la crisi dei consumi Farinetti: con"
       testata = "Italia Oggi"

    document3
       spell = "convenienza Il 2008 porta i primi aumenti nei pre zi L'Ipercoop cresce il listino"
       testata = "Nuova Ferrara (La)"

I don`t understand why my sorting working not properly. It should returns me result like this:

    document3
       spell = "convenienza Il 2008 porta i primi aumenti nei pre zi L'Ipercoop cresce il listino"
       testata = "Nuova Ferrara (La)"

    document1:
       spell = "contro un indice generale dei prezzi salito del 2, 1%. Rincari ben piщ evidenti, tra i prodotti da bar"
       testata = "Mattino di Padova (Il)"

    document2:
       spell="con i prodotti di qualitа vinco la crisi dei consumi Farinetti: con"
       testata = "Italia Oggi"
javanna
  • 59,145
  • 14
  • 144
  • 125
vladimir
  • 695
  • 3
  • 10
  • 23

1 Answers1

28

Sorting doesn't work good on multivalued and tokenized fields.
As testata has been defined with text_general field type, it will be tokensized and hence the sort would not work fine.

Sorting can be done on the "score" of the document, or on any multiValued="false" indexed="true" field provided that field is either non-tokenized (ie: has no Analyzer) or uses an Analyzer that only produces a single Term (ie: uses the KeywordTokenizer)

Source: http://wiki.apache.org/solr/CommonQueryParameters#sort

Use string as the field type and copy the title field into the new field.

<field name="testata_sort" type="string" indexed="true" stored="false"/>

<copyField source="testata" dest="testata_sort" />  
vegemite4me
  • 6,621
  • 5
  • 53
  • 79
Jayendra
  • 52,349
  • 4
  • 80
  • 90
  • +1. That's what I ended up doing to enable "sort" on multivalued fields: had each one's first value duplicated in a corresponding string field, and sort on those. – Shivan Dragon Oct 23 '12 at 10:41
  • Thank you! I was using a "partial matching" field type and couldn't figure out why my results were returning completely unsorted. Switching to a regular text field fixed that up :) – masterchief Aug 05 '14 at 23:05