How to implement sorting in Lucene?
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Fanny_Yeung
Posted On:   Monday, May 6, 2002 08:10 PM

Hi All,


I was wondering is it possible to get the search results sorted by a particular field value in Lucene? (similar to the sql statement "order by")


I am trying to get the results sorted by a date field in descending order where the date is one of the field in the index.


Is it support in Lucene? Do I need to implement by myself? Can anyone give me some hints/guidelines where to start from?


Thanks in advance.


Fanny

IndexOrderSearcher: sort data before indexing and use 1/docID instead of score as sort field

Posted By:   Anonymous  
Posted On:   Wednesday, May 8, 2002 03:50 AM




--------------------------------------------------------------------------------

From: Che Dong
Subject: IndexOrderSearcher: sort data before indexing and use 1/docID instead of score as sort field
Date: Tue, 05 Mar 2002 01:52:29 -0800

--------------------------------------------------------------------------------
Hi all:
I think many lucene user want sort lucene results on some certain field. but
just like Doug said: The problem is that a call to getField() makes searches
an order of magnitude slower.


for example: many lucene apps base on database, just sort data by date, rank
... even some complex: rank * price....
and dump into lucene index with sorted order.

when searching, with same lucene index, you can choose return search results
with two sort method:
use IndexSearcher: return results with default sort method by score
use IndexOrderSearcher: return results with doc added sequence.

I tested with (float) doc and (float) 1/doc and find 1/doc more similar to
range of score.


Che Dong


beside class name, the only difference between IndexOrderSearcher.java and
IndexSearch.java is IndexOrderSearcher use
(float) 1/docID as score field while just use score filter results with
minScore in search() method.
diff IndexOrderSearcher.java IndexSearch.java
66,67c66,67
< /** Implements search over a single IndexReader. and sort by document id*/
< public final class IndexOrderSearcher extends Searcher {
---
> /** Implements search over a single IndexReader. */
> public final class IndexSearcher extends Searcher {
71c71
< public IndexOrderSearcher(String path) throws IOException {
---
> public IndexSearcher(String path) throws IOException {
76c76
< public IndexOrderSearcher(Directory directory) throws IOException {
---
> public IndexSearcher(Directory directory) throws IOException {
81c81
< public IndexOrderSearcher(IndexReader r) {
---
> public IndexSearcher(IndexReader r) {
119,120c119
< //use 1/doc instead of score as sort field
< hq.put(new ScoreDoc(doc, (float) 1/doc)); // update
hit queue
---
> hq.put(new ScoreDoc(doc, score)); // update hit queue
159,160c158
< //use 1/doc instead of score as sort field
< results.collect(doc, (float) 1/doc);
---
> results.collect(doc, score);


Re: How to implement sorting in Lucene?

Posted By:   Anonymous  
Posted On:   Wednesday, May 8, 2002 03:44 AM

http://216.239.35.100/search?sourceid=navclient-menuext&q=cache:http%3A//www.mail-archive.com/lucene-user@jakarta.apache.org/msg00825.html

Re: How to implement sorting in Lucene?

Posted By:   Otis_Gospodnetic  
Posted On:   Tuesday, May 7, 2002 06:06 PM

Lucene does allow sorting by date.
Unfortunately I can't think of the name of the class, but I imagine that you can figure it out by checking the Javadocs.
About | Sitemap | Contact