[ 
https://issues.apache.org/jira/browse/LUCENE-6180?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14275840#comment-14275840
 ] 

David Smiley commented on LUCENE-6180:
--------------------------------------

In trunk, see NumberRangePrefixTreeFacets (in spatial module).  I'm using Bits 
acceptDocs as a way for the caller to articulate which docs should be counted.  
The first method, compute, is the one doing this since this method does it at 
the index level.  The second method is named the same but works at the segment 
level and doesn't need it.  It's called by the first.

p.s. this class will be refactored/renamed to PrefixTreeFacetCounter soon.

I'll put the relevant code here:
{code:java}
//We collect per-leaf
    final List<LeafReaderContext> leaves = context.leaves();
    for (final LeafReaderContext leafCtx : leaves) {
      //determine leaf acceptDocs
      Bits leafAcceptDocs;
      if (acceptDocs == null) {
        leafAcceptDocs = leafCtx.reader().getLiveDocs();
      } else if (leaves.size() == 1) {
        leafAcceptDocs = acceptDocs;
      } else {
        leafAcceptDocs = new Bits() {//note: it'd be nice if Lucene's BitsSlice 
was public.

          final int docBase = leafCtx.docBase;

          @Override
          public boolean get(int index) {
            return acceptDocs.get(docBase + index);
          }

          @Override
          public int length() {
            return leafCtx.reader().maxDoc();
          }
        };
      }

      facets = compute(strategy, leafCtx, leafAcceptDocs, queryShape, facets);
    }
{code}

> Make BitsSlice public (not package-private)
> -------------------------------------------
>
>                 Key: LUCENE-6180
>                 URL: https://issues.apache.org/jira/browse/LUCENE-6180
>             Project: Lucene - Core
>          Issue Type: Improvement
>            Reporter: David Smiley
>            Priority: Minor
>
> org.apache.lucene.index.BitsSlice is a simple and generic utility class. I've 
> found a need to use and it'd be nice if it were public but it's currently 
> package-private.  It should go to the util package, and the constructor 
> taking ReaderSlice cold be removed.
> In Java 8, it'd be neat to have a Bits.subSlice default method simply 
> calling-out to this but no big deal.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to