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 suren <gu...@yahoo.com> on 2013/09/14 02:56:26 UTC

sorting using org.apache.solr.client.solrj.SolrQuery not working

I tried below 3 methods to sort the output from solr 4.3.1., no error and not
sorting on any given field.
1)addSort(field, order)
2)addOrUpdateSort(field, order)
3)setSort(field, order)

my schema setting for the fields i tried are
<field name="CLAI_CLM_NUM" type="string" indexed="true" stored="false" 
multiValued="false"/>
<field name="FIRST_NAM" type="string" indexed="true" stored="false" 
multiValued="false"/>
<field name="LAST_NAM" type="string" indexed="true" stored="false" 
multiValued="false"/>

Any one please tell me why the sorting is not working?



--
View this message in context: http://lucene.472066.n3.nabble.com/sorting-using-org-apache-solr-client-solrj-SolrQuery-not-working-tp4089985.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: sorting using org.apache.solr.client.solrj.SolrQuery not working

Posted by Chris Hostetter <ho...@fucit.org>.
: In the log i see the sorting column as "LAST_NAM". 
: Is there a difference between "LAST_NAM asc" and "LAST_NAM+asc"...I see only
: this diff?

the log message you are looking at is showing you the request params 
recieved by the handler fro mthe client, with URL escaping -- so the "+" 
you see is the url escaing of the " " sent by the client.

can you show us the <requestHandler /> declaration for the handler name 
you are using? 

If you are seeing theresults sorted by a differnet field then the one you 
specified in the client, then it has to be specified somehwere -- I'm 
guessing since it's not explicit in that log message that it's "/select" 
but it could also be whatever you have configured asthe default="true".

my best guess is that the requestHandler has some init params that set the 
sot option as an invariant so that you can't override it.

: "params={sort=LAST_NAM+asc&start=0&q=*:*&wt=javabin&fq=(LAST_NAM:*D*)+AND++-CLAI_RISK_MNGT_FLG+:+Y+&version=2&rows=30}
: hits=196 status=0 QTime=2 "

one other thing to sanity check: try loading your requestHandler, with all 
ofthose params (except for "wt=javabin") in a browser window, and double 
check which order the results come back -- just to verify that the results 
really are getting sorted incorrectly on the solr side and that the 
problem isn't some other bit of javacode you have re-sorting the results 
that get returned.

if you load the URL in your browser, yo ucan also add echoParams=all to 
see every param used in the request, even if it is an invariant specified 
in the requestHandler config.


-Hoss

Re: sorting using org.apache.solr.client.solrj.SolrQuery not working

Posted by suren <gu...@yahoo.com>.
Shawn,
          I am doing exactly same. Data output is not sorting on "LAST_NAME"
column , but it is always sorting on different column "CLAIM_NUM", and I am
not adding this sorting condition( sort on CLAIM_NUM).

solrQuery.setQuery("*:*");
solrQuery.setSort("LAST_NAM",SolrQuery.ORDER.asc);
solrQuery.setFilterQueries("String Query");
In the log i see the sorting column as "LAST_NAM". 
Is there a difference between "LAST_NAM asc" and "LAST_NAM+asc"...I see only
this diff?

"params={sort=LAST_NAM+asc&start=0&q=*:*&wt=javabin&fq=(LAST_NAM:*D*)+AND++-CLAI_RISK_MNGT_FLG+:+Y+&version=2&rows=30}
hits=196 status=0 QTime=2 "


<field name="CLAI_IDN" type="int" indexed="true" stored="true"
multiValued="false"/>
<field name="CLAI_CLM_NUM" type="string" indexed="true" stored="false" 
multiValued="false"/>
<field name="FIRST_NAM" type="string" indexed="true" stored="false" 
multiValued="false"/>
<field name="MIDDLE_NAM" type="string" indexed="true" stored="false" />
<field name="LAST_NAM" type="string" indexed="true" stored="false" 
multiValued="false"/>


 <uniqueKey>CLAI_IDN</uniqueKey>

I also tried addOrUpdateSort and  addSort, But it is always sorting on
CLAI_CLM_NUM, not sure why?





--
View this message in context: http://lucene.472066.n3.nabble.com/sorting-using-org-apache-solr-client-solrj-SolrQuery-not-working-tp4089985p4090364.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: sorting using org.apache.solr.client.solrj.SolrQuery not working

Posted by Shawn Heisey <so...@elyograg.org>.
On 9/13/2013 6:56 PM, suren wrote:
> I tried below 3 methods to sort the output from solr 4.3.1., no error and not
> sorting on any given field.
> 1)addSort(field, order)
> 2)addOrUpdateSort(field, order)
> 3)setSort(field, order)
> 
> my schema setting for the fields i tried are
> <field name="CLAI_CLM_NUM" type="string" indexed="true" stored="false" 
> multiValued="false"/>
> <field name="FIRST_NAM" type="string" indexed="true" stored="false" 
> multiValued="false"/>
> <field name="LAST_NAM" type="string" indexed="true" stored="false" 
> multiValued="false"/>
> 
> Any one please tell me why the sorting is not working?

Here's an example of how to do a sort with SolrJ, assuming query is a
SolrQuery object:

query.setSort("LAST_NAM", ORDER.asc);

You'll need this import:

import org.apache.solr.client.solrj.SolrQuery.ORDER;

For the example I've just given, you should see "sort=LAST_NAM asc" in
your solr log in the parameter list for that query.

If that doesn't seem to work, what are you actually seeing?

Thanks,
Shawn