List of usage examples for org.apache.lucene.util NumericUtils sortableLongToDouble
public static double sortableLongToDouble(long encoded)
long back to a double. From source file:com.github.flaxsearch.util.BytesRefUtils.java
License:Apache License
private static Function<BytesRef, String> getEncoder(String type) { switch (type.toLowerCase(Locale.ROOT)) { case "base64": return b -> new String(Base64.getUrlEncoder().encode(b.bytes), Charset.defaultCharset()); case "utf8": return BytesRef::utf8ToString; case "int": return b -> Integer.toString(LegacyNumericUtils.prefixCodedToInt(b)); case "long": return b -> Long.toString(LegacyNumericUtils.prefixCodedToLong(b)); case "float": return b -> Float.toString(NumericUtils.sortableIntToFloat(LegacyNumericUtils.prefixCodedToInt(b))); case "double": return b -> Double.toString(NumericUtils.sortableLongToDouble(LegacyNumericUtils.prefixCodedToLong(b))); default://ww w. j a v a2 s.c o m throw new IllegalArgumentException("Unknown encoder type: " + type); } }
From source file:dk.statsbiblioteket.netark.dvenabler.DVReaderTest.java
License:Apache License
private static Double getDoubleDocValue(AtomicReaderContext atomContext, int docID, String field) throws IOException { NumericDocValues dvs = atomContext.reader().getNumericDocValues(field); if (dvs == null) { throw new IllegalStateException("No NumericDocValues for field '" + field + "'"); }/*from w w w . jav a 2 s . c o m*/ return NumericUtils.sortableLongToDouble(dvs.get(docID)); }
From source file:org.alfresco.solr.transformer.DocValueDocTransformer.java
License:Open Source License
@Override public void transform(SolrDocument doc, int docid, float score) throws IOException { for (String fieldName : context.getSearcher().getFieldNames()) { SchemaField schemaField = context.getSearcher().getSchema().getFieldOrNull(fieldName); if (schemaField != null) { if (schemaField.hasDocValues()) { SortedDocValues sortedDocValues = context.getSearcher().getSlowAtomicReader() .getSortedDocValues(fieldName); if (sortedDocValues != null) { int ordinal = sortedDocValues.getOrd(docid); if (ordinal > -1) { doc.removeFields(fieldName); String alfrescoFieldName = AlfrescoSolrDataModel.getInstance() .getAlfrescoPropertyFromSchemaField(fieldName); doc.removeFields(alfrescoFieldName); doc.addField(alfrescoFieldName, schemaField.getType().toObject(schemaField, sortedDocValues.lookupOrd(ordinal))); }// www . j a v a 2s . c o m } SortedSetDocValues sortedSetDocValues = context.getSearcher().getSlowAtomicReader() .getSortedSetDocValues(fieldName); if (sortedSetDocValues != null) { ArrayList<Object> newValues = new ArrayList<Object>(); sortedSetDocValues.setDocument(docid); long ordinal; while ((ordinal = sortedSetDocValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) { newValues.add(schemaField.getType().toObject(schemaField, sortedSetDocValues.lookupOrd(ordinal))); } doc.removeFields(fieldName); String alfrescoFieldName = AlfrescoSolrDataModel.getInstance() .getAlfrescoPropertyFromSchemaField(fieldName); doc.removeFields(alfrescoFieldName); doc.addField(alfrescoFieldName, newValues); } BinaryDocValues binaryDocValues = context.getSearcher().getSlowAtomicReader() .getBinaryDocValues(fieldName); if (binaryDocValues != null) { doc.removeFields(fieldName); String alfrescoFieldName = AlfrescoSolrDataModel.getInstance() .getAlfrescoPropertyFromSchemaField(fieldName); doc.removeFields(alfrescoFieldName); doc.addField(alfrescoFieldName, schemaField.getType().toObject(schemaField, binaryDocValues.get(docid))); } if (schemaField.getType().getNumericType() != null) { NumericDocValues numericDocValues = context.getSearcher().getSlowAtomicReader() .getNumericDocValues(fieldName); if (numericDocValues != null) { doc.removeFields(fieldName); String alfrescoFieldName = AlfrescoSolrDataModel.getInstance() .getAlfrescoPropertyFromSchemaField(fieldName); doc.removeFields(alfrescoFieldName); switch (schemaField.getType().getNumericType()) { case DOUBLE: doc.addField(alfrescoFieldName, Double.longBitsToDouble(numericDocValues.get(docid))); break; case FLOAT: doc.addField(alfrescoFieldName, Float.intBitsToFloat((int) numericDocValues.get(docid))); break; case INT: doc.addField(alfrescoFieldName, (int) numericDocValues.get(docid)); break; case LONG: doc.addField(alfrescoFieldName, numericDocValues.get(docid)); break; } } SortedNumericDocValues sortedNumericDocValues = context.getSearcher().getSlowAtomicReader() .getSortedNumericDocValues(fieldName); if (sortedNumericDocValues != null) { sortedNumericDocValues.setDocument(docid); doc.removeFields(fieldName); String alfrescoFieldName = AlfrescoSolrDataModel.getInstance() .getAlfrescoPropertyFromSchemaField(fieldName); doc.removeFields(alfrescoFieldName); ArrayList<Object> newValues = new ArrayList<Object>(sortedNumericDocValues.count()); if (sortedNumericDocValues.count() > 0) { for (int i = 0; i < sortedNumericDocValues.count(); i++) { switch (schemaField.getType().getNumericType()) { case DOUBLE: newValues.add(NumericUtils .sortableLongToDouble(sortedNumericDocValues.valueAt(i))); break; case FLOAT: newValues.add(NumericUtils .sortableIntToFloat((int) sortedNumericDocValues.valueAt(i))); break; case INT: newValues.add((int) sortedNumericDocValues.valueAt(i)); break; case LONG: newValues.add(sortedNumericDocValues.valueAt(i)); break; } } } doc.addField(alfrescoFieldName, newValues); } } } } } }
From source file:org.apache.blur.analysis.type.DoubleFieldTypeDefinition.java
License:Apache License
@Override public String readTerm(BytesRef byteRef) { if (NumericUtils.getPrefixCodedLongShift(byteRef) == 0) return NumericUtils.sortableLongToDouble(NumericUtils.prefixCodedToLong(byteRef)) + ""; return null;/* w w w . ja va2s. c o m*/ }
From source file:org.apache.solr.analytics.function.field.DoubleField.java
License:Apache License
@Override public void collect(int doc) throws IOException { exists = docValues.advanceExact(doc); if (exists) { value = NumericUtils.sortableLongToDouble(docValues.longValue()); }//from w w w. j a v a 2 s. c o m }
From source file:org.apache.solr.analytics.function.field.DoubleMultiPointField.java
License:Apache License
@Override public void collect(int doc) throws IOException { if (docValues.advanceExact(doc)) { count = docValues.docValueCount(); resizeEmptyValues(count);//from w ww .j a v a 2s . co m for (int i = 0; i < count; ++i) { values[i] = NumericUtils.sortableLongToDouble(docValues.nextValue()); } } else { count = 0; } }
From source file:org.apache.solr.analytics.function.field.DoubleMultiTrieField.java
License:Apache License
@Override public void collect(int doc) throws IOException { count = 0;/*from www . ja va2 s . c o m*/ if (docValues.advanceExact(doc)) { int term; while ((term = (int) docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) { if (count == values.length) { resizeValues(); } values[count++] = NumericUtils .sortableLongToDouble(LegacyNumericUtils.prefixCodedToLong(docValues.lookupOrd(term))); } } }
From source file:org.apache.solr.handler.component.SortedNumericStatsValues.java
License:Apache License
private Number toCorrectType(long value) { switch (numberType) { case INTEGER: case LONG:// w w w . j a v a 2s.co m return value; case FLOAT: return NumericUtils.sortableIntToFloat((int) value); case DOUBLE: return NumericUtils.sortableLongToDouble(value); default: throw new AssertionError("Unsupported number type"); } }
From source file:org.apache.solr.legacy.TestLegacyNumericUtils.java
License:Apache License
public void testDoubles() throws Exception { double[] vals = new double[] { Double.NEGATIVE_INFINITY, -2.3E25, -1.0E15, -1.0, -1.0E-1, -1.0E-2, -0.0, +0.0, 1.0E-2, 1.0E-1, 1.0, 1.0E15, 2.3E25, Double.POSITIVE_INFINITY, Double.NaN }; long[] longVals = new long[vals.length]; // check forward and back conversion for (int i = 0; i < vals.length; i++) { longVals[i] = NumericUtils.doubleToSortableLong(vals[i]); assertTrue("forward and back conversion should generate same double", Double.compare(vals[i], NumericUtils.sortableLongToDouble(longVals[i])) == 0); }/* ww w . ja v a2 s .c o m*/ // check sort order (prefixVals should be ascending) for (int i = 1; i < longVals.length; i++) { assertTrue("check sort order", longVals[i - 1] < longVals[i]); } }
From source file:org.apache.solr.legacy.TestLegacyTerms.java
License:Apache License
public void testDoubleFieldMinMax() throws Exception { Directory dir = newDirectory();/*from www . j a v a 2 s . c om*/ RandomIndexWriter w = new RandomIndexWriter(random(), dir); int numDocs = atLeast(100); double minValue = Double.POSITIVE_INFINITY; double maxValue = Double.NEGATIVE_INFINITY; for (int i = 0; i < numDocs; i++) { Document doc = new Document(); double num = random().nextDouble(); minValue = Math.min(num, minValue); maxValue = Math.max(num, maxValue); doc.add(new LegacyDoubleField("field", num, Field.Store.NO)); w.addDocument(doc); } IndexReader r = w.getReader(); Terms terms = MultiFields.getTerms(r, "field"); assertEquals(minValue, NumericUtils.sortableLongToDouble(LegacyNumericUtils.getMinLong(terms)), 0.0); assertEquals(maxValue, NumericUtils.sortableLongToDouble(LegacyNumericUtils.getMaxLong(terms)), 0.0); r.close(); w.close(); dir.close(); }