Github user mikemccand commented on a diff in the pull request:

    https://github.com/apache/lucene-solr/pull/526#discussion_r241372770
  
    --- Diff: 
lucene/core/src/java/org/apache/lucene/index/FrozenBufferedUpdates.java ---
    @@ -821,4 +759,93 @@ public String toString() {
       boolean any() {
         return deleteTerms.size() > 0 || deleteQueries.length > 0 || 
fieldUpdatesCount > 0 ;
       }
    +
    +  /**
    +   * This class helps iterating a term dictionary and consuming all the 
docs for each terms.
    +   * It accepts a field, value tuple and returns a {@link 
DocIdSetIterator} if the field has an entry
    +   * for the given value. It has an optimized way of iterating the term 
dictionary if the terms are
    +   * passed in sorted order and makes sure terms and postings are reused 
as much as possible.
    +   */
    +  static final class TermDocsIterator {
    +    private final TermsProvider provider;
    +    private String field;
    +    private TermsEnum termsEnum;
    +    private PostingsEnum postingsEnum;
    +    private final boolean sortedTerms;
    +    private BytesRef readerTerm;
    +
    +    @FunctionalInterface
    +    interface TermsProvider {
    +      Terms terms(String field) throws IOException;
    +    }
    +
    +    TermDocsIterator(Fields fields, boolean sortedTerms) {
    +      this(fields::terms, sortedTerms);
    +    }
    +
    +    TermDocsIterator(LeafReader reader, boolean sortedTerms) {
    +      this(reader::terms, sortedTerms);
    +    }
    +
    +    private TermDocsIterator(TermsProvider provider, boolean sortedTerms) {
    +      this.sortedTerms = sortedTerms;
    +      this.provider = provider;
    +    }
    +
    +    private void nextField(String field) throws IOException {
    +      if (this.field == null || this.field.equals(field) == false) {
    +        this.field = field;
    +        Terms terms = provider.terms(field);
    +        if (terms != null) {
    +          termsEnum = terms.iterator();
    +          if (sortedTerms) {
    +            readerTerm = termsEnum.next();
    +          }
    +        } else {
    +          termsEnum = null;
    +        }
    +      }
    +    }
    +
    +    DocIdSetIterator nextTerm(String field, BytesRef term) throws 
IOException {
    +      nextField(field);
    +      if (termsEnum != null) {
    +        if (sortedTerms) {
    +          // in the sorted case we can take advantage of the "seeking 
forward" property
    +          // this allows us depending on the term dict impl to reuse 
data-strucutres internally
    --- End diff --
    
    `data-strucutres` -> `data-structures`


---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org

Reply via email to