You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by mahaveer jain <ja...@yahoo.com> on 2005/01/03 10:55:02 UTC

Help for sorting

Hello All, 

I am looking out to implement sorting in my lucene application. This is what my code look like. 

I am using StandardAnalyzer() analyzer. 

Query query = QueryParser.parse(keyword, "contents", analyzer); 

Sort sortCol = new Sort(new SortField("date"));

// date is one of the field I have indexed.

Hits hits = searcher.search(query, sortCol);

for (int start = 0; start < hits.length(); start ++) { 
Document doc = hits.doc(start); 

// get all the data required.
} 

I get this error : 

no terms in field sdate - cannot determine sort type 

Can any let me know where I am wrong ? Also what is the default sorting in lucene ? 

Also can some one explain what exactly is the score ? Is it something to do with ranking ? Do somebody have a link to a good lucene tutorial ? 

Thanks 

Mahaveer


		
---------------------------------
Do you Yahoo!?
 Dress up your holiday email, Hollywood style. Learn more.

Re: Help for sorting

Posted by Otis Gospodnetic <ot...@yahoo.com>.
Hello,

--- mahaveer jain <ja...@yahoo.com> wrote:

> I am looking out to implement sorting in my lucene application. This
> is what my code look like. 
> 
> I am using StandardAnalyzer() analyzer. 
> 
> Query query = QueryParser.parse(keyword, "contents", analyzer); 
> 
> Sort sortCol = new Sort(new SortField("date"));
> 
> // date is one of the field I have indexed.
> 
> Hits hits = searcher.search(query, sortCol);
> 
> for (int start = 0; start < hits.length(); start ++) { 
> Document doc = hits.doc(start); 
> 
> // get all the data required.
> } 
> 
> I get this error : 
> 
> no terms in field sdate - cannot determine sort type 

Is it possible that your 'date' field is empty in some documents you
indexed?  If so, you should specify your sort field type explicitly. 
Look at the Javadoc for SortField class.

> Can any let me know where I am wrong ? Also what is the default
> sorting in lucene ? 

Default sorting is by rank/score.

> Also can some one explain what exactly is the score ? Is it something
> to do with ranking ? Do somebody have a link to a good lucene
> tutorial ? 

There are links to a few Lucene articles on Lucene's Wiki.  There is
also a link to the Lucene book (Lucene in Action) on the same page. 
Another good source of information about how to use the Lucene API are
Lucene's unit tests.

Otis


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org