You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by tf...@apache.org on 2016/10/11 20:21:54 UTC
lucene-solr:jira/solr-8396: SOLR-8396: Fixed issue with atomic
updates. Added atomic update tests for int and double
Repository: lucene-solr
Updated Branches:
refs/heads/jira/solr-8396 ef04122c1 -> ec9d2ed02
SOLR-8396: Fixed issue with atomic updates. Added atomic update tests for int and double
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/ec9d2ed0
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/ec9d2ed0
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/ec9d2ed0
Branch: refs/heads/jira/solr-8396
Commit: ec9d2ed0245944a4b637e390ac15164ed88e6b99
Parents: ef04122
Author: Tomas Fernandez Lobbe <tf...@apache.org>
Authored: Tue Oct 11 13:21:37 2016 -0700
Committer: Tomas Fernandez Lobbe <tf...@apache.org>
Committed: Tue Oct 11 13:21:37 2016 -0700
----------------------------------------------------------------------
.../apache/solr/search/SolrIndexSearcher.java | 97 +++++++++++++++++---
.../solr/collection1/conf/schema-point.xml | 4 +
.../test/org/apache/solr/TestPointFields.java | 79 ++++++++++++++++
3 files changed, 166 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ec9d2ed0/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
index 933477b..09f6453 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
@@ -41,23 +41,71 @@ import java.util.concurrent.atomic.AtomicReference;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.DocumentStoredFieldVisitor;
import org.apache.lucene.document.LazyDocument;
-import org.apache.lucene.index.*;
+import org.apache.lucene.index.BinaryDocValues;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.DocValuesType;
+import org.apache.lucene.index.ExitableDirectoryReader;
+import org.apache.lucene.index.FieldInfo;
+import org.apache.lucene.index.FieldInfos;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexableField;
+import org.apache.lucene.index.LeafReader;
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.MultiPostingsEnum;
import org.apache.lucene.index.NumericDocValues;
+import org.apache.lucene.index.PostingsEnum;
+import org.apache.lucene.index.ReaderUtil;
+import org.apache.lucene.index.SortedDocValues;
+import org.apache.lucene.index.SortedSetDocValues;
+import org.apache.lucene.index.StoredFieldVisitor;
import org.apache.lucene.index.StoredFieldVisitor.Status;
-import org.apache.lucene.search.*;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.index.TermContext;
+import org.apache.lucene.index.Terms;
+import org.apache.lucene.index.TermsEnum;
+import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanClause.Occur;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.CollectionStatistics;
+import org.apache.lucene.search.Collector;
+import org.apache.lucene.search.ConstantScoreQuery;
+import org.apache.lucene.search.DocIdSet;
+import org.apache.lucene.search.DocIdSetIterator;
+import org.apache.lucene.search.EarlyTerminatingSortingCollector;
+import org.apache.lucene.search.Explanation;
+import org.apache.lucene.search.FieldDoc;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.LeafCollector;
+import org.apache.lucene.search.MatchAllDocsQuery;
+import org.apache.lucene.search.MultiCollector;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.Scorer;
+import org.apache.lucene.search.SimpleCollector;
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.SortField;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.TermStatistics;
+import org.apache.lucene.search.TimeLimitingCollector;
+import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.search.TopDocsCollector;
+import org.apache.lucene.search.TopFieldCollector;
+import org.apache.lucene.search.TopFieldDocs;
+import org.apache.lucene.search.TopScoreDocCollector;
+import org.apache.lucene.search.TotalHitCountCollector;
+import org.apache.lucene.search.Weight;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.FixedBitSet;
import org.apache.solr.common.SolrDocumentBase;
-import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
-import org.apache.solr.core.DirectoryFactory.DirContext;
import org.apache.solr.core.DirectoryFactory;
+import org.apache.solr.core.DirectoryFactory.DirContext;
import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrInfoMBean;
@@ -69,6 +117,7 @@ import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.schema.BoolField;
import org.apache.solr.schema.EnumField;
import org.apache.solr.schema.IndexSchema;
+import org.apache.solr.schema.PointField;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.schema.TrieDateField;
import org.apache.solr.schema.TrieDoubleField;
@@ -801,16 +850,36 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
continue;
}
Object newVal = val;
- if (schemaField.getType() instanceof TrieIntField) {
- newVal = val.intValue();
- } else if (schemaField.getType() instanceof TrieFloatField) {
- newVal = Float.intBitsToFloat(val.intValue());
- } else if (schemaField.getType() instanceof TrieDoubleField) {
- newVal = Double.longBitsToDouble(val);
- } else if (schemaField.getType() instanceof TrieDateField) {
- newVal = new Date(val);
- } else if (schemaField.getType() instanceof EnumField) {
- newVal = ((EnumField) schemaField.getType()).intValueToStringValue(val.intValue());
+ if (schemaField.getType().isPointField()) {
+ PointField.PointTypes type = ((PointField)schemaField.getType()).getType();
+ switch (type) {
+ case INTEGER:
+ newVal = val.intValue();
+ break;
+ case FLOAT:
+ newVal = Float.intBitsToFloat(val.intValue());
+ break;
+ case DOUBLE:
+ newVal = Double.longBitsToDouble(val);
+ break;
+ case DATE:
+ newVal = new Date(val);
+ break;
+ default:
+ throw new AssertionError("Unexpected PointType: " + type);
+ }
+ } else {
+ if (schemaField.getType() instanceof TrieIntField) {
+ newVal = val.intValue();
+ } else if (schemaField.getType() instanceof TrieFloatField) {
+ newVal = Float.intBitsToFloat(val.intValue());
+ } else if (schemaField.getType() instanceof TrieDoubleField) {
+ newVal = Double.longBitsToDouble(val);
+ } else if (schemaField.getType() instanceof TrieDateField) {
+ newVal = new Date(val);
+ } else if (schemaField.getType() instanceof EnumField) {
+ newVal = ((EnumField) schemaField.getType()).intValueToStringValue(val.intValue());
+ }
}
doc.addField(fieldName, newVal);
break;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ec9d2ed0/solr/core/src/test-files/solr/collection1/conf/schema-point.xml
----------------------------------------------------------------------
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-point.xml b/solr/core/src/test-files/solr/collection1/conf/schema-point.xml
index 6a5ccd6..daa8a69 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema-point.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema-point.xml
@@ -107,6 +107,10 @@
<dynamicField name="*_p_d_ni_dv" type="pdouble" indexed="false" stored="true" docValues="true"/>
<dynamicField name="*_p_d_ni_mv_dv" type="pdouble" indexed="false" stored="true" docValues="true" multiValued="true"/>
+ <!-- return DV fields as -->
+ <dynamicField name="*_p_i_dv_ns" type="pint" indexed="true" stored="false" docValues="true" useDocValuesAsStored="true"/>
+ <dynamicField name="*_p_d_dv_ns" type="pdouble" indexed="true" stored="false" docValues="true" useDocValuesAsStored="true"/>
+
<!-- dynamicField name="*_l" type="plong" indexed="true" stored="true"/>
<dynamicField name="*_f" type="pfloat" indexed="true" stored="true"/>
<dynamicField name="*_d" type="pdouble" indexed="true" stored="true"/>
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ec9d2ed0/solr/core/src/test/org/apache/solr/TestPointFields.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/TestPointFields.java b/solr/core/src/test/org/apache/solr/TestPointFields.java
index 1636b8b..42041ec 100644
--- a/solr/core/src/test/org/apache/solr/TestPointFields.java
+++ b/solr/core/src/test/org/apache/solr/TestPointFields.java
@@ -32,6 +32,8 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.collect.ImmutableMap;
+
/**
* Tests for PointField functionality
*
@@ -643,6 +645,39 @@ public class TestPointFields extends SolrTestCaseJ4 {
testPointMultiValuedFunctionQuery("number_p_i_mv", "number_p_i_mv_dv", "int", getSequentialStringArrayWithInts(20));
}
+ @Test
+ public void testIntPointFieldsAtomicUpdates() throws Exception {
+ if (!Boolean.getBoolean("enable.update.log")) {
+ return;
+ }
+ testIntPointFieldsAtomicUpdates("number_p_i", "int");
+ testIntPointFieldsAtomicUpdates("number_p_i_dv", "int");
+ testIntPointFieldsAtomicUpdates("number_p_i_dv_ns", "int");
+ }
+
+ private void testIntPointFieldsAtomicUpdates(String field, String type) throws Exception {
+ assertU(adoc(sdoc("id", "1", field, "1")));
+ assertU(commit());
+
+ assertU(adoc(sdoc("id", "1", field, ImmutableMap.of("inc", 1))));
+ assertU(commit());
+
+ assertQ(req("q", "id:1"),
+ "//result/doc[1]/" + type + "[@name='" + field + "'][.='2']");
+
+ assertU(adoc(sdoc("id", "1", field, ImmutableMap.of("inc", -1))));
+ assertU(commit());
+
+ assertQ(req("q", "id:1"),
+ "//result/doc[1]/" + type + "[@name='" + field + "'][.='1']");
+
+ assertU(adoc(sdoc("id", "1", field, ImmutableMap.of("set", 3))));
+ assertU(commit());
+
+ assertQ(req("q", "id:1"),
+ "//result/doc[1]/" + type + "[@name='" + field + "'][.='3']");
+ }
+
@Test
public void testDoublePointFieldExactQuery() throws Exception {
@@ -1072,4 +1107,48 @@ public class TestPointFields extends SolrTestCaseJ4 {
testPointMultiValuedFunctionQuery("number_p_d_mv", "number_p_d_mv_dv", "double", getRandomStringArrayWithFloats(20, true));
}
+ @Test
+ public void testDoublePointFieldsAtomicUpdates() throws Exception {
+ if (!Boolean.getBoolean("enable.update.log")) {
+ return;
+ }
+ testDoublePointFieldsAtomicUpdates("number_p_d");
+ testDoublePointFieldsAtomicUpdates("number_p_d_dv");
+ testDoublePointFieldsAtomicUpdates("number_p_d_dv_ns");
+ }
+
+ private void testDoublePointFieldsAtomicUpdates(String field) throws Exception {
+ assertU(adoc(sdoc("id", "1", field, "1.1234")));
+ assertU(commit());
+
+ assertU(adoc(sdoc("id", "1", field, ImmutableMap.of("inc", 1.1D))));
+ assertU(commit());
+
+ assertQ(req("q", "id:1"),
+ "//result/doc[1]/double[@name='" + field + "'][.='2.2234']");
+
+ assertU(adoc(sdoc("id", "1", field, ImmutableMap.of("inc", -1.1D))));
+ assertU(commit());
+
+ // TODO: can this test be better?
+ assertQ(req("q", "id:1"),
+ "//result/doc[1]/double[@name='" + field + "'][.>'1.1233']",
+ "//result/doc[1]/double[@name='" + field + "'][.<'1.1235']");
+
+ assertU(adoc(sdoc("id", "1", field, ImmutableMap.of("set", 3.123D))));
+ assertU(commit());
+
+ assertQ(req("q", "id:1"),
+ "//result/doc[1]/double[@name='" + field + "'][.='3.123']");
+
+ assertU(adoc(sdoc("id", "1", field, ImmutableMap.of("set", 3.14D))));
+ assertU(commit());
+ assertU(adoc(sdoc("id", "1", field, ImmutableMap.of("inc", 1D))));
+ assertU(commit());
+ assertQ(req("q", "id:1"),
+ "//result/doc[1]/double[@name='" + field + "'][.>'4.13']",
+ "//result/doc[1]/double[@name='" + field + "'][.<'4.15']");
+
+ }
+
}