lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Haruska <jharu...@gmail.com>
Subject Re: custom sort
Date Wed, 31 Aug 2005 21:12:45 GMT
I had to do something similar, but I plan on re-writing it into something 
more elegant. I hope this helps give you some ideas.

1. Create a QueryFilter on only those items that matched the criteria (have 
a required clause in your boolean query)
2. Create a BitFilter which takes a BitSet from step 1 and flip the bits
3. Perform a search with each Filter and display results for each search

Here is my BitFilter code:
--------------------------------------------------
package org.apache.lucene.search;

import java.io.IOException;
import java.util.BitSet;

import org.apache.lucene.index.IndexReader;

public class BitFilter extends Filter {
private BitSet bitSet;

public BitFilter(BitSet bs) {
bitSet = bs;
}

public void flipAll() {
bitSet.flip(0, bitSet.size()-1);
}

/* (non-Javadoc)
* @see org.apache.lucene.search.Filter#bits(
org.apache.lucene.index.IndexReader)
*/
public BitSet bits(IndexReader reader) throws IOException {
return bitSet;
}
}
--------------------------------------------------------------------------------

On 8/31/05, raymondcreel (sent by Nabble.com <http://Nabble.com>) <
lists@nabble.com> wrote:
> 
> 
> Actually in this case I am sorting by score already but I'm not sure if 
> that helps. Regardless of how I do my primary sort, I want to tweak the 
> results such that some hardcoded number of documents that match some 
> criteria get pushed or frontloaded to the top of the results. For instance 
> think of a search engine where you generally are displaying a list of pages 
> sorted by score, but you want 10 pages from a featured site to always show 
> at the top of the first page, while leaving the rest of the sort order as it 
> is. That's why it's not something I can really do at the index stage by 
> assigning boosts - I only want to boost those first 10 items that match the 
> criteria, not all of them.
> 
> What I'm doing now is taking the whole resulting document collection, 
> iterating through it and manually moving these 10 documents to the front of 
> the collection. This is slow and ugly. I was hoping there might be a slicker 
> way to do it as part of the actual sort. I will play around with the custom 
> sorting and report back if I figure out an elegant way to do it.
> 
> Thanks for all your replies.
> Raymond
> --
> Sent from the Lucene - Java Users forum at Nabble.com <http://Nabble.com>:
> http://www.nabble.com/custom-sort-t262833.html#a750675
> 
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message