Java Code Examples for org.apache.lucene.index.DocValuesType#SORTED_NUMERIC

The following examples show how to use org.apache.lucene.index.DocValuesType#SORTED_NUMERIC . 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: Lucene50FieldInfosFormat.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private static DocValuesType getDocValuesType(IndexInput input, byte b) throws IOException {
  switch(b) {
  case 0:
    return DocValuesType.NONE;
  case 1:
    return DocValuesType.NUMERIC;
  case 2:
    return DocValuesType.BINARY;
  case 3:
    return DocValuesType.SORTED;
  case 4:
    return DocValuesType.SORTED_SET;
  case 5:
    return DocValuesType.SORTED_NUMERIC;
  default:
    throw new CorruptIndexException("invalid docvalues byte: " + b, input);
  }
}
 
Example 2
Source File: Lucene60FieldInfosFormat.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private static DocValuesType getDocValuesType(IndexInput input, byte b) throws IOException {
  switch(b) {
  case 0:
    return DocValuesType.NONE;
  case 1:
    return DocValuesType.NUMERIC;
  case 2:
    return DocValuesType.BINARY;
  case 3:
    return DocValuesType.SORTED;
  case 4:
    return DocValuesType.SORTED_SET;
  case 5:
    return DocValuesType.SORTED_NUMERIC;
  default:
    throw new CorruptIndexException("invalid docvalues byte: " + b, input);
  }
}
 
Example 3
Source File: FacetFieldProcessorByHashDV.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
FacetFieldProcessorByHashDV(FacetContext fcontext, FacetField freq, SchemaField sf) {
  super(fcontext, freq, sf);
  if (freq.mincount == 0) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
        getClass()+" doesn't support mincount=0");
  }
  if (freq.prefix != null) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
        getClass()+" doesn't support prefix"); // yet, but it could
  }
  FieldInfo fieldInfo = fcontext.searcher.getFieldInfos().fieldInfo(sf.getName());
  if (fieldInfo != null &&
      fieldInfo.getDocValuesType() != DocValuesType.NUMERIC &&
      fieldInfo.getDocValuesType() != DocValuesType.SORTED &&
      fieldInfo.getDocValuesType() != DocValuesType.SORTED_NUMERIC) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
        getClass()+" only support single valued number/string with docValues");
  }
}
 
