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 Kevin Osborn <os...@yahoo.com> on 2008/05/15 20:41:20 UTC

DocSet to BitSet

I have a custom query object that extends ContstantScoreQuery. I give it a key which pulls some documents out of a cache. Thinking to make it more efficient, I used DocSet, backed by OpenBitSet or OpenHashSet. However, I need to set the BitSet object for the Lucene filter. Any idea on how to best do this from DocSet? It seems like this is a problem that people have encountered before.

I could iterate through each item in the DocSet and do that, but that seems rather inefficient.

public class MyQuery extends ConstantScoreQuery {   
    private static class ResellerSupplierFilter extends Filter {
        private final BitSet bitset;
        
        public MyFilter(String reseller, String supplier) {           
            DocSet docset = (DocSet)context.get().searcher.getCache("my-filter").get(new CompositeKey(reseller, supplier));
        }

        public @Override BitSet bits(IndexReader reader) {
            //return docset.getBits().
        }

        public @Override int hashCode() {
            return new HashCodeBuilder().append(reseller).append(supplier).toHashCode();
        }
    }
    
    public ResellerSupplierQuery(String reseller, String supplier) {
        super(new ResellerSupplierFilter(reseller, supplier));
    }
}

Re: DocSet to BitSet

Posted by Chris Hostetter <ho...@fucit.org>.
: I have a custom query object that extends ContstantScoreQuery. I give it 
: a key which pulls some documents out of a cache. Thinking to make it 
: more efficient, I used DocSet, backed by OpenBitSet or OpenHashSet. 
: However, I need to set the BitSet object for the Lucene filter. Any idea 
: on how to best do this from DocSet? It seems like this is a problem that 
: people have encountered before.

I've never really encountered this particular problem ... typically any 
"sets" i'm dealing with can be passed as "filters" directly to the 
SolrIndexSearcher method -- so I use DocSets.

if I *had* to use a ConstantScoreQuery, i'd probably skip DocSet initially 
and use a BitSet from the get go (the BitSets could still be cashed using  
custom cache).  but you could also just create anew custom constnat 
scoring Query class that used a Scorer that refrenced your DocSet 
directly. 

if you look at the source of ConstantScoreQuery it should be fairly 
obvious how to make something similar backed by a DocSet instead of a 
Filter.

(in future versions of Lucene this will all be moot, as the Filter API 
will no longer require a BitSet and can intead return a "DocIdSet" which 
is essentially just an iterator that Solr's DocSet can implement 
trivially. ... if you look at the trunk version of ConstantScoreQuery it 
already does this ... that class may serve as an even better example of 
implementing a Query that scores based on an o.a.s.search.DocIterator)


-Hoss