You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2019/04/11 20:29:37 UTC
[lucene-solr] branch branch_8x updated: LUCENE-8725: Make
TermsQuery.SeekingTermSetTermsEnum a top level class and public
This is an automated email from the ASF dual-hosted git repository.
noble pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/branch_8x by this push:
new c2e5e83 LUCENE-8725: Make TermsQuery.SeekingTermSetTermsEnum a top level class and public
c2e5e83 is described below
commit c2e5e83c477d6f93b4248513983b251f2910edab
Author: Noble Paul <no...@apache.org>
AuthorDate: Fri Apr 12 06:22:09 2019 +1000
LUCENE-8725: Make TermsQuery.SeekingTermSetTermsEnum a top level class and public
---
lucene/CHANGES.txt | 2 +
.../search/join/SeekingTermSetTermsEnum.java | 99 ++++++++++++++++++++++
.../org/apache/lucene/search/join/TermsQuery.java | 72 ----------------
3 files changed, 101 insertions(+), 72 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 9ca2e7b..f5552c7 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -125,6 +125,8 @@ Other
* LUCENE-8729: Workaround: Disable accessibility doclints (Java 13+),
so compilation with recent JDK succeeds. (Uwe Schindler)
+* LUCENE-8725: Make TermsQuery.SeekingTermSetTermsEnum a top level class and public (noble)
+
======================= Lucene 8.0.0 =======================
API Changes
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/SeekingTermSetTermsEnum.java b/lucene/join/src/java/org/apache/lucene/search/join/SeekingTermSetTermsEnum.java
new file mode 100644
index 0000000..1f590dc
--- /dev/null
+++ b/lucene/join/src/java/org/apache/lucene/search/join/SeekingTermSetTermsEnum.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.search.join;
+
+import java.io.IOException;
+
+import org.apache.lucene.index.FilteredTermsEnum;
+import org.apache.lucene.index.TermsEnum;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefHash;
+
+/**A filtered TermsEnum that uses a BytesRefHash as a filter
+ *
+ * @lucene.internal
+ */
+public class SeekingTermSetTermsEnum extends FilteredTermsEnum {
+
+ private final BytesRefHash terms;
+ private final int[] ords;
+ private final int lastElement;
+
+ private final BytesRef lastTerm;
+ private final BytesRef spare = new BytesRef();
+
+ private BytesRef seekTerm;
+ private int upto = 0;
+
+ public SeekingTermSetTermsEnum(TermsEnum tenum, BytesRefHash terms, int[] ords) {
+ super(tenum);
+ this.terms = terms;
+ this.ords = ords;
+ lastElement = terms.size() - 1;
+ lastTerm = terms.get(ords[lastElement], new BytesRef());
+ seekTerm = terms.get(ords[upto], spare);
+ }
+
+ @Override
+ protected BytesRef nextSeekTerm(BytesRef currentTerm) throws IOException {
+ BytesRef temp = seekTerm;
+ seekTerm = null;
+ return temp;
+ }
+
+ @Override
+ protected AcceptStatus accept(BytesRef term) throws IOException {
+ if (term.compareTo(lastTerm) > 0) {
+ return AcceptStatus.END;
+ }
+
+ BytesRef currentTerm = terms.get(ords[upto], spare);
+ if (term.compareTo(currentTerm) == 0) {
+ if (upto == lastElement) {
+ return AcceptStatus.YES;
+ } else {
+ seekTerm = terms.get(ords[++upto], spare);
+ return AcceptStatus.YES_AND_SEEK;
+ }
+ } else {
+ if (upto == lastElement) {
+ return AcceptStatus.NO;
+ } else { // Our current term doesn't match the the given term.
+ int cmp;
+ do { // We maybe are behind the given term by more than one step. Keep incrementing till we're the same or higher.
+ if (upto == lastElement) {
+ return AcceptStatus.NO;
+ }
+ // typically the terms dict is a superset of query's terms so it's unusual that we have to skip many of
+ // our terms so we don't do a binary search here
+ seekTerm = terms.get(ords[++upto], spare);
+ } while ((cmp = seekTerm.compareTo(term)) < 0);
+ if (cmp == 0) {
+ if (upto == lastElement) {
+ return AcceptStatus.YES;
+ }
+ seekTerm = terms.get(ords[++upto], spare);
+ return AcceptStatus.YES_AND_SEEK;
+ } else {
+ return AcceptStatus.NO_AND_SEEK;
+ }
+ }
+ }
+ }
+
+}
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/TermsQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/TermsQuery.java
index 53b9c40..0f8b3d7 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/TermsQuery.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/TermsQuery.java
@@ -19,14 +19,12 @@ package org.apache.lucene.search.join;
import java.io.IOException;
import java.util.Objects;
-import org.apache.lucene.index.FilteredTermsEnum;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.search.MultiTermQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryVisitor;
import org.apache.lucene.util.AttributeSource;
-import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefHash;
/**
@@ -104,74 +102,4 @@ class TermsQuery extends MultiTermQuery {
return classHash() + Objects.hash(field, fromField, fromQuery, indexReaderContextId);
}
- static class SeekingTermSetTermsEnum extends FilteredTermsEnum {
-
- private final BytesRefHash terms;
- private final int[] ords;
- private final int lastElement;
-
- private final BytesRef lastTerm;
- private final BytesRef spare = new BytesRef();
-
- private BytesRef seekTerm;
- private int upto = 0;
-
- SeekingTermSetTermsEnum(TermsEnum tenum, BytesRefHash terms, int[] ords) {
- super(tenum);
- this.terms = terms;
- this.ords = ords;
- lastElement = terms.size() - 1;
- lastTerm = terms.get(ords[lastElement], new BytesRef());
- seekTerm = terms.get(ords[upto], spare);
- }
-
- @Override
- protected BytesRef nextSeekTerm(BytesRef currentTerm) throws IOException {
- BytesRef temp = seekTerm;
- seekTerm = null;
- return temp;
- }
-
- @Override
- protected AcceptStatus accept(BytesRef term) throws IOException {
- if (term.compareTo(lastTerm) > 0) {
- return AcceptStatus.END;
- }
-
- BytesRef currentTerm = terms.get(ords[upto], spare);
- if (term.compareTo(currentTerm) == 0) {
- if (upto == lastElement) {
- return AcceptStatus.YES;
- } else {
- seekTerm = terms.get(ords[++upto], spare);
- return AcceptStatus.YES_AND_SEEK;
- }
- } else {
- if (upto == lastElement) {
- return AcceptStatus.NO;
- } else { // Our current term doesn't match the the given term.
- int cmp;
- do { // We maybe are behind the given term by more than one step. Keep incrementing till we're the same or higher.
- if (upto == lastElement) {
- return AcceptStatus.NO;
- }
- // typically the terms dict is a superset of query's terms so it's unusual that we have to skip many of
- // our terms so we don't do a binary search here
- seekTerm = terms.get(ords[++upto], spare);
- } while ((cmp = seekTerm.compareTo(term)) < 0);
- if (cmp == 0) {
- if (upto == lastElement) {
- return AcceptStatus.YES;
- }
- seekTerm = terms.get(ords[++upto], spare);
- return AcceptStatus.YES_AND_SEEK;
- } else {
- return AcceptStatus.NO_AND_SEEK;
- }
- }
- }
- }
-
- }
-
}