You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by MOuli <za...@hotmail.de> on 2011/03/15 15:35:14 UTC

Sorting 0 values last

Hi @everyone.

I want so sort ASC on a price field, but some of the docs got a 0 (not NULL)
value. Now I want that this docs are at the end when i sort the price field
ascending. Is it possible?

Thanks in advance.

MOuli

--
View this message in context: http://lucene.472066.n3.nabble.com/Sorting-0-values-last-tp2681612p2681612.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Sorting 0 values last

Posted by MOuli <za...@hotmail.de>.
Okay.

When I use the map function with ..&sort=map(price, 0, 0, 0, 1) desc then
solr output an error: 
17.03.2011 09:42:58 org.apache.solr.common.SolrException log
SCHWERWIEGEND: org.apache.solr.common.SolrException: Missing sort order.
        at
org.apache.solr.search.QueryParsing.parseSort(QueryParsing.java:254)
        at org.apache.solr.search.QParser.getSort(QParser.java:211)
        at
org.apache.solr.handler.component.QueryComponent.prepare(QueryComponent.java:90)
        at
org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:174)
        at
org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:131)
        at org.apache.solr.core.SolrCore.execute(SolrCore.java:1316)
        at
org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:338)
        at
org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:241)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
        at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
        at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:662)

17.03.2011 09:42:58 org.apache.solr.core.SolrCore execute
INFO: [de] webapp=/solr path=/select
params={sort=map(calc_curr,0,0,1)+desc&qt=nonequery} status=400 QTime=1


fyi: I use solr 1.4.1 

--
View this message in context: http://lucene.472066.n3.nabble.com/Sorting-0-values-last-tp2681612p2692701.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Sorting 0 values last

Posted by Chris Hostetter <ho...@fucit.org>.
: Not sure how you are indexing, but in addition to the above
: suggestion by Yonik, one could ignore 0's at indexing time,
: i.e., ensure that 0 values for that field are not indexed, and
: use sortMissingLast.

Once upon a time i had a usecase where i was indexing product data, and in 
thta product data a null price ment not currently for sale, but "0" was a 
legal price for products that were being given away free.  i had a similar 
requirement that the default sort should be based on price, but "free" 
products should come last ... except if the user explicitly said "sort by 
price".

what i did was to index a "hasPrice" field that was true if the price 
field existed and was non-zero.  my default sort was "hasPrice desc, price 
asc" but if the user clicked "sort by price" it was "price asc"

that might give you ideas about your own usecase.

-Hoss

Re: Sorting 0 values last

Posted by Gora Mohanty <go...@mimirtech.com>.
On Tue, Mar 15, 2011 at 9:04 PM, Yonik Seeley
<yo...@lucidimagination.com> wrote:
> On Tue, Mar 15, 2011 at 10:35 AM, MOuli <za...@hotmail.de> wrote:
>> I want so sort ASC on a price field, but some of the ouldocs got a 0 (not NULL)
>> value. Now I want that this docs are at the end when i sort the price field
>> ascending. Is it possible?
>
> In 3.1 and trunk (4.0-dev), you could sort by a function query that
> maps values of 0 to something very large.
[...]

Not sure how you are indexing, but in addition to the above
suggestion by Yonik, one could ignore 0's at indexing time,
i.e., ensure that 0 values for that field are not indexed, and
use sortMissingLast.

Regards,
Gora

Re: Sorting 0 values last

Posted by Yonik Seeley <yo...@lucidimagination.com>.
On Tue, Mar 15, 2011 at 10:35 AM, MOuli <za...@hotmail.de> wrote:
> I want so sort ASC on a price field, but some of the docs got a 0 (not NULL)
> value. Now I want that this docs are at the end when i sort the price field
> ascending. Is it possible?

In 3.1 and trunk (4.0-dev), you could sort by a function query that
maps values of 0 to something very large.

sort=map(price,0,0,999999) asc

This should map anything with a price between 0 and 0 to 999999 for
the purposes of sorting.

http://wiki.apache.org/solr/FunctionQuery

-Yonik
http://lucidimagination.com