mirror of https://github.com/apache/lucene.git
Modernize LineFileDocs. (#12929)
This replaces `StringField`/`SortedDocValuesField` with `KeywordField` and `IntPoint`/`NumericDocValuesField` with `IntField`.
This commit is contained in:
parent
5c084fcd6e
commit
bcc7e120ba
|
@ -64,7 +64,7 @@ public class TestAllFilesCheckIndexHeader extends LuceneTestCase {
|
|||
}
|
||||
if (random().nextInt(15) == 0) {
|
||||
riw.updateNumericDocValue(
|
||||
new Term("docid", Integer.toString(i)), "docid_intDV", Long.valueOf(i));
|
||||
new Term("docid", Integer.toString(i)), "page_views", Long.valueOf(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public class TestAllFilesHaveChecksumFooter extends LuceneTestCase {
|
|||
}
|
||||
if (random().nextInt(15) == 0) {
|
||||
riw.updateNumericDocValue(
|
||||
new Term("docid", Integer.toString(i)), "docid_intDV", Long.valueOf(i));
|
||||
new Term("docid", Integer.toString(i)), "page_views", Long.valueOf(i));
|
||||
}
|
||||
}
|
||||
riw.close();
|
||||
|
|
|
@ -49,7 +49,7 @@ public class TestAllFilesHaveCodecHeader extends LuceneTestCase {
|
|||
}
|
||||
if (random().nextInt(15) == 0) {
|
||||
riw.updateNumericDocValue(
|
||||
new Term("docid", Integer.toString(i)), "docid_intDV", Long.valueOf(i));
|
||||
new Term("docid", Integer.toString(i)), "page_views", Long.valueOf(i));
|
||||
}
|
||||
}
|
||||
riw.close();
|
||||
|
|
|
@ -37,14 +37,14 @@ import java.util.zip.GZIPInputStream;
|
|||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.document.IntField;
|
||||
import org.apache.lucene.document.IntPoint;
|
||||
import org.apache.lucene.document.KeywordField;
|
||||
import org.apache.lucene.document.NumericDocValuesField;
|
||||
import org.apache.lucene.document.SortedDocValuesField;
|
||||
import org.apache.lucene.document.StringField;
|
||||
import org.apache.lucene.document.TextField;
|
||||
import org.apache.lucene.index.IndexOptions;
|
||||
import org.apache.lucene.index.IndexableField;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.CloseableThreadLocal;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
|
||||
|
@ -199,17 +199,16 @@ public class LineFileDocs implements Closeable {
|
|||
final Document doc;
|
||||
final Field titleTokenized;
|
||||
final Field title;
|
||||
final Field titleDV;
|
||||
final Field body;
|
||||
final Field id;
|
||||
final Field idNum;
|
||||
final Field idNumDV;
|
||||
final Field date;
|
||||
final Field pageViews;
|
||||
|
||||
public DocState() {
|
||||
doc = new Document();
|
||||
|
||||
title = new StringField("title", "", Field.Store.NO);
|
||||
title = new KeywordField("title", "", Field.Store.NO);
|
||||
doc.add(title);
|
||||
|
||||
FieldType ft = new FieldType(TextField.TYPE_STORED);
|
||||
|
@ -227,16 +226,15 @@ public class LineFileDocs implements Closeable {
|
|||
id = new StringField("docid", "", Field.Store.YES);
|
||||
doc.add(id);
|
||||
|
||||
idNum = new IntPoint("docid_int", 0);
|
||||
idNum = new IntField("docid_int", 0, Field.Store.NO);
|
||||
doc.add(idNum);
|
||||
|
||||
date = new StringField("date", "", Field.Store.YES);
|
||||
doc.add(date);
|
||||
|
||||
titleDV = new SortedDocValuesField("titleDV", new BytesRef());
|
||||
idNumDV = new NumericDocValuesField("docid_intDV", 0);
|
||||
doc.add(titleDV);
|
||||
doc.add(idNumDV);
|
||||
// A numeric DV field that can be used for DV updates
|
||||
pageViews = new NumericDocValuesField("page_views", 0L);
|
||||
doc.add(pageViews);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -277,17 +275,12 @@ public class LineFileDocs implements Closeable {
|
|||
docState.body.setStringValue(line.substring(1 + spot2, line.length()));
|
||||
final String title = line.substring(0, spot);
|
||||
docState.title.setStringValue(title);
|
||||
if (docState.titleDV != null) {
|
||||
docState.titleDV.setBytesValue(new BytesRef(title));
|
||||
}
|
||||
docState.titleTokenized.setStringValue(title);
|
||||
docState.date.setStringValue(line.substring(1 + spot, spot2));
|
||||
final int i = id.getAndIncrement();
|
||||
docState.id.setStringValue(Integer.toString(i));
|
||||
docState.idNum.setIntValue(i);
|
||||
if (docState.idNumDV != null) {
|
||||
docState.idNumDV.setLongValue(i);
|
||||
}
|
||||
docState.pageViews.setLongValue(random.nextInt(10_000));
|
||||
|
||||
if (random.nextInt(5) == 4) {
|
||||
// Make some sparse fields
|
||||
|
|
|
@ -63,6 +63,8 @@ import org.apache.lucene.document.BinaryDocValuesField;
|
|||
import org.apache.lucene.document.BinaryPoint;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.IntField;
|
||||
import org.apache.lucene.document.KeywordField;
|
||||
import org.apache.lucene.document.NumericDocValuesField;
|
||||
import org.apache.lucene.document.SortedDocValuesField;
|
||||
import org.apache.lucene.index.CheckIndex;
|
||||
|
@ -1420,7 +1422,19 @@ public final class TestUtil {
|
|||
final Field field2;
|
||||
final DocValuesType dvType = field1.fieldType().docValuesType();
|
||||
final int dimCount = field1.fieldType().pointDimensionCount();
|
||||
if (dvType != DocValuesType.NONE) {
|
||||
if (f instanceof KeywordField) {
|
||||
field2 =
|
||||
new KeywordField(
|
||||
f.name(),
|
||||
f.stringValue(),
|
||||
f.fieldType().stored() ? Field.Store.YES : Field.Store.NO);
|
||||
} else if (f instanceof IntField) {
|
||||
field2 =
|
||||
new IntField(
|
||||
f.name(),
|
||||
f.numericValue().intValue(),
|
||||
f.fieldType().stored() ? Field.Store.YES : Field.Store.NO);
|
||||
} else if (dvType != DocValuesType.NONE) {
|
||||
switch (dvType) {
|
||||
case NUMERIC:
|
||||
field2 = new NumericDocValuesField(field1.name(), field1.numericValue().longValue());
|
||||
|
|
Loading…
Reference in New Issue