0
votes

I have these emails : "[email protected]", "[email protected]". I want to sort them

The Solr will return the following result:

[email protected]
[email protected]

I think the correct sort result should be:

[email protected]
[email protected]

The configuration like this:

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

Anyone could help?

The following is solr response:

{ "responseHeader":{ "status":0, "QTime":0, "params":{ "sort":"advertiser_email_t asc", "indent":"true", "q":":", "wt":"json", "response":{"numFound":3,"start":0,"docs":[ { "advertiser_email_t":"[email protected]", "id":"01df4dea-beb3-46fb-940b-78eda109503c" }, { "advertiser_email_t":"[email protected]", "id":"935de002-10e0-437f-a571-e74bb6646228" }, { "advertiser_email_t":"[email protected]", "id":"2a80935e-e520-4c3e-8d56-8e7b1096b372"}] } } 

This is field definition:

<dynamicField name="*_t" type="text_general" indexed="true" stored="true"/>

This is field type 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" />
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
    </fieldType>

After changed field name to "email":

{ "responseHeader": { "status": 0, "QTime": 0, "params": { "sort": "email asc", "indent": "true", "q": ":", "_": "1383822359034", "wt": "json" } }, "response": { "numFound": 2, "start": 0, "docs": [ { "email": "[email protected]", "id": "00000000-0000-0000-0000-000000000002" }, { "email": "[email protected]", "id": "00000000-0000-0000-0000-000000000001" } ] } }

1
Could you add to your post how you perform the sort?cheffe
I passed sort field to Solr, The solr response is { "responseHeader":{ "status":0, "QTime":0, "params":{ "sort":"advertiser_email_t asc", "indent":"true", "q":":", "wt":"json", "response":{"numFound":3,"start":0,"docs":[ { "advertiser_email_t":"[email protected]", "id":"01df4dea-beb3-46fb-940b-78eda109503c" }, { "advertiser_email_t":"[email protected]", "id":"935de002-10e0-437f-a571-e74bb6646228" }, { "advertiser_email_t":"[email protected]", "id":"2a80935e-e520-4c3e-8d56-8e7b1096b372"}] } }staticage
By the response you posted, I can see that you try to sort by a field named advertiser_email_t, whose definition you did not share with us. What field type does it have? Could you post more of your schema.xml so that we can see your field types?cheffe
I add field and field type definitionsstaticage

1 Answers

0
votes

You need to change your query to sort by the field named email instead of advertiser_email_t. Something like

q=*:*&sort=email+asc

As according to the response you posted, you try to sort by the field named advertiser_email_t. This field is of the type text_general you also provided. That field type is tokenized and receives additional tokens by the mapped synonyms.

When reading in the reference about sorting you can see that this cannot work

Solr can sort query responses according to document scores or the value of any indexed field with a single value (that is, any field whose attributes in schema.xml include multiValued="false" and indexed="true"), provided that:

  • the field is non-tokenized (that is, the field has no analyzer and its contents have been parsed into tokens, which would make the sorting inconsistent), or

  • the field uses an analyzer (such as the KeywordTokenizer) that produces only a single term.

But your field named email is fine. It is of type string, which is sortable.