Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

test with 2 numbers

Robert Muir3e82da5bc77e
diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSimpleDocValuesFormat.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSimpleDocValuesFormat.java
index d0ddce2ef01..dea13fc8147 100644
--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSimpleDocValuesFormat.java
+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSimpleDocValuesFormat.java
@@ -333,7 +333,7 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat {
String pattern;
String ordPattern;
int maxLength;
- int minValue;
+ long minValue;
int numValues;
};
@@ -350,7 +350,7 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat {
if (scratch.equals(END)) {
break;
}
- assert startsWith(FIELD);
+ assert startsWith(FIELD) : scratch.utf8ToString();
String fieldName = stripPrefix(FIELD);
FieldInfo fieldInfo = fieldInfos.fieldInfo(fieldName);
assert fieldInfo != null;
@@ -365,7 +365,7 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat {
if (DocValues.isNumber(dvType)) {
readLine();
assert startsWith(MINVALUE);
- field.minValue = Integer.parseInt(stripPrefix(MINVALUE));
+ field.minValue = Long.parseLong(stripPrefix(MINVALUE));
readLine();
assert startsWith(PATTERN);
field.pattern = stripPrefix(PATTERN);
@@ -422,6 +422,7 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat {
DocValues.Type dvType = field.fieldInfo.getDocValuesType();
if (DocValues.isNumber(dvType)) {
Source source = loadDirectSource();
+ System.out.println(maxDoc);
long[] values = new long[maxDoc];
for(int docID=0;docID<maxDoc;docID++) {
values[docID] = source.getInt(docID);
@@ -507,7 +508,6 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat {
final IndexInput in = data.clone();
final BytesRef scratch = new BytesRef();
final DecimalFormat decoder = new DecimalFormat(field.pattern, new DecimalFormatSymbols(Locale.ROOT));
- final ParsePosition pos = new ParsePosition(0);
if (DocValues.isNumber(dvType)) {
return new Source(dvType) {
@@ -519,7 +519,8 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat {
// value from the wrong field ...
in.seek(field.dataStartFilePointer + (1+field.pattern.length())*docID);
SimpleTextUtil.readLine(in, scratch);
- return field.minValue + decoder.parse(scratch.utf8ToString(), pos).longValue();
+ System.out.println("parsing delta: " + scratch.utf8ToString());
+ return field.minValue + decoder.parse(scratch.utf8ToString(), new ParsePosition(0)).longValue();
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
@@ -563,7 +564,7 @@ public class SimpleTextSimpleDocValuesFormat extends SimpleDocValuesFormat {
try {
in.seek(field.dataStartFilePointer + field.numValues * (9 + field.pattern.length() + field.maxLength) + (1 + field.ordPattern.length()) * docID);
SimpleTextUtil.readLine(in, scratch);
- return ordDecoder.parse(scratch.utf8ToString(), pos).intValue();
+ return ordDecoder.parse(scratch.utf8ToString(), new ParsePosition(0)).intValue();
} catch (IOException ioe) {
// nocommit should .get() just throw IOE...
throw new RuntimeException(ioe);
diff --git a/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.java b/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.java
index 11b9e5884a5..b345ec78288 100644
--- a/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.java
+++ b/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.java
@@ -29,6 +29,7 @@ import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.StoredDocument;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.RandomIndexWriter;
@@ -36,6 +37,7 @@ import org.apache.lucene.search.*;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
+import org.junit.Ignore;
/**
* A very simple demo used in the API documentation (src/java/overview.html).
@@ -89,6 +91,69 @@ public class TestDemoDocValue extends LuceneTestCase {
directory.close();
}
+ public void testTwoDocuments() throws IOException {
+ Analyzer analyzer = new MockAnalyzer(random());
+
+ // Store the index in memory:
+ Directory directory = newDirectory();
+ // To store an index on disk, use this instead:
+ // Directory directory = FSDirectory.open(new File("/tmp/testindex"));
+ // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!1
+ IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);
+ iwc.setMergePolicy(newLogMergePolicy());
+ IndexWriter iwriter = new IndexWriter(directory, iwc);
+ Document doc = new Document();
+ doc.add(new PackedLongDocValuesField("dv", 1));
+ iwriter.addDocument(doc);
+ doc = new Document();
+ doc.add(new PackedLongDocValuesField("dv", 2));
+ iwriter.addDocument(doc);
+ iwriter.forceMerge(1);
+ iwriter.close();
+
+ // Now search the index:
+ IndexReader ireader = DirectoryReader.open(directory); // read-only=true
+ assert ireader.leaves().size() == 1;
+ DocValues dv = ireader.leaves().get(0).reader().docValues("dv");
+ assertEquals(1, dv.getSource().getInt(0));
+ assertEquals(2, dv.getSource().getInt(1));
+
+ ireader.close();
+ directory.close();
+ }
+
+ @Ignore("get ST to use bigdecimal, also negatives are maybe not working yet!")
+ public void testBigRange() throws IOException {
+ Analyzer analyzer = new MockAnalyzer(random());
+
+ // Store the index in memory:
+ Directory directory = newDirectory();
+ // To store an index on disk, use this instead:
+ // Directory directory = FSDirectory.open(new File("/tmp/testindex"));
+ // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!1
+ IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);
+ iwc.setMergePolicy(newLogMergePolicy());
+ IndexWriter iwriter = new IndexWriter(directory, iwc);
+ Document doc = new Document();
+ doc.add(new PackedLongDocValuesField("dv", Long.MIN_VALUE));
+ iwriter.addDocument(doc);
+ doc = new Document();
+ doc.add(new PackedLongDocValuesField("dv", Long.MAX_VALUE));
+ iwriter.addDocument(doc);
+ iwriter.forceMerge(1);
+ iwriter.close();
+
+ // Now search the index:
+ IndexReader ireader = DirectoryReader.open(directory); // read-only=true
+ assert ireader.leaves().size() == 1;
+ DocValues dv = ireader.leaves().get(0).reader().docValues("dv");
+ assertEquals(Long.MIN_VALUE, dv.getSource().getInt(0));
+ assertEquals(Long.MAX_VALUE, dv.getSource().getInt(1));
+
+ ireader.close();
+ directory.close();
+ }
+
public void testDemoBytes() throws IOException {
Analyzer analyzer = new MockAnalyzer(random());