Note that there are some explanatory texts on larger screens.

plurals
  1. POSorting Order in Django Haystack SOLR
    text
    copied!<p>I am trying to sort by a date field in Haystack Solr on Django. It has a lot of NULL values. I want the not null values to be sorted and come on top. The -order_by('field') is not doing this. It is bringing the null values between the non-null values. I want the sorting to happen purely on this field irrespective of the scores.</p> <hr> <h2>EDIT</h2> <p>The field in schema.xml</p> <pre><code> &lt;field name="sort_date" type="date" indexed="true" stored="true" multiValued="false" /&gt; &lt;field name="sort_date_exact" type="date" indexed="true" stored="true" multiValued="false" /&gt; </code></pre> <hr> <h2>EDIT</h2> <p>The whole schema.xml without the fields</p> <pre><code> &lt;?xml version="1.0" ?&gt; &lt;!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --&gt; &lt;schema name="default" version="1.4"&gt; &lt;types&gt; &lt;fieldtype name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/&gt; &lt;fieldType name="boolean" class="solr.BoolField" sortMissingLast="true" omitNorms="true"/&gt; &lt;fieldtype name="binary" class="solr.BinaryField"/&gt; &lt;!-- Numeric field types that manipulate the value into a string value that isn't human-readable in its internal form, but with a lexicographic ordering the same as the numeric ordering, so that range queries work correctly. --&gt; &lt;fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" sortMissingLast="true" positionIncrementGap="0"/&gt; &lt;fieldType name="float" class="solr.TrieFloatField" precisionStep="0" omitNorms="true" sortMissingLast="true" positionIncrementGap="0"/&gt; &lt;fieldType name="long" class="solr.TrieLongField" precisionStep="0" omitNorms="true" sortMissingLast="true" positionIncrementGap="0"/&gt; &lt;fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" omitNorms="true" sortMissingLast="true" positionIncrementGap="0"/&gt; &lt;fieldType name="tint" class="solr.TrieIntField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/&gt; &lt;fieldType name="tfloat" class="solr.TrieFloatField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/&gt; &lt;fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/&gt; &lt;fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/&gt; &lt;fieldType name="date" class="solr.TrieDateField" omitNorms="true" precisionStep="0" positionIncrementGap="0"/&gt; &lt;!-- A Trie based date field for faster date range queries and date faceting. --&gt; &lt;fieldType name="tdate" class="solr.TrieDateField" omitNorms="true" precisionStep="6" positionIncrementGap="0"/&gt; &lt;fieldType name="point" class="solr.PointType" dimension="2" subFieldSuffix="_d"/&gt; &lt;fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/&gt; &lt;fieldtype name="geohash" class="solr.GeoHashField"/&gt; &lt;fieldType name="text_general" class="solr.TextField" positionIncrementGap="100"&gt; &lt;analyzer type="index"&gt; &lt;tokenizer class="solr.StandardTokenizerFactory"/&gt; &lt;filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_en.txt" enablePositionIncrements="true" /&gt; &lt;!-- in this example, we will only use synonyms at query time &lt;filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/&gt; --&gt; &lt;filter class="solr.LowerCaseFilterFactory"/&gt; &lt;/analyzer&gt; &lt;analyzer type="query"&gt; &lt;tokenizer class="solr.StandardTokenizerFactory"/&gt; &lt;filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_en.txt" enablePositionIncrements="true" /&gt; &lt;filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/&gt; &lt;filter class="solr.LowerCaseFilterFactory"/&gt; &lt;/analyzer&gt; &lt;/fieldType&gt; &lt;fieldType name="text_en" class="solr.TextField" positionIncrementGap="100"&gt; &lt;analyzer type="index"&gt; &lt;tokenizer class="solr.StandardTokenizerFactory"/&gt; &lt;filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_en.txt" enablePositionIncrements="true" /&gt; &lt;filter class="solr.LowerCaseFilterFactory"/&gt; &lt;filter class="solr.EnglishPossessiveFilterFactory"/&gt; &lt;filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/&gt; &lt;!-- Optionally you may want to use this less aggressive stemmer instead of PorterStemFilterFactory: &lt;filter class="solr.EnglishMinimalStemFilterFactory"/&gt; --&gt; &lt;filter class="solr.PorterStemFilterFactory"/&gt; &lt;/analyzer&gt; &lt;analyzer type="query"&gt; &lt;tokenizer class="solr.StandardTokenizerFactory"/&gt; &lt;filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/&gt; &lt;filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_en.txt" enablePositionIncrements="true" /&gt; &lt;filter class="solr.LowerCaseFilterFactory"/&gt; &lt;filter class="solr.EnglishPossessiveFilterFactory"/&gt; &lt;filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/&gt; &lt;!-- Optionally you may want to use this less aggressive stemmer instead of PorterStemFilterFactory: &lt;filter class="solr.EnglishMinimalStemFilterFactory"/&gt; --&gt; &lt;filter class="solr.PorterStemFilterFactory"/&gt; &lt;/analyzer&gt; &lt;/fieldType&gt; &lt;fieldType name="text_ws" class="solr.TextField" positionIncrementGap="100"&gt; &lt;analyzer&gt; &lt;tokenizer class="solr.WhitespaceTokenizerFactory"/&gt; &lt;/analyzer&gt; &lt;/fieldType&gt; &lt;fieldType name="ngram" class="solr.TextField" &gt; &lt;analyzer type="index"&gt; &lt;tokenizer class="solr.KeywordTokenizerFactory"/&gt; &lt;filter class="solr.LowerCaseFilterFactory"/&gt; &lt;filter class="solr.NGramFilterFactory" minGramSize="3" maxGramSize="15" /&gt; &lt;/analyzer&gt; &lt;analyzer type="query"&gt; &lt;tokenizer class="solr.KeywordTokenizerFactory"/&gt; &lt;filter class="solr.LowerCaseFilterFactory"/&gt; &lt;/analyzer&gt; &lt;/fieldType&gt; &lt;fieldType name="edge_ngram" class="solr.TextField" positionIncrementGap="1"&gt; &lt;analyzer type="index"&gt; &lt;tokenizer class="solr.WhitespaceTokenizerFactory" /&gt; &lt;filter class="solr.LowerCaseFilterFactory" /&gt; &lt;filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/&gt; &lt;filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="15" side="front" /&gt; &lt;/analyzer&gt; &lt;analyzer type="query"&gt; &lt;tokenizer class="solr.WhitespaceTokenizerFactory" /&gt; &lt;filter class="solr.LowerCaseFilterFactory" /&gt; &lt;filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/&gt; &lt;/analyzer&gt; &lt;/fieldType&gt; &lt;/types&gt; &lt;fields&gt; &lt;!-- general --&gt; &lt;field name="id" type="string" indexed="true" stored="true" multiValued="false" required="true"/&gt; &lt;field name="django_ct" type="string" indexed="true" stored="true" multiValued="false"/&gt; &lt;field name="django_id" type="string" indexed="true" stored="true" multiValued="false"/&gt; &lt;dynamicField name="*_i" type="int" indexed="true" stored="true"/&gt; &lt;dynamicField name="*_s" type="string" indexed="true" stored="true"/&gt; &lt;dynamicField name="*_l" type="long" indexed="true" stored="true"/&gt; &lt;dynamicField name="*_t" type="text_en" indexed="true" stored="true"/&gt; &lt;dynamicField name="*_b" type="boolean" indexed="true" stored="true"/&gt; &lt;dynamicField name="*_f" type="float" indexed="true" stored="true"/&gt; &lt;dynamicField name="*_d" type="double" indexed="true" stored="true"/&gt; &lt;dynamicField name="*_dt" type="date" indexed="true" stored="true"/&gt; &lt;dynamicField name="*_p" type="location" indexed="true" stored="true"/&gt; &lt;dynamicField name="*_coordinate" type="tdouble" indexed="true" stored="false"/&gt; &lt;field name="_version_" type="long" indexed="true" stored="true" multiValued="false"/&gt; &lt;/fields&gt; &lt;!-- field to use to determine and enforce document uniqueness. --&gt; &lt;uniqueKey&gt;id&lt;/uniqueKey&gt; &lt;!-- field for the QueryParser to use when an explicit fieldname is absent --&gt; &lt;defaultSearchField&gt;text&lt;/defaultSearchField&gt; &lt;!-- SolrQueryParser configuration: defaultOperator="AND|OR" --&gt; &lt;solrQueryParser defaultOperator="AND"/&gt; &lt;/schema&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload