Skip to content

Apache Lucene open-source search software

LUCENE-5666: fix test failures

Robert Muirff8e841fa1b2
diff --git a/lucene/misc/src/java/org/apache/lucene/uninverting/UninvertingReader.java b/lucene/misc/src/java/org/apache/lucene/uninverting/UninvertingReader.java
index 12fa719e78c..08cd9c8e2f4 100644
--- a/lucene/misc/src/java/org/apache/lucene/uninverting/UninvertingReader.java
+++ b/lucene/misc/src/java/org/apache/lucene/uninverting/UninvertingReader.java
@@ -171,7 +171,15 @@ public class UninvertingReader extends FilterAtomicReader {
final Map<String,Type> mapping;
final FieldInfos fieldInfos;
- UninvertingReader(AtomicReader in, Map<String,Type> mapping) {
+ /**
+ * Create a new UninvertingReader with the specified mapping
+ * <p>
+ * Expert: This should almost never be used. Use {@link #wrap(DirectoryReader, Map)}
+ * instead.
+ *
+ * @lucene.internal
+ */
+ public UninvertingReader(AtomicReader in, Map<String,Type> mapping) {
super(in);
this.mapping = mapping;
ArrayList<FieldInfo> filteredInfos = new ArrayList<>();
diff --git a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
index 304ba87fe75..387486c8964 100644
--- a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
+++ b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
@@ -21,6 +21,7 @@ import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.AnalyzerWrapper;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.FieldInfo;
+import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.MultiFields;
import org.apache.lucene.index.StorableField;
@@ -362,7 +363,7 @@ public class IndexSchema {
queryAnalyzer = new SolrQueryAnalyzer();
}
- public Map<String,UninvertingReader.Type> getUninversionMap(DirectoryReader reader) {
+ public Map<String,UninvertingReader.Type> getUninversionMap(IndexReader reader) {
Map<String,UninvertingReader.Type> map = new HashMap<>();
for (FieldInfo f : MultiFields.getMergedFieldInfos(reader)) {
if (f.hasDocValues() == false && f.isIndexed()) {
diff --git a/solr/core/src/java/org/apache/solr/update/DeleteByQueryWrapper.java b/solr/core/src/java/org/apache/solr/update/DeleteByQueryWrapper.java
new file mode 100644
index 00000000000..4a0306447ca
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/update/DeleteByQueryWrapper.java
@@ -0,0 +1,119 @@
+package org.apache.solr.update;
+
+/*
+ * 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.
+ */
+
+import java.io.IOException;
+
+import org.apache.lucene.index.AtomicReader;
+import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.Explanation;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Scorer;
+import org.apache.lucene.search.Weight;
+import org.apache.lucene.uninverting.UninvertingReader;
+import org.apache.lucene.util.Bits;
+import org.apache.solr.schema.IndexSchema;
+
+/**
+ * Allows access to uninverted docvalues by delete-by-queries.
+ * this is used e.g. to implement versioning constraints in solr.
+ * <p>
+ * Even though we wrap for each query, UninvertingReader's core
+ * cache key is the inner one, so it still reuses fieldcaches and so on.
+ */
+final class DeleteByQueryWrapper extends Query {
+ final Query in;
+ final IndexSchema schema;
+
+ DeleteByQueryWrapper(Query in, IndexSchema schema) {
+ this.in = in;
+ this.schema = schema;
+ }
+
+ AtomicReader wrap(AtomicReader reader) {
+ return new UninvertingReader(reader, schema.getUninversionMap(reader));
+ }
+
+ // we try to be well-behaved, but we are not (and IW's applyQueryDeletes isn't much better...)
+
+ @Override
+ public Query rewrite(IndexReader reader) throws IOException {
+ Query rewritten = in.rewrite(reader);
+ if (rewritten != in) {
+ return new DeleteByQueryWrapper(in, schema);
+ } else {
+ return this;
+ }
+ }
+
+ @Override
+ public Weight createWeight(IndexSearcher searcher) throws IOException {
+ final AtomicReader wrapped = wrap((AtomicReader) searcher.getIndexReader());
+ final IndexSearcher privateContext = new IndexSearcher(wrapped);
+ final Weight inner = in.createWeight(privateContext);
+ return new Weight() {
+ @Override
+ public Explanation explain(AtomicReaderContext context, int doc) throws IOException { throw new UnsupportedOperationException(); }
+
+ @Override
+ public Query getQuery() { return DeleteByQueryWrapper.this; }
+
+ @Override
+ public float getValueForNormalization() throws IOException { return inner.getValueForNormalization(); }
+
+ @Override
+ public void normalize(float norm, float topLevelBoost) { inner.normalize(norm, topLevelBoost); }
+
+ @Override
+ public Scorer scorer(AtomicReaderContext context, Bits acceptDocs) throws IOException {
+ return inner.scorer(privateContext.getIndexReader().leaves().get(0), acceptDocs);
+ }
+ };
+ }
+
+ @Override
+ public String toString(String field) {
+ return "Uninverting(" + in.toString(field) + ")";
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((in == null) ? 0 : in.hashCode());
+ result = prime * result + ((schema == null) ? 0 : schema.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (!super.equals(obj)) return false;
+ if (getClass() != obj.getClass()) return false;
+ DeleteByQueryWrapper other = (DeleteByQueryWrapper) obj;
+ if (in == null) {
+ if (other.in != null) return false;
+ } else if (!in.equals(other.in)) return false;
+ if (schema == null) {
+ if (other.schema != null) return false;
+ } else if (!schema.equals(other.schema)) return false;
+ return true;
+ }
+}
diff --git a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java b/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
index a7ace1dd072..524075393a9 100644
--- a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
+++ b/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
@@ -242,7 +242,7 @@ public class DirectUpdateHandler2 extends UpdateHandler implements SolrCoreState
bq.add(new BooleanClause(new TermQuery(updateTerm),
Occur.MUST_NOT));
bq.add(new BooleanClause(new TermQuery(idTerm), Occur.MUST));
- writer.deleteDocuments(bq);
+ writer.deleteDocuments(new DeleteByQueryWrapper(bq, core.getLatestSchema()));
}
// Add to the transaction log *after* successfully adding to the
@@ -402,7 +402,7 @@ public class DirectUpdateHandler2 extends UpdateHandler implements SolrCoreState
} else {
RefCounted<IndexWriter> iw = solrCoreState.getIndexWriter(core);
try {
- iw.get().deleteDocuments(q);
+ iw.get().deleteDocuments(new DeleteByQueryWrapper(q, core.getLatestSchema()));
} finally {
iw.decref();
}
@@ -440,7 +440,7 @@ public class DirectUpdateHandler2 extends UpdateHandler implements SolrCoreState
.getIndexAnalyzer());
for (Query q : dbqList) {
- writer.deleteDocuments(q);
+ writer.deleteDocuments(new DeleteByQueryWrapper(q, core.getLatestSchema()));
}
} finally {
iw.decref();