org.apache.lucene.document.SortedDocValuesField Java Examples
The following examples show how to use
org.apache.lucene.document.SortedDocValuesField.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestIndexReaderFunctions.java From lucene-solr with Apache License 2.0 | 7 votes |
@BeforeClass public static void beforeClass() throws Exception { dir = newDirectory(); analyzer = new MockAnalyzer(random()); IndexWriterConfig iwConfig = newIndexWriterConfig(analyzer); iwConfig.setMergePolicy(newLogMergePolicy()); RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwConfig); for (String [] doc : documents) { Document document = new Document(); document.add(new StringField("id", doc[0], Field.Store.NO)); document.add(new SortedDocValuesField("id", new BytesRef(doc[0]))); document.add(new StringField("string", doc[5], Field.Store.NO)); document.add(new SortedDocValuesField("string", new BytesRef(doc[5]))); document.add(new TextField("text", doc[6], Field.Store.NO)); iw.addDocument(document); } reader = iw.getReader(); searcher = newSearcher(reader); iw.close(); }
Example #2
Source File: TestDocValuesQueries.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testMissingField() throws IOException { Directory dir = newDirectory(); RandomIndexWriter iw = new RandomIndexWriter(random(), dir); iw.addDocument(new Document()); IndexReader reader = iw.getReader(); iw.close(); IndexSearcher searcher = newSearcher(reader); for (Query query : Arrays.asList( NumericDocValuesField.newSlowRangeQuery("foo", 2, 4), SortedNumericDocValuesField.newSlowRangeQuery("foo", 2, 4), SortedDocValuesField.newSlowRangeQuery("foo", new BytesRef("abc"), new BytesRef("bcd"), random().nextBoolean(), random().nextBoolean()), SortedSetDocValuesField.newSlowRangeQuery("foo", new BytesRef("abc"), new BytesRef("bcd"), random().nextBoolean(), random().nextBoolean()))) { Weight w = searcher.createWeight(searcher.rewrite(query), ScoreMode.COMPLETE, 1); assertNull(w.scorer(searcher.getIndexReader().leaves().get(0))); } reader.close(); dir.close(); }
Example #3
Source File: ICUCollationField.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public List<IndexableField> createFields(SchemaField field, Object value) { if (field.hasDocValues()) { List<IndexableField> fields = new ArrayList<>(); fields.add(createField(field, value)); final BytesRef bytes = getCollationKey(field.getName(), value.toString()); if (field.multiValued()) { fields.add(new SortedSetDocValuesField(field.getName(), bytes)); } else { fields.add(new SortedDocValuesField(field.getName(), bytes)); } return fields; } else { return Collections.singletonList(createField(field, value)); } }
Example #4
Source File: BlockGroupingTest.java From lucene-solr with Apache License 2.0 | 6 votes |
private static List<Document> createRandomBlock(int book) { List<Document> block = new ArrayList<>(); String bookName = "book" + book; int chapterCount = atLeast(10); for (int j = 0; j < chapterCount; j++) { Document doc = new Document(); String chapterName = "chapter" + j; String chapterText = randomText(); doc.add(new TextField("book", bookName, Field.Store.YES)); doc.add(new TextField("chapter", chapterName, Field.Store.YES)); doc.add(new TextField("text", chapterText, Field.Store.NO)); doc.add(new NumericDocValuesField("length", chapterText.length())); doc.add(new SortedDocValuesField("book", new BytesRef(bookName))); if (j == chapterCount - 1) { doc.add(new TextField("blockEnd", "true", Field.Store.NO)); } block.add(doc); } return block; }
Example #5
Source File: DocValuesAdapterTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override protected void createIndex() throws IOException { indexDir = createTempDir("testIndex"); Directory dir = newFSDirectory(indexDir); RandomIndexWriter writer = new RandomIndexWriter(random(), dir, new MockAnalyzer(random())); Document doc = new Document(); doc.add(new BinaryDocValuesField("dv_binary", new BytesRef("lucene"))); doc.add(new SortedDocValuesField("dv_sorted", new BytesRef("abc"))); doc.add(new SortedSetDocValuesField("dv_sortedset", new BytesRef("python"))); doc.add(new SortedSetDocValuesField("dv_sortedset", new BytesRef("java"))); doc.add(new NumericDocValuesField("dv_numeric", 42L)); doc.add(new SortedNumericDocValuesField("dv_sortednumeric", 22L)); doc.add(new SortedNumericDocValuesField("dv_sortednumeric", 11L)); doc.add(newStringField("no_dv", "aaa", Field.Store.NO)); writer.addDocument(doc); writer.commit(); writer.close(); dir.close(); }
Example #6
Source File: CollationField.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public List<IndexableField> createFields(SchemaField field, Object value) { if (field.hasDocValues()) { List<IndexableField> fields = new ArrayList<>(); fields.add(createField(field, value)); final BytesRef bytes = getCollationKey(field.getName(), value.toString()); if (field.multiValued()) { fields.add(new SortedSetDocValuesField(field.getName(), bytes)); } else { fields.add(new SortedDocValuesField(field.getName(), bytes)); } return fields; } else { return Collections.singletonList(createField(field, value)); } }
Example #7
Source File: TestLuceneIndexer.java From dremio-oss with Apache License 2.0 | 6 votes |
@Override public void run() { try { for (int i = 0; i < 10000; ++i) { final Document document = new Document(); final String key = "key" + i; final String val = "value" + i; document.add(new StringField(key, val, Field.Store.YES)); document.add(new SortedDocValuesField(key, new BytesRef(val.getBytes()))); index.add(document); data.put(key, val); sleep(1); } } catch (InterruptedException e) { } }
Example #8
Source File: SimpleDocumentWriter.java From dremio-oss with Apache License 2.0 | 6 votes |
private void addToDoc(IndexKey key, byte[]... values){ Preconditions.checkArgument(key.getValueType() == String.class); final boolean sorted = key.isSorted(); if (sorted) { checkIfSorted(key, (Object[]) values); } checkIfMultiValueField(key, (Object[]) values); final String indexFieldName = key.getIndexFieldName(); final Store stored = key.isStored() ? Store.YES : Store.NO; for (final byte[] value : values) { if (value == null) { continue; } final BytesRef truncatedValue = new BytesRef(value,0, Math.min(value.length, MAX_STRING_LENGTH)); doc.add(new StringField(indexFieldName, truncatedValue, stored)); } if (sorted && values.length == 1 && values[0] != null) { Preconditions.checkArgument(key.getSortedValueType() == SearchFieldSorting.FieldType.STRING); doc.add(new SortedDocValuesField(indexFieldName, new BytesRef(values[0]))); } }
Example #9
Source File: SimpleDocumentWriter.java From dremio-oss with Apache License 2.0 | 6 votes |
private void addToDoc(IndexKey key, String... values){ Preconditions.checkArgument(key.getValueType() == String.class); final boolean sorted = key.isSorted(); if (sorted) { checkIfSorted(key, (Object[]) values); } checkIfMultiValueField(key, (Object[]) values); final String indexFieldName = key.getIndexFieldName(); final Store stored = key.isStored() ? Store.YES : Store.NO; for (final String value : values) { if (value == null) { continue; } final String truncatedValue = StringUtils.abbreviate(value, MAX_STRING_LENGTH); doc.add(new StringField(indexFieldName, truncatedValue, stored)); } if (sorted && values.length == 1 && values[0] != null) { Preconditions.checkArgument(key.getSortedValueType() == SearchFieldSorting.FieldType.STRING); doc.add(new SortedDocValuesField(indexFieldName, new BytesRef(values[0]))); } }
Example #10
Source File: TestSortableTextField.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testWhiteboxCreateFields() throws Exception { List<IndexableField> values = null; // common case... for (String field : Arrays.asList("keyword_stxt", "keyword_dv_stxt", "whitespace_stxt", "whitespace_f_stxt", "whitespace_l_stxt")) { values = createIndexableFields(field); assertEquals(field, 2, values.size()); assertThat(field, values.get(0), instanceOf(Field.class)); assertThat(field, values.get(1), instanceOf(SortedDocValuesField.class)); } // special cases... values = createIndexableFields("whitespace_nois_stxt"); assertEquals(1, values.size()); assertThat(values.get(0), instanceOf(SortedDocValuesField.class)); // values = createIndexableFields("whitespace_nodv_stxt"); assertEquals(1, values.size()); assertThat(values.get(0), instanceOf(Field.class)); // values = createIndexableFields("whitespace_m_stxt"); assertEquals(2, values.size()); assertThat(values.get(0), instanceOf(Field.class)); assertThat(values.get(1), instanceOf(SortedSetDocValuesField.class)); }
Example #11
Source File: SortableBinaryField.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public List<IndexableField> createFields(SchemaField field, Object value) { if (field.hasDocValues()) { List<IndexableField> fields = new ArrayList<>(); IndexableField storedField = createField(field, value); fields.add(storedField); ByteBuffer byteBuffer = toObject(storedField); BytesRef bytes = new BytesRef (byteBuffer.array(), byteBuffer.arrayOffset() + byteBuffer.position(), byteBuffer.remaining()); if (field.multiValued()) { fields.add(new SortedSetDocValuesField(field.getName(), bytes)); } else { fields.add(new SortedDocValuesField(field.getName(), bytes)); } return fields; } else { return Collections.singletonList(createField(field, value)); } }
Example #12
Source File: GroupingSearchTest.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testSetAllGroups() throws Exception { Directory dir = newDirectory(); RandomIndexWriter w = new RandomIndexWriter( random(), dir, newIndexWriterConfig(new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy())); Document doc = new Document(); doc.add(newField("group", "foo", StringField.TYPE_NOT_STORED)); doc.add(new SortedDocValuesField("group", new BytesRef("foo"))); w.addDocument(doc); IndexSearcher indexSearcher = newSearcher(w.getReader()); w.close(); GroupingSearch gs = new GroupingSearch("group"); gs.setAllGroups(true); TopGroups<?> groups = gs.search(indexSearcher, new TermQuery(new Term("group", "foo")), 0, 10); assertEquals(1, groups.totalHitCount); //assertEquals(1, groups.totalGroupCount.intValue()); assertEquals(1, groups.totalGroupedHitCount); assertEquals(1, gs.getAllMatchingGroups().size()); indexSearcher.getIndexReader().close(); dir.close(); }
Example #13
Source File: TestDocValuesIndexing.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testTypeChangeViaAddIndexesIR2() throws Exception { Directory dir = newDirectory(); IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random())); IndexWriter writer = new IndexWriter(dir, conf); Document doc = new Document(); doc.add(new NumericDocValuesField("dv", 0L)); writer.addDocument(doc); writer.close(); Directory dir2 = newDirectory(); conf = newIndexWriterConfig(new MockAnalyzer(random())); IndexWriter writer2 = new IndexWriter(dir2, conf); DirectoryReader reader = DirectoryReader.open(dir); TestUtil.addIndexesSlowly(writer2, reader); reader.close(); Document doc2 = new Document(); doc2.add(new SortedDocValuesField("dv", new BytesRef("foo"))); expectThrows(IllegalArgumentException.class, () -> { writer2.addDocument(doc2); }); writer2.close(); dir2.close(); dir.close(); }
Example #14
Source File: TestDocValuesIndexing.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testTypeChangeViaAddIndexes2() throws Exception { Directory dir = newDirectory(); IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random())); IndexWriter writer = new IndexWriter(dir, conf); Document doc = new Document(); doc.add(new NumericDocValuesField("dv", 0L)); writer.addDocument(doc); writer.close(); Directory dir2 = newDirectory(); conf = newIndexWriterConfig(new MockAnalyzer(random())); IndexWriter writer2 = new IndexWriter(dir2, conf); writer2.addIndexes(dir); Document doc2 = new Document(); doc2.add(new SortedDocValuesField("dv", new BytesRef("foo"))); expectThrows(IllegalArgumentException.class, () -> { writer2.addDocument(doc2); }); writer2.close(); dir2.close(); dir.close(); }
Example #15
Source File: TestDocValuesIndexing.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testIllegalTypeChange() throws Exception { Directory dir = newDirectory(); IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random())); IndexWriter writer = new IndexWriter(dir, conf); Document doc = new Document(); doc.add(new NumericDocValuesField("dv", 0L)); writer.addDocument(doc); Document doc2 = new Document(); doc2.add(new SortedDocValuesField("dv", new BytesRef("foo"))); expectThrows(IllegalArgumentException.class, () -> { writer.addDocument(doc2); }); IndexReader ir = writer.getReader(); assertEquals(1, ir.numDocs()); ir.close(); writer.close(); dir.close(); }
Example #16
Source File: TestDocValuesIndexing.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testMixedTypesAfterReopenAppend1() throws Exception { Directory dir = newDirectory(); IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random()))); Document doc = new Document(); doc.add(new NumericDocValuesField("foo", 0)); w.addDocument(doc); w.close(); IndexWriter w2 = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random()))); Document doc2 = new Document(); doc2.add(new SortedDocValuesField("foo", new BytesRef("hello"))); expectThrows(IllegalArgumentException.class, () -> { w2.addDocument(doc2); }); w2.close(); dir.close(); }
Example #17
Source File: TestDocValuesIndexing.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testMixedTypesDifferentSegments() throws Exception { Directory dir = newDirectory(); IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random()))); Document doc = new Document(); doc.add(new NumericDocValuesField("foo", 0)); w.addDocument(doc); w.commit(); Document doc2 = new Document(); doc2.add(new SortedDocValuesField("foo", new BytesRef("hello"))); expectThrows(IllegalArgumentException.class, () -> { w.addDocument(doc2); }); w.close(); dir.close(); }
Example #18
Source File: TestDocValuesIndexing.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testAddSortedTwice() throws IOException { Analyzer analyzer = new MockAnalyzer(random()); Directory directory = newDirectory(); // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!1 IndexWriterConfig iwc = newIndexWriterConfig(analyzer); iwc.setMergePolicy(newLogMergePolicy()); IndexWriter iwriter = new IndexWriter(directory, iwc); Document doc = new Document(); doc.add(new SortedDocValuesField("dv", new BytesRef("foo!"))); iwriter.addDocument(doc); doc.add(new SortedDocValuesField("dv", new BytesRef("bar!"))); expectThrows(IllegalArgumentException.class, () -> { iwriter.addDocument(doc); }); IndexReader ir = iwriter.getReader(); assertEquals(1, ir.numDocs()); ir.close(); iwriter.close(); directory.close(); }
Example #19
Source File: TestDocValuesIndexing.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testMixedTypesDifferentDocuments() throws Exception { Directory dir = newDirectory(); IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random()))); Document doc = new Document(); doc.add(new NumericDocValuesField("foo", 0)); w.addDocument(doc); Document doc2 = new Document(); doc2.add(new SortedDocValuesField("foo", new BytesRef("hello"))); expectThrows(IllegalArgumentException.class, () -> { w.addDocument(doc2); }); IndexReader ir = w.getReader(); assertEquals(1, ir.numDocs()); ir.close(); w.close(); dir.close(); }
Example #20
Source File: TestDocValuesIndexing.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testMixedTypesSameDocument() throws Exception { Directory dir = newDirectory(); IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random()))); w.addDocument(new Document()); Document doc = new Document(); doc.add(new NumericDocValuesField("foo", 0)); doc.add(new SortedDocValuesField("foo", new BytesRef("hello"))); expectThrows(IllegalArgumentException.class, () -> { w.addDocument(doc); }); IndexReader ir = w.getReader(); assertEquals(1, ir.numDocs()); ir.close(); w.close(); dir.close(); }
Example #21
Source File: TestDocValuesIndexing.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testDifferentTypedDocValuesField2() throws Exception { Directory d = newDirectory(); RandomIndexWriter w = new RandomIndexWriter(random(), d); Document doc = new Document(); doc.add(new NumericDocValuesField("field", 17)); w.addDocument(doc); // Index doc values are single-valued so we should not // be able to add same field more than once: doc.add(new SortedDocValuesField("field", new BytesRef("hello"))); expectThrows(IllegalArgumentException.class, () -> { w.addDocument(doc); }); DirectoryReader r = w.getReader(); NumericDocValues values = DocValues.getNumeric(getOnlyLeafReader(r), "field"); assertEquals(0, values.nextDoc()); assertEquals(17, values.longValue()); r.close(); w.close(); d.close(); }
Example #22
Source File: InMemoryLuceneIndex.java From tutorials with MIT License | 6 votes |
/** * * @param title * @param body */ public void indexDocument(String title, String body) { IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer); try { IndexWriter writter = new IndexWriter(memoryIndex, indexWriterConfig); Document document = new Document(); document.add(new TextField("title", title, Field.Store.YES)); document.add(new TextField("body", body, Field.Store.YES)); document.add(new SortedDocValuesField("title", new BytesRef(title))); writter.addDocument(document); writter.close(); } catch (IOException e) { e.printStackTrace(); } }
Example #23
Source File: BaseDocValuesFormatTestCase.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override protected void addRandomFields(Document doc) { if (usually()) { doc.add(new NumericDocValuesField("ndv", random().nextInt(1 << 12))); doc.add(new BinaryDocValuesField("bdv", new BytesRef(TestUtil.randomSimpleString(random())))); doc.add(new SortedDocValuesField("sdv", new BytesRef(TestUtil.randomSimpleString(random(), 2)))); } int numValues = random().nextInt(5); for (int i = 0; i < numValues; ++i) { doc.add(new SortedSetDocValuesField("ssdv", new BytesRef(TestUtil.randomSimpleString(random(), 2)))); } numValues = random().nextInt(5); for (int i = 0; i < numValues; ++i) { doc.add(new SortedNumericDocValuesField("sndv", TestUtil.nextLong(random(), Long.MIN_VALUE, Long.MAX_VALUE))); } }
Example #24
Source File: TestIndexWriter.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testHasUncommittedChangesAfterException() throws IOException { Analyzer analyzer = new MockAnalyzer(random()); Directory directory = newDirectory(); // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!! IndexWriterConfig iwc = newIndexWriterConfig(analyzer); iwc.setMergePolicy(newLogMergePolicy()); IndexWriter iwriter = new IndexWriter(directory, iwc); Document doc = new Document(); doc.add(new SortedDocValuesField("dv", new BytesRef("foo!"))); doc.add(new SortedDocValuesField("dv", new BytesRef("bar!"))); expectThrows(IllegalArgumentException.class, () -> { iwriter.addDocument(doc); }); iwriter.commit(); assertFalse(iwriter.hasUncommittedChanges()); iwriter.close(); directory.close(); }
Example #25
Source File: QueryIndex.java From lucene-solr with Apache License 2.0 | 6 votes |
private List<Indexable> buildIndexables(List<MonitorQuery> updates) { List<Indexable> indexables = new ArrayList<>(); for (MonitorQuery mq : updates) { if (serializer != null && mq.getQueryString() == null) { throw new IllegalArgumentException("Cannot add a MonitorQuery with a null string representation to a non-ephemeral Monitor"); } BytesRef serialized = serializer == null ? EMPTY : serializer.serialize(mq); for (QueryCacheEntry qce : QueryCacheEntry.decompose(mq, decomposer)) { Document doc = presearcher.indexQuery(qce.matchQuery, mq.getMetadata()); doc.add(new StringField(FIELDS.query_id, qce.queryId, Field.Store.NO)); doc.add(new SortedDocValuesField(FIELDS.cache_id, new BytesRef(qce.cacheId))); doc.add(new SortedDocValuesField(FIELDS.query_id, new BytesRef(qce.queryId))); doc.add(new BinaryDocValuesField(FIELDS.mq, serialized)); indexables.add(new Indexable(qce, doc)); } } return indexables; }
Example #26
Source File: Blur024CodecTest.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
@Test public void testDocValuesFormat() throws IOException { RAMDirectory directory = new RAMDirectory(); IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_43, new WhitespaceAnalyzer(Version.LUCENE_43)); conf.setCodec(new Blur024Codec()); IndexWriter writer = new IndexWriter(directory, conf); Document doc = new Document(); doc.add(new StringField("f", "v", Store.YES)); doc.add(new SortedDocValuesField("f", new BytesRef("v"))); writer.addDocument(doc); writer.close(); DirectoryReader reader = DirectoryReader.open(directory); AtomicReaderContext context = reader.leaves().get(0); AtomicReader atomicReader = context.reader(); SortedDocValues sortedDocValues = atomicReader.getSortedDocValues("f"); assertTrue(sortedDocValues.getClass().getName().startsWith(DiskDocValuesProducer.class.getName())); reader.close(); }
Example #27
Source File: TestDocValuesIndexing.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testIllegalTypeChangeAcrossSegments() throws Exception { Directory dir = newDirectory(); IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random())); IndexWriter writer = new IndexWriter(dir, conf); Document doc = new Document(); doc.add(new NumericDocValuesField("dv", 0L)); writer.addDocument(doc); writer.close(); conf = newIndexWriterConfig(new MockAnalyzer(random())); IndexWriter writer2 = new IndexWriter(dir, conf); Document doc2 = new Document(); doc2.add(new SortedDocValuesField("dv", new BytesRef("foo"))); expectThrows(IllegalArgumentException.class, () -> { writer2.addDocument(doc2); }); writer2.close(); dir.close(); }
Example #28
Source File: TestDateSort.java From lucene-solr with Apache License 2.0 | 5 votes |
private Document createDocument(String text, long time) { Document document = new Document(); // Add the text field. Field textField = newTextField(TEXT_FIELD, text, Field.Store.YES); document.add(textField); // Add the date/time field. String dateTimeString = DateTools.timeToString(time, DateTools.Resolution.SECOND); Field dateTimeField = newStringField(DATE_TIME_FIELD, dateTimeString, Field.Store.YES); document.add(dateTimeField); document.add(new SortedDocValuesField(DATE_TIME_FIELD, new BytesRef(dateTimeString))); return document; }
Example #29
Source File: TestDocValues.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * field with sorted docvalues */ public void testSortedField() throws Exception { Directory dir = newDirectory(); IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(null)); Document doc = new Document(); doc.add(new SortedDocValuesField("foo", new BytesRef("bar"))); iw.addDocument(doc); DirectoryReader dr = DirectoryReader.open(iw); LeafReader r = getOnlyLeafReader(dr); // ok assertNotNull(DocValues.getBinary(r, "foo")); assertNotNull(DocValues.getSorted(r, "foo")); assertNotNull(DocValues.getSortedSet(r, "foo")); // errors expectThrows(IllegalStateException.class, () -> { DocValues.getNumeric(r, "foo"); }); expectThrows(IllegalStateException.class, () -> { DocValues.getSortedNumeric(r, "foo"); }); dr.close(); iw.close(); dir.close(); }
Example #30
Source File: TestElevationComparator.java From lucene-solr with Apache License 2.0 | 5 votes |
private Document adoc(String[] vals) { Document doc = new Document(); for (int i = 0; i < vals.length - 2; i += 2) { doc.add(newTextField(vals[i], vals[i + 1], Field.Store.YES)); if (vals[i].equals("id")) { doc.add(new SortedDocValuesField(vals[i], new BytesRef(vals[i+1]))); } } return doc; }