lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zach Bailey <zach.bai...@hannonhill.com>
Subject Re: Sorting a search result
Date Tue, 18 Sep 2007 16:29:48 GMT
Sure. You'll have to do away with the List abstraction in favor of the 
SortedSet abstraction which in your case is probably ok for the 
following reasons:

1.) List does not ensure the elements are unique (you probably don't 
want to have duplicate results), while Set and by extension SortedSet do
2.) List implies an ordered set however does not do the sorting 
automatically for you, while SortedSet handles this automatically.

There are two ways of telling TreeSet about how you want to compare your 
elements:

1.) Construct your SortedSet implementation with a comparator:

SortedSet<ResultBean> results = new TreeSet<ResultBean>(new 
ResultBeanComparator());

2.) Have your ResultBean implement Comparable<ResultBean>

In this case I find #2 a little better from a code maintenance 
standpoint but functionally they are equivalent.

Cheers,
-Zach

anorman wrote:
> Hmmmm.
> 
> Right now my search results are contained in an ArrayList object like so:
> 
> List searchResult = new ArrayList();
> 
> I am adding my "resultBean" objects (with it's data, i.e. title, author,
> score, etc) into the searchResult (ArrayList).  
> 
> Would this be possible with a SortedSet?
> 
> Thanks,
> Albert
> 
> 
> 
> 
> 
> Zach Bailey wrote:
>> You could use a SortedSet, which automatically inserts an object into 
>> its sorted position when calling add()?
>>
>> Cheers,
>> -Zach
>>
>> anorman wrote:
>>> I have set up a search result made up of a resultBean object containing
>>> the
>>> information that I am fetching.  Currently it is sorted by score
>>> (relevance)
>>> which is great and what I want.  However, I have created a loop which
>>> continues to add results from several indexes to the search result (e.g.
>>> articles, books, chapters).  This works fine, but each specific section
>>> is
>>> sorted by score so that the articles are listed first (lets say 200 of
>>> them
>>> return) then the books are listed and sorted based on relevance and so
>>> on.  
>>>
>>> I need some way to again sort by score on my compiled search result.
>>>
>>> Any thoughts?
>>>
>>> Thanks,
>>> Albert
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>
>>
>>
> 

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


Mime
View raw message