/** Add the {@link #top()} slice as well as all slices that are positionned * on the same term to {@code tops} and return how many of them there are. */ int fillTop(TermsEnumWithSlice[] tops) { final int size = size(); if (size == 0) { return 0; } tops[0] = top(); int numTop = 1; stack[0] = 1; int stackLen = 1; while (stackLen != 0) { final int index = stack[--stackLen]; final int leftChild = index << 1; for (int child = leftChild, end = Math.min(size, leftChild + 1); child <= end; ++child) { TermsEnumWithSlice te = get(child); if (te.current.equals(tops[0].current)) { tops[numTop++] = te; stack[stackLen++] = child; } } } return numTop; }
@Override public SeekStatus seekCeil(BytesRef term) throws IOException { queue.clear(); numTop = 0; lastSeekExact = false; top[numTop++] = currentSubs[i]; current = currentSubs[i].current = currentSubs[i].terms.term(); queue.add(currentSubs[i]); } else { if (status == SeekStatus.NOT_FOUND) { currentSubs[i].current = currentSubs[i].terms.term(); assert currentSubs[i].current != null; queue.add(currentSubs[i]); } else { assert status == SeekStatus.END; } else if (queue.size() > 0) {
@Override public SeekStatus seekCeil(BytesRef term) throws IOException { queue.clear(); numTop = 0; lastSeekExact = false; top[numTop++] = currentSubs[i]; current = currentSubs[i].current = currentSubs[i].terms.term(); queue.add(currentSubs[i]); } else { if (status == SeekStatus.NOT_FOUND) { currentSubs[i].current = currentSubs[i].terms.term(); assert currentSubs[i].current != null; queue.add(currentSubs[i]); } else { assert status == SeekStatus.END; } else if (queue.size() > 0) {
@Override public SeekStatus seekCeil(BytesRef term) throws IOException { queue.clear(); numTop = 0; lastSeekExact = false; top[numTop++] = currentSubs[i]; current = currentSubs[i].current = currentSubs[i].terms.term(); queue.add(currentSubs[i]); } else { if (status == SeekStatus.NOT_FOUND) { currentSubs[i].current = currentSubs[i].terms.term(); assert currentSubs[i].current != null; queue.add(currentSubs[i]); } else { assert status == SeekStatus.END; } else if (queue.size() > 0) {
@Override public boolean seekExact(BytesRef term) throws IOException { queue.clear(); numTop = 0;
@Override public boolean seekExact(BytesRef term) throws IOException { queue.clear(); numTop = 0;
@Override public boolean seekExact(BytesRef term) throws IOException { queue.clear(); numTop = 0;
@Override public BytesRef next() throws IOException { if (lastSeekExact) { // Must seekCeil at this point, so those subs that // didn't have the term can find the following term. // NOTE: we could save some CPU by only seekCeil the // subs that didn't match the last exact seek... but // most impls short-circuit if you seekCeil to term // they are already on. final SeekStatus status = seekCeil(current); assert status == SeekStatus.FOUND; lastSeekExact = false; } lastSeek = null; // restore queue pushTop(); // gather equal top fields if (queue.size() > 0) { pullTop(); } else { current = null; } return current; }
/** The terms array must be newly created TermsEnum, ie * {@link TermsEnum#next} has not yet been called. */ public TermsEnum reset(TermsEnumIndex[] termsEnumsIndex) throws IOException { assert termsEnumsIndex.length <= top.length; numSubs = 0; numTop = 0; queue.clear(); for(int i=0;i<termsEnumsIndex.length;i++) { final TermsEnumIndex termsEnumIndex = termsEnumsIndex[i]; assert termsEnumIndex != null; final BytesRef term = termsEnumIndex.termsEnum.next(); if (term != null) { final TermsEnumWithSlice entry = subs[termsEnumIndex.subIndex]; entry.reset(termsEnumIndex.termsEnum, term); queue.add(entry); currentSubs[numSubs++] = entry; } else { // field has no terms } } if (queue.size() == 0) { return TermsEnum.EMPTY; } else { return this; } }
@Override public BytesRef next() throws IOException { if (lastSeekExact) { // Must seekCeil at this point, so those subs that // didn't have the term can find the following term. // NOTE: we could save some CPU by only seekCeil the // subs that didn't match the last exact seek... but // most impls short-circuit if you seekCeil to term // they are already on. final SeekStatus status = seekCeil(current); assert status == SeekStatus.FOUND; lastSeekExact = false; } lastSeek = null; // restore queue pushTop(); // gather equal top fields if (queue.size() > 0) { // TODO: we could maybe defer this somewhat costly operation until one of the APIs that // needs to see the top is invoked (docFreq, postings, etc.) pullTop(); } else { current = null; } return current; }
/** Add the {@link #top()} slice as well as all slices that are positionned * on the same term to {@code tops} and return how many of them there are. */ int fillTop(TermsEnumWithSlice[] tops) { final int size = size(); if (size == 0) { return 0; } tops[0] = top(); int numTop = 1; stack[0] = 1; int stackLen = 1; while (stackLen != 0) { final int index = stack[--stackLen]; final int leftChild = index << 1; for (int child = leftChild, end = Math.min(size, leftChild + 1); child <= end; ++child) { TermsEnumWithSlice te = get(child); if (te.current.equals(tops[0].current)) { tops[numTop++] = te; stack[stackLen++] = child; } } } return numTop; }
/** Add the {@link #top()} slice as well as all slices that are positionned * on the same term to {@code tops} and return how many of them there are. */ int fillTop(TermsEnumWithSlice[] tops) { final int size = size(); if (size == 0) { return 0; } tops[0] = top(); int numTop = 1; stack[0] = 1; int stackLen = 1; while (stackLen != 0) { final int index = stack[--stackLen]; final int leftChild = index << 1; for (int child = leftChild, end = Math.min(size, leftChild + 1); child <= end; ++child) { TermsEnumWithSlice te = get(child); if (te.current.equals(tops[0].current)) { tops[numTop++] = te; stack[stackLen++] = child; } } } return numTop; }
/** The terms array must be newly created TermsEnum, ie * {@link TermsEnum#next} has not yet been called. */ public TermsEnum reset(TermsEnumIndex[] termsEnumsIndex) throws IOException { assert termsEnumsIndex.length <= top.length; numSubs = 0; numTop = 0; queue.clear(); for(int i=0;i<termsEnumsIndex.length;i++) { final TermsEnumIndex termsEnumIndex = termsEnumsIndex[i]; assert termsEnumIndex != null; final BytesRef term = termsEnumIndex.termsEnum.next(); if (term != null) { final TermsEnumWithSlice entry = subs[termsEnumIndex.subIndex]; entry.reset(termsEnumIndex.termsEnum, term); queue.add(entry); currentSubs[numSubs++] = entry; } else { // field has no terms } } if (queue.size() == 0) { return TermsEnum.EMPTY; } else { return this; } }
/** The terms array must be newly created TermsEnum, ie * {@link TermsEnum#next} has not yet been called. */ public TermsEnum reset(TermsEnumIndex[] termsEnumsIndex) throws IOException { assert termsEnumsIndex.length <= top.length; numSubs = 0; numTop = 0; queue.clear(); for(int i=0;i<termsEnumsIndex.length;i++) { final TermsEnumIndex termsEnumIndex = termsEnumsIndex[i]; assert termsEnumIndex != null; final BytesRef term = termsEnumIndex.termsEnum.next(); if (term != null) { final TermsEnumWithSlice entry = subs[termsEnumIndex.subIndex]; entry.reset(termsEnumIndex.termsEnum, term); queue.add(entry); currentSubs[numSubs++] = entry; } else { // field has no terms } } if (queue.size() == 0) { return TermsEnum.EMPTY; } else { return this; } }
/** Add the {@link #top()} slice as well as all slices that are positionned * on the same term to {@code tops} and return how many of them there are. */ int fillTop(TermsEnumWithSlice[] tops) { final int size = size(); if (size == 0) { return 0; } tops[0] = top(); int numTop = 1; stack[0] = 1; int stackLen = 1; while (stackLen != 0) { final int index = stack[--stackLen]; final int leftChild = index << 1; for (int child = leftChild, end = Math.min(size, leftChild + 1); child <= end; ++child) { TermsEnumWithSlice te = get(child); if (te.current.equals(tops[0].current)) { tops[numTop++] = te; stack[stackLen++] = child; } } } return numTop; }
@Override public BytesRef next() throws IOException { if (lastSeekExact) { // Must seekCeil at this point, so those subs that // didn't have the term can find the following term. // NOTE: we could save some CPU by only seekCeil the // subs that didn't match the last exact seek... but // most impls short-circuit if you seekCeil to term // they are already on. final SeekStatus status = seekCeil(current); assert status == SeekStatus.FOUND; lastSeekExact = false; } lastSeek = null; // restore queue pushTop(); // gather equal top fields if (queue.size() > 0) { pullTop(); } else { current = null; } return current; }
/** Sole constructor. * @param slices Which sub-reader slices we should * merge. */ public MultiTermsEnum(ReaderSlice[] slices) { queue = new TermMergeQueue(slices.length); top = new TermsEnumWithSlice[slices.length]; subs = new TermsEnumWithSlice[slices.length]; subDocs = new MultiPostingsEnum.EnumWithSlice[slices.length]; for(int i=0;i<slices.length;i++) { subs[i] = new TermsEnumWithSlice(i, slices[i]); subDocs[i] = new MultiPostingsEnum.EnumWithSlice(); subDocs[i].slice = slices[i]; } currentSubs = new TermsEnumWithSlice[slices.length]; }
/** Sole constructor. * @param slices Which sub-reader slices we should * merge. */ public MultiTermsEnum(ReaderSlice[] slices) { queue = new TermMergeQueue(slices.length); top = new TermsEnumWithSlice[slices.length]; subs = new TermsEnumWithSlice[slices.length]; subDocs = new MultiPostingsEnum.EnumWithSlice[slices.length]; for(int i=0;i<slices.length;i++) { subs[i] = new TermsEnumWithSlice(i, slices[i]); subDocs[i] = new MultiPostingsEnum.EnumWithSlice(); subDocs[i].slice = slices[i]; } currentSubs = new TermsEnumWithSlice[slices.length]; }
/** Sole constructor. * @param slices Which sub-reader slices we should * merge. */ public MultiTermsEnum(ReaderSlice[] slices) { queue = new TermMergeQueue(slices.length); top = new TermsEnumWithSlice[slices.length]; subs = new TermsEnumWithSlice[slices.length]; subDocs = new MultiPostingsEnum.EnumWithSlice[slices.length]; for(int i=0;i<slices.length;i++) { subs[i] = new TermsEnumWithSlice(i, slices[i]); subDocs[i] = new MultiPostingsEnum.EnumWithSlice(); subDocs[i].slice = slices[i]; } currentSubs = new TermsEnumWithSlice[slices.length]; }