lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject [26/54] [abbrv] lucene-solr:jira/solr-11702: WIP
Date Wed, 27 Dec 2017 15:04:19 GMT
WIP


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/48c8947c
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/48c8947c
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/48c8947c

Branch: refs/heads/jira/solr-11702
Commit: 48c8947c1775c7695fdd689049fc0ef0e487ebc7
Parents: 33a64af
Author: Alan Woodward <romseygeek@apache.org>
Authored: Mon Dec 18 18:33:01 2017 +0000
Committer: Alan Woodward <romseygeek@apache.org>
Committed: Mon Dec 18 18:33:01 2017 +0000

----------------------------------------------------------------------
 .../java/org/apache/lucene/search/Query.java    |  4 +--
 .../apache/lucene/search/RewriteContext.java    | 32 ++++++++++++++++++++
 .../org/apache/lucene/search/TermQuery.java     | 29 +++++++-----------
 3 files changed, 44 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/48c8947c/lucene/core/src/java/org/apache/lucene/search/Query.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/Query.java b/lucene/core/src/java/org/apache/lucene/search/Query.java
index 54de63f..7a3fc0d 100644
--- a/lucene/core/src/java/org/apache/lucene/search/Query.java
+++ b/lucene/core/src/java/org/apache/lucene/search/Query.java
@@ -70,9 +70,7 @@ public abstract class Query {
    * a PrefixQuery will be rewritten into a BooleanQuery that consists
    * of TermQuerys.
    */
-  public Query rewrite(IndexReader reader) throws IOException {
-    return this;
-  }
+  public abstract Query rewrite(IndexReader reader, RewriteContext rewriteContext) throws
IOException;
 
   /**
    * Override and implement query instance equivalence properly in a subclass. 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/48c8947c/lucene/core/src/java/org/apache/lucene/search/RewriteContext.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/RewriteContext.java b/lucene/core/src/java/org/apache/lucene/search/RewriteContext.java
new file mode 100644
index 0000000..8738399
--- /dev/null
+++ b/lucene/core/src/java/org/apache/lucene/search/RewriteContext.java
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.index.TermContext;
+
+public class RewriteContext {
+
+  public TermContext buildTermContext(Term term, IndexReader reader) throws IOException {
+    return TermContext.build(reader.getContext(), term);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/48c8947c/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/TermQuery.java b/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
index 925fe93..b13a9f4 100644
--- a/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
@@ -22,6 +22,7 @@ import java.util.Objects;
 import java.util.Set;
 
 import org.apache.lucene.index.IndexOptions;
+import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexReaderContext;
 import org.apache.lucene.index.LeafReader;
 import org.apache.lucene.index.LeafReaderContext;
@@ -203,25 +204,17 @@ public class TermQuery extends Query {
 
   @Override
   public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws
IOException {
-    final IndexReaderContext context = searcher.getTopReaderContext();
-    final TermContext termState;
-    if (perReaderTermState == null
-        || perReaderTermState.wasBuiltFor(context) == false) {
-      if (scoreMode.needsScores()) {
-        // make TermQuery single-pass if we don't have a PRTS or if the context
-        // differs!
-        termState = TermContext.build(context, term);
-      } else {
-        // do not compute the term state, this will help save seeks in the terms
-        // dict on segments that have a cache entry for this query
-        termState = null;
-      }
-    } else {
-      // PRTS was pre-build for this IS
-      termState = this.perReaderTermState;
-    }
+    if (perReaderTermState == null)
+      throw new IllegalStateException("TermQuery must be rewritten before use");
+    if (perReaderTermState.wasBuiltFor(searcher.getTopReaderContext()) == false)
+      throw new IllegalStateException("TermQuery was built against a different IndexReader");
+    return new TermWeight(searcher, scoreMode.needsScores(), boost, perReaderTermState);
+  }
 
-    return new TermWeight(searcher, scoreMode.needsScores(), boost, termState);
+  @Override
+  public Query rewrite(IndexReader reader, RewriteContext rewriteContext) throws IOException
{
+    TermContext tc = rewriteContext.buildTermContext(term, reader);
+    return new TermQuery(term, tc);
   }
 
   /** Prints a user-readable version of this query. */


Mime
View raw message