Example 4
Source File: DocValuesConsumer.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** Merges in the fields from the readers in 
 *  <code>mergeState</code>. The default implementation 
 *  calls {@link #mergeNumericField}, {@link #mergeBinaryField},
 *  {@link #mergeSortedField}, {@link #mergeSortedSetField},
 *  or {@link #mergeSortedNumericField} for each field,
 *  depending on its type.
 *  Implementations can override this method 
 *  for more sophisticated merging (bulk-byte copying, etc). */
public void merge(MergeState mergeState) throws IOException {
  for(DocValuesProducer docValuesProducer : mergeState.docValuesProducers) {
    if (docValuesProducer != null) {
      docValuesProducer.checkIntegrity();
    }
  }

  for (FieldInfo mergeFieldInfo : mergeState.mergeFieldInfos) {
    DocValuesType type = mergeFieldInfo.getDocValuesType();
    if (type != DocValuesType.NONE) {
      if (type == DocValuesType.NUMERIC) {
        mergeNumericField(mergeFieldInfo, mergeState);
      } else if (type == DocValuesType.BINARY) {
        mergeBinaryField(mergeFieldInfo, mergeState);
      } else if (type == DocValuesType.SORTED) {
        mergeSortedField(mergeFieldInfo, mergeState);
      } else if (type == DocValuesType.SORTED_SET) {
        mergeSortedSetField(mergeFieldInfo, mergeState);
      } else if (type == DocValuesType.SORTED_NUMERIC) {
        mergeSortedNumericField(mergeFieldInfo, mergeState);
      } else {
        throw new AssertionError("type=" + type);
      }
    }
  }
}
 
Example 5
Source File: SolrDocumentFetcher.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private boolean canSubstituteDvForStored(FieldInfo fieldInfo, SchemaField schemaField) {
  if (!schemaField.hasDocValues() || !schemaField.stored()) return false;
  if (schemaField.multiValued()) return false;
  DocValuesType docValuesType = fieldInfo.getDocValuesType();
  NumberType numberType = schemaField.getType().getNumberType();
  // can not decode a numeric without knowing its numberType
  if (numberType == null && (docValuesType == DocValuesType.SORTED_NUMERIC || docValuesType == DocValuesType.NUMERIC)) {
    return false;
  }
  return true;
}
 
Example 6
Source File: RealTimeGetComponent.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private static SolrDocument toSolrDoc(Document doc, IndexSchema schema) {
  SolrDocument out = new SolrDocument();
  for( IndexableField f : doc.getFields() ) {
    // Make sure multivalued fields are represented as lists
    Object existing = out.get(f.name());
    if (existing == null) {
    SchemaField sf = schema.getFieldOrNull(f.name());

    // don't return copyField targets
      if (sf != null && schema.isCopyFieldTarget(sf)) continue;
    
      if (sf != null && sf.multiValued()) {
      List<Object> vals = new ArrayList<>();
        if (f.fieldType().docValuesType() == DocValuesType.SORTED_NUMERIC) {
          // SORTED_NUMERICS store sortable bits version of the value, need to retrieve the original
          vals.add(sf.getType().toObject(f)); // (will materialize by side-effect)
        } else {
          vals.add( materialize(f) );
        }
      out.setField(f.name(), vals);
    } else {
        out.setField( f.name(), materialize(f) );
      }
    }
    else {
      out.addField( f.name(), materialize(f) );
    }
  }
  return out;
}
 
Example 7
Source File: FloatPointField.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public Object toObject(IndexableField f) {
  final Number val = f.numericValue();
  if (val != null) {
    if (f.fieldType().stored() == false && f.fieldType().docValuesType() == DocValuesType.NUMERIC) {
      return Float.intBitsToFloat(val.intValue());
    } else if (f.fieldType().stored() == false && f.fieldType().docValuesType() == DocValuesType.SORTED_NUMERIC) {
      return NumericUtils.sortableIntToFloat(val.intValue());
    } else  {
      return val;
    }
  } else {
    throw new AssertionError("Unexpected state. Field: '" + f + "'");
  }
}
 
Example 8
Source File: DoublePointField.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public Object toObject(IndexableField f) {
  final Number val = f.numericValue();
  if (val != null) {
    if (f.fieldType().stored() == false && f.fieldType().docValuesType() == DocValuesType.NUMERIC) {
      return Double.longBitsToDouble(val.longValue());
    } else if (f.fieldType().stored() == false && f.fieldType().docValuesType() == DocValuesType.SORTED_NUMERIC) {
      return NumericUtils.sortableLongToDouble(val.longValue());
    } else {
      return val;
    }
  } else {
    throw new AssertionError("Unexpected state. Field: '" + f + "'");
  }
}
 
Example 9
Source File: DocValuesMultiTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testDocValues() throws IOException {

  final DocValuesType expectedNumericDvType = Boolean.getBoolean(NUMERIC_POINTS_SYSPROP) ?
    DocValuesType.SORTED_NUMERIC : DocValuesType.SORTED_SET;
  
  assertU(adoc("id", "1", "floatdv", "4.5", "intdv", "-1", "intdv", "3",
      "stringdv", "value1", "stringdv", "value2",
      "booldv", "false", "booldv", "true"));
  assertU(commit());
  try (SolrCore core = h.getCoreInc()) {
    final RefCounted<SolrIndexSearcher> searcherRef = core.openNewSearcher(true, true);
    final SolrIndexSearcher searcher = searcherRef.get();
    try {
      final LeafReader reader = searcher.getSlowAtomicReader();
      assertEquals(1, reader.numDocs());
      final FieldInfos infos = reader.getFieldInfos();
      assertEquals(DocValuesType.SORTED_SET, infos.fieldInfo("stringdv").getDocValuesType());
      assertEquals(DocValuesType.SORTED_SET, infos.fieldInfo("booldv").getDocValuesType());
      assertEquals(expectedNumericDvType, infos.fieldInfo("floatdv").getDocValuesType());
      assertEquals(expectedNumericDvType, infos.fieldInfo("intdv").getDocValuesType());

      SortedSetDocValues dv = reader.getSortedSetDocValues("stringdv");
      assertEquals(0, dv.nextDoc());
      assertEquals(0, dv.nextOrd());
      assertEquals(1, dv.nextOrd());
      assertEquals(SortedSetDocValues.NO_MORE_ORDS, dv.nextOrd());

      dv = reader.getSortedSetDocValues("booldv");
      assertEquals(0, dv.nextDoc());
      assertEquals(0, dv.nextOrd());
      assertEquals(1, dv.nextOrd());
      assertEquals(SortedSetDocValues.NO_MORE_ORDS, dv.nextOrd());


    } finally {
      searcherRef.decref();
    }
  }
}