|
39 | 39 | import org.apache.lucene.document.Field;
|
40 | 40 | import org.apache.lucene.document.FieldType;
|
41 | 41 | import org.apache.lucene.document.FloatPoint;
|
| 42 | +import org.apache.lucene.document.IntField; |
42 | 43 | import org.apache.lucene.document.IntPoint;
|
43 | 44 | import org.apache.lucene.document.LongPoint;
|
44 | 45 | import org.apache.lucene.document.NumericDocValuesField;
|
@@ -795,4 +796,50 @@ private static boolean arrayBinaryContains(BytesRef[] array, BytesRef value) {
|
795 | 796 | }
|
796 | 797 | return false;
|
797 | 798 | }
|
| 799 | + |
| 800 | + public void testIntegerNumericDocValue() throws IOException { |
| 801 | + // MemoryIndex used to fail when doc values are enabled and numericValue() returns an Integer |
| 802 | + // such as with IntField. |
| 803 | + FieldType ft = new FieldType(); |
| 804 | + ft.setDocValuesType(DocValuesType.NUMERIC); |
| 805 | + ft.freeze(); |
| 806 | + Field field = |
| 807 | + new Field("field", ft) { |
| 808 | + { |
| 809 | + fieldsData = 35; |
| 810 | + } |
| 811 | + }; |
| 812 | + |
| 813 | + FieldType multiFt = new FieldType(); |
| 814 | + multiFt.setDocValuesType(DocValuesType.SORTED_NUMERIC); |
| 815 | + multiFt.freeze(); |
| 816 | + Field multiField = |
| 817 | + new Field("multi_field", multiFt) { |
| 818 | + { |
| 819 | + fieldsData = 42; |
| 820 | + } |
| 821 | + }; |
| 822 | + |
| 823 | + Field intField = new IntField("int_field", 50); |
| 824 | + |
| 825 | + MemoryIndex index = MemoryIndex.fromDocument(Arrays.asList(field, multiField, intField), null); |
| 826 | + IndexSearcher searcher = index.createSearcher(); |
| 827 | + |
| 828 | + NumericDocValues ndv = |
| 829 | + searcher.getIndexReader().leaves().get(0).reader().getNumericDocValues("field"); |
| 830 | + assertTrue(ndv.advanceExact(0)); |
| 831 | + assertEquals(35, ndv.longValue()); |
| 832 | + |
| 833 | + SortedNumericDocValues sndv = |
| 834 | + searcher.getIndexReader().leaves().get(0).reader().getSortedNumericDocValues("multi_field"); |
| 835 | + assertTrue(sndv.advanceExact(0)); |
| 836 | + assertEquals(1, sndv.docValueCount()); |
| 837 | + assertEquals(42, sndv.nextValue()); |
| 838 | + |
| 839 | + sndv = |
| 840 | + searcher.getIndexReader().leaves().get(0).reader().getSortedNumericDocValues("int_field"); |
| 841 | + assertTrue(sndv.advanceExact(0)); |
| 842 | + assertEquals(1, sndv.docValueCount()); |
| 843 | + assertEquals(50, sndv.nextValue()); |
| 844 | + } |
798 | 845 | }
|
0 commit comments