org.apache.lucene.document.DoublePoint Java Examples

The following examples show how to use org.apache.lucene.document.DoublePoint. 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: NumberFieldMapper.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public List<Field> createFields(String name, Number value,
                                boolean indexed, boolean docValued, boolean stored) {
    List<Field> fields = new ArrayList<>();
    if (indexed) {
        fields.add(new DoublePoint(name, value.doubleValue()));
    }
    if (docValued) {
        fields.add(new SortedNumericDocValuesField(name,
            NumericUtils.doubleToSortableLong(value.doubleValue())));
    }
    if (stored) {
        fields.add(new StoredField(name, value.doubleValue()));
    }
    return fields;
}
 
Example #2
Source File: TestPointQueries.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testToString() throws Exception {
  
  // ints
  assertEquals("field:[1 TO 2]", IntPoint.newRangeQuery("field", 1, 2).toString());
  assertEquals("field:[-2 TO 1]", IntPoint.newRangeQuery("field", -2, 1).toString());

  // longs
  assertEquals("field:[1099511627776 TO 2199023255552]", LongPoint.newRangeQuery("field", 1L<<40, 1L<<41).toString());
  assertEquals("field:[-5 TO 6]", LongPoint.newRangeQuery("field", -5L, 6L).toString());
  
  // floats
  assertEquals("field:[1.3 TO 2.5]", FloatPoint.newRangeQuery("field", 1.3F, 2.5F).toString());
  assertEquals("field:[-2.9 TO 1.0]", FloatPoint.newRangeQuery("field", -2.9F, 1.0F).toString());
  
  // doubles
  assertEquals("field:[1.3 TO 2.5]", DoublePoint.newRangeQuery("field", 1.3, 2.5).toString());
  assertEquals("field:[-2.9 TO 1.0]", DoublePoint.newRangeQuery("field", -2.9, 1.0).toString());
  
  // n-dimensional double
  assertEquals("field:[1.3 TO 2.5],[-2.9 TO 1.0]", DoublePoint.newRangeQuery("field", 
                                                                    new double[] { 1.3, -2.9 }, 
                                                                    new double[] { 2.5, 1.0 }).toString());

}
 
Example #3
Source File: PointVectorStrategy.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a numeric range query based on FieldType
 * {@link LegacyNumericRangeQuery} is used for indexes created using {@code FieldType.LegacyNumericType}
 * {@link DoublePoint#newRangeQuery} is used for indexes created using {@link DoublePoint} fields
 */
private Query rangeQuery(String fieldName, Double min, Double max) {
  if (hasPointVals) {
    if (min == null) {
      min = Double.NEGATIVE_INFINITY;
    }

    if (max == null) {
      max = Double.POSITIVE_INFINITY;
    }

    return DoublePoint.newRangeQuery(fieldName, min, max);

  } else if (legacyNumericFieldType != null) {// todo remove legacy numeric support in 7.0
    return LegacyNumericRangeQuery.newDoubleRange(fieldName, legacyNumericFieldType.numericPrecisionStep(), min, max, true, true);//inclusive
  }
  //TODO try doc-value range query?
  throw new UnsupportedOperationException("An index is required for this operation.");
}
 
Example #4
Source File: BBoxStrategy.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a numeric range query based on FieldType
 * {@link LegacyNumericRangeQuery} is used for indexes created using {@code FieldType.LegacyNumericType}
 * {@link DoublePoint#newRangeQuery} is used for indexes created using {@link DoublePoint} fields
 *
 * @param fieldname field name. must not be <code>null</code>.
 * @param min minimum value of the range.
 * @param max maximum value of the range.
 * @param minInclusive include the minimum value if <code>true</code>.
 * @param maxInclusive include the maximum value if <code>true</code>
 */
private Query makeNumericRangeQuery(String fieldname, Double min, Double max, boolean minInclusive, boolean maxInclusive) {
  if (hasPointVals) {
    if (min == null) {
      min = Double.NEGATIVE_INFINITY;
    }

    if (max == null) {
      max = Double.POSITIVE_INFINITY;
    }

    if (minInclusive == false) {
      min = Math.nextUp(min);
    }

    if (maxInclusive == false) {
      max = Math.nextDown(max);
    }

    return DoublePoint.newRangeQuery(fieldname, min, max);
  } else if (legacyNumericFieldType != null) {// todo remove legacy numeric support in 7.0
    return LegacyNumericRangeQuery.newDoubleRange(fieldname, legacyNumericFieldType.numericPrecisionStep(), min, max, minInclusive, maxInclusive);
  }
  throw new UnsupportedOperationException("An index is required for this operation.");
}
 
Example #5
Source File: PointMerger.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void visit(int docID, byte[] packedValue) throws IOException {
  // TODO: handle filter or deleted documents?
  double v = DoublePoint.decodeDimension(packedValue, 0);
  if (v < last) return;

  if (v == last && pos >= 0) {
    count[pos]++;
  } else {
    if (pos+1 < values.length) {
      last = v;
      ++pos;
      values[pos] = v;
      count[pos] = 1;
    } else {
      // a new value we don't have room for
      throw breakException;
    }
  }
}
 
Example #6
Source File: NumericFieldType.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected Query getRangeQueryForMultiValuedDoubleDocValues(SchemaField sf, String min, String max, boolean minInclusive, boolean maxInclusive) {
  double minVal,maxVal;
  if (min == null) {
    minVal = Double.NEGATIVE_INFINITY;
  } else {
    minVal = parseDoubleFromUser(sf.getName(), min);
    if (!minInclusive) {
      if (minVal == Double.POSITIVE_INFINITY) return new MatchNoDocsQuery();
      minVal = DoublePoint.nextUp(minVal);
    }
  }
  if (max == null) {
    maxVal = Double.POSITIVE_INFINITY;
  } else {
    maxVal = parseDoubleFromUser(sf.getName(), max);
    if (!maxInclusive) {
      if (maxVal == Double.NEGATIVE_INFINITY) return new MatchNoDocsQuery();
      maxVal = DoublePoint.nextDown(maxVal);
    }
  }
  Long minBits = NumericUtils.doubleToSortableLong(minVal);
  Long maxBits = NumericUtils.doubleToSortableLong(maxVal);
  return numericDocValuesRangeQuery(sf.getName(), minBits, maxBits, true, true, true);
}
 
Example #7
Source File: DoublePointField.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public Query getPointRangeQuery(QParser parser, SchemaField field, String min, String max, boolean minInclusive,
    boolean maxInclusive) {
  double actualMin, actualMax;
  if (min == null) {
    actualMin = Double.NEGATIVE_INFINITY;
  } else {
    actualMin = parseDoubleFromUser(field.getName(), min);
    if (!minInclusive) {
      if (actualMin == Double.POSITIVE_INFINITY) return new MatchNoDocsQuery();
      actualMin = DoublePoint.nextUp(actualMin);
    }
  }
  if (max == null) {
    actualMax = Double.POSITIVE_INFINITY;
  } else {
    actualMax = parseDoubleFromUser(field.getName(), max);
    if (!maxInclusive) {
      if (actualMax == Double.NEGATIVE_INFINITY) return new MatchNoDocsQuery();
      actualMax = DoublePoint.nextDown(actualMax);
    }
  }
  return DoublePoint.newRangeQuery(field.getName(), actualMin, actualMax);
}
 
Example #8
Source File: TestPointQueries.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testEmptyPointInSetQuery() throws Exception {
  Directory dir = newDirectory();
  IndexWriterConfig iwc = newIndexWriterConfig();
  iwc.setCodec(getCodec());
  IndexWriter w = new IndexWriter(dir, iwc);

  Document doc = new Document();
  doc.add(new IntPoint("int", 17));
  doc.add(new LongPoint("long", 17L));
  doc.add(new FloatPoint("float", 17.0f));
  doc.add(new DoublePoint("double", 17.0));
  doc.add(new BinaryPoint("bytes", new byte[] {0, 17}));
  w.addDocument(doc);

  IndexReader r = DirectoryReader.open(w);
  IndexSearcher s = newSearcher(r, false);
  assertEquals(0, s.count(IntPoint.newSetQuery("int")));
  assertEquals(0, s.count(LongPoint.newSetQuery("long")));
  assertEquals(0, s.count(FloatPoint.newSetQuery("float")));
  assertEquals(0, s.count(DoublePoint.newSetQuery("double")));
  assertEquals(0, s.count(BinaryPoint.newSetQuery("bytes")));

  w.close();
  r.close();
  dir.close();
}
 
Example #9
Source File: PointVectorStrategy.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a numeric range query based on FieldType
 * {@link DoublePoint#newRangeQuery} is used for indexes created using {@link DoublePoint} fields
 */
private Query rangeQuery(String fieldName, Double min, Double max) {
  if (hasPointVals) {
    if (min == null) {
      min = Double.NEGATIVE_INFINITY;
    }

    if (max == null) {
      max = Double.POSITIVE_INFINITY;
    }

    return DoublePoint.newRangeQuery(fieldName, min, max);

  }
  //TODO try doc-value range query?
  throw new UnsupportedOperationException("An index is required for this operation.");
}
 
Example #10
Source File: BBoxStrategy.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a numeric range query based on FieldType
 * {@link DoublePoint#newRangeQuery} is used for indexes created using {@link DoublePoint} fields
 *
 * @param fieldname field name. must not be <code>null</code>.
 * @param min minimum value of the range.
 * @param max maximum value of the range.
 * @param minInclusive include the minimum value if <code>true</code>.
 * @param maxInclusive include the maximum value if <code>true</code>
 */
private Query makeNumericRangeQuery(String fieldname, Double min, Double max, boolean minInclusive, boolean maxInclusive) {
  if (hasPointVals) {
    if (min == null) {
      min = Double.NEGATIVE_INFINITY;
    }

    if (max == null) {
      max = Double.POSITIVE_INFINITY;
    }

    if (minInclusive == false) {
      min = Math.nextUp(min);
    }

    if (maxInclusive == false) {
      max = Math.nextDown(max);
    }

    return DoublePoint.newRangeQuery(fieldname, min, max);
  }
  throw new UnsupportedOperationException("An index is required for this operation.");
}
 
Example #11
Source File: TestPointQueries.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testPointInSetQueryToString() throws Exception {
  // int
  assertEquals("int:{-42 18}", IntPoint.newSetQuery("int", -42, 18).toString());

  // long
  assertEquals("long:{-42 18}", LongPoint.newSetQuery("long", -42L, 18L).toString());

  // float
  assertEquals("float:{-42.0 18.0}", FloatPoint.newSetQuery("float", -42.0f, 18.0f).toString());

  // double
  assertEquals("double:{-42.0 18.0}", DoublePoint.newSetQuery("double", -42.0, 18.0).toString());

  // binary
  assertEquals("bytes:{[12] [2a]}", BinaryPoint.newSetQuery("bytes", new byte[] {42}, new byte[] {18}).toString());
}
 
Example #12
Source File: DoubleQuery.java    From HongsCORE with MIT License 6 votes vote down vote up
@Override
public Query whr(String k, Object n, Object x, boolean l, boolean g) {
    if (n == null && x == null) {
        throw new NullPointerException("Range for "+k+" must be number, but null");
    }
    double n2, x2;
    if (n == null || "".equals(n)) {
        n2 = Double.NEGATIVE_INFINITY;
    } else {
        n2 = Synt.asFloat (n);
        if (!l) {
            n2 = DoublePoint.nextUp  (n2);
        }
    }
    if (x == null || "".equals(x)) {
        x2 = Double.POSITIVE_INFINITY;
    } else {
        x2 = Synt.asFloat (x);
        if (!g) {
            x2 = DoublePoint.nextDown(x2);
        }
    }
    Query   q2 = DoublePoint.newRangeQuery("@"+k, n2, x2);
    return  q2;
}
 
Example #13
Source File: TestMemoryIndex.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testMultiValuedPointsSortedCorrectly() throws Exception {
  Document doc = new Document();
  doc.add(new IntPoint("ints", 3));
  doc.add(new IntPoint("ints", 2));
  doc.add(new IntPoint("ints", 1));
  doc.add(new LongPoint("longs", 3L));
  doc.add(new LongPoint("longs", 2L));
  doc.add(new LongPoint("longs", 1L));
  doc.add(new FloatPoint("floats", 3F));
  doc.add(new FloatPoint("floats", 2F));
  doc.add(new FloatPoint("floats", 1F));
  doc.add(new DoublePoint("doubles", 3D));
  doc.add(new DoublePoint("doubles", 2D));
  doc.add(new DoublePoint("doubles", 1D));

  MemoryIndex mi = MemoryIndex.fromDocument(doc, analyzer);
  IndexSearcher s = mi.createSearcher();

  assertEquals(1, s.count(IntPoint.newSetQuery("ints", 2)));
  assertEquals(1, s.count(LongPoint.newSetQuery("longs", 2)));
  assertEquals(1, s.count(FloatPoint.newSetQuery("floats", 2)));
  assertEquals(1, s.count(DoublePoint.newSetQuery("doubles", 2)));
}
 
Example #14
Source File: TestMemoryIndex.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void test2DPoints() throws Exception {
  Document doc = new Document();
  doc.add(new IntPoint("ints", 0, -100));
  doc.add(new IntPoint("ints", 20, 20));
  doc.add(new IntPoint("ints", 100, -100));
  doc.add(new LongPoint("longs", 0L, -100L));
  doc.add(new LongPoint("longs", 20L, 20L));
  doc.add(new LongPoint("longs", 100L, -100L));
  doc.add(new FloatPoint("floats", 0F, -100F));
  doc.add(new FloatPoint("floats", 20F, 20F));
  doc.add(new FloatPoint("floats", 100F, -100F));
  doc.add(new DoublePoint("doubles", 0D, -100D));
  doc.add(new DoublePoint("doubles", 20D, 20D));
  doc.add(new DoublePoint("doubles", 100D, -100D));

  MemoryIndex mi = MemoryIndex.fromDocument(doc, analyzer);
  IndexSearcher s = mi.createSearcher();

  assertEquals(1, s.count(IntPoint.newRangeQuery("ints", new int[] {10, 10}, new int[] {30, 30})));
  assertEquals(1, s.count(LongPoint.newRangeQuery("longs", new long[] {10L, 10L}, new long[] {30L, 30L})));
  assertEquals(1, s.count(FloatPoint.newRangeQuery("floats", new float[] {10F, 10F}, new float[] {30F, 30F})));
  assertEquals(1, s.count(DoublePoint.newRangeQuery("doubles", new double[] {10D, 10D}, new double[] {30D, 30D})));
}
 
Example #15
Source File: LuceneQueryVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Query createDoubleRangeQuery(final String name, final Object value,
        final ConditionType type, final boolean minInclusive, final boolean maxInclusive) {
    final Double doubleValue = Double.valueOf(value.toString());
    Double min = getMin(type, doubleValue);
    if (min == null) {
        min = Double.NEGATIVE_INFINITY;
    } else if (!minInclusive) {
        min = Math.nextUp(min);
    }

    Double max = getMax(type, doubleValue);
    if (max == null) {
        max = Double.POSITIVE_INFINITY;
    } else if (!maxInclusive) {
        max = Math.nextDown(max);
    }
    return DoublePoint.newRangeQuery(name, min, max);
}
 
Example #16
Source File: SimpleDocumentWriter.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
private void addToDoc(IndexKey key, Double value){
  Preconditions.checkArgument(key.getValueType() == Double.class);
  if(value == null){
    return;
  }

  checkIfMultiValueField(key);

  final String indexFieldName = key.getIndexFieldName();
  doc.add(new DoublePoint(indexFieldName, value));
  if (key.isStored()) {
    doc.add(new StoredField(indexFieldName, value));
  }
  if (key.isSorted()) {
    Preconditions.checkArgument(key.getSortedValueType() == SearchFieldSorting.FieldType.DOUBLE);
    doc.add(new DoubleDocValuesField(indexFieldName, value));
  }
}
 
Example #17
Source File: NumberIndexConverter.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<IndexableField> convert(LuceneContext context, String path, Field field, LuceneIndex annotation, Type type, Object data) {
    Collection<IndexableField> indexables = new LinkedList<>();
    Class<?> clazz = TypeUtility.getRawType(type, null);
    clazz = ClassUtility.primitiveToWrapper(clazz);
    if (Byte.class.isAssignableFrom(clazz)) {
        indexables.add(new IntPoint(path, (byte) data));
        return indexables;
    }
    if (Short.class.isAssignableFrom(clazz)) {
        indexables.add(new IntPoint(path, (short) data));
        return indexables;
    }
    if (Integer.class.isAssignableFrom(clazz)) {
        indexables.add(new IntPoint(path, (int) data));
        return indexables;
    }
    if (Long.class.isAssignableFrom(clazz)) {
        indexables.add(new LongPoint(path, (long) data));
        return indexables;
    }
    if (Float.class.isAssignableFrom(clazz)) {
        indexables.add(new FloatPoint(path, (float) data));
        return indexables;
    }
    if (Double.class.isAssignableFrom(clazz)) {
        indexables.add(new DoublePoint(path, (double) data));
        return indexables;
    }
    throw new StorageException();
}
 
Example #18
Source File: DoubleRangeGroupSelectorTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected Query filterQuery(DoubleRange groupValue) {
  if (groupValue == null) {
    return new BooleanQuery.Builder()
        .add(new MatchAllDocsQuery(), BooleanClause.Occur.FILTER)
        .add(new DocValuesFieldExistsQuery("double"), BooleanClause.Occur.MUST_NOT)
        .build();
  }
  return DoublePoint.newRangeQuery("double", groupValue.min, Math.nextDown(groupValue.max));
}
 
Example #19
Source File: TestPointQueries.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testPointInSetEquals() {
  Query q1, q2;
  q1 = IntPoint.newSetQuery("a", 0, 1000, 17);
  q2 = IntPoint.newSetQuery("a", 17, 0, 1000);
  assertEquals(q1, q2);
  assertEquals(q1.hashCode(), q2.hashCode());
  assertFalse(q1.equals(IntPoint.newSetQuery("a", 1, 17, 1000)));
  assertFalse(q1.equals(IntPoint.newSetQuery("b", 0, 1000, 17)));

  q1 = LongPoint.newSetQuery("a", 0, 1000, 17);
  q2 = LongPoint.newSetQuery("a", 17, 0, 1000);
  assertEquals(q1, q2);
  assertEquals(q1.hashCode(), q2.hashCode());
  assertFalse(q1.equals(LongPoint.newSetQuery("a", 1, 17, 1000)));

  q1 = FloatPoint.newSetQuery("a", 0, 1000, 17);
  q2 = FloatPoint.newSetQuery("a", 17, 0, 1000);
  assertEquals(q1, q2);
  assertEquals(q1.hashCode(), q2.hashCode());
  assertFalse(q1.equals(FloatPoint.newSetQuery("a", 1, 17, 1000)));

  q1 = DoublePoint.newSetQuery("a", 0, 1000, 17);
  q2 = DoublePoint.newSetQuery("a", 17, 0, 1000);
  assertEquals(q1, q2);
  assertEquals(q1.hashCode(), q2.hashCode());
  assertFalse(q1.equals(DoublePoint.newSetQuery("a", 1, 17, 1000)));

  byte[] zeros = new byte[5];
  byte[] ones = new byte[5];
  Arrays.fill(ones, (byte) 0xff);
  q1 = BinaryPoint.newSetQuery("a", new byte[][] {zeros, ones});
  q2 = BinaryPoint.newSetQuery("a", new byte[][] {zeros, ones});
  assertEquals(q1, q2);
  assertEquals(q1.hashCode(), q2.hashCode());
  byte[] other = ones.clone();
  other[2] = (byte) 5;
  assertFalse(q1.equals(BinaryPoint.newSetQuery("a", new byte[][] {zeros, other})));
}
 
Example #20
Source File: TestPointQueries.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testPointRangeEquals() {
  Query q1, q2;

  q1 = IntPoint.newRangeQuery("a", 0, 1000);
  q2 = IntPoint.newRangeQuery("a", 0, 1000);
  assertEquals(q1, q2);
  assertEquals(q1.hashCode(), q2.hashCode());
  assertFalse(q1.equals(IntPoint.newRangeQuery("a", 1, 1000)));
  assertFalse(q1.equals(IntPoint.newRangeQuery("b", 0, 1000)));

  q1 = LongPoint.newRangeQuery("a", 0, 1000);
  q2 = LongPoint.newRangeQuery("a", 0, 1000);
  assertEquals(q1, q2);
  assertEquals(q1.hashCode(), q2.hashCode());
  assertFalse(q1.equals(LongPoint.newRangeQuery("a", 1, 1000)));

  q1 = FloatPoint.newRangeQuery("a", 0, 1000);
  q2 = FloatPoint.newRangeQuery("a", 0, 1000);
  assertEquals(q1, q2);
  assertEquals(q1.hashCode(), q2.hashCode());
  assertFalse(q1.equals(FloatPoint.newRangeQuery("a", 1, 1000)));

  q1 = DoublePoint.newRangeQuery("a", 0, 1000);
  q2 = DoublePoint.newRangeQuery("a", 0, 1000);
  assertEquals(q1, q2);
  assertEquals(q1.hashCode(), q2.hashCode());
  assertFalse(q1.equals(DoublePoint.newRangeQuery("a", 1, 1000)));

  byte[] zeros = new byte[5];
  byte[] ones = new byte[5];
  Arrays.fill(ones, (byte) 0xff);
  q1 = BinaryPoint.newRangeQuery("a", new byte[][] {zeros}, new byte[][] {ones});
  q2 = BinaryPoint.newRangeQuery("a", new byte[][] {zeros}, new byte[][] {ones});
  assertEquals(q1, q2);
  assertEquals(q1.hashCode(), q2.hashCode());
  byte[] other = ones.clone();
  other[2] = (byte) 5;
  assertFalse(q1.equals(BinaryPoint.newRangeQuery("a", new byte[][] {zeros}, new byte[][] {other})));
}
 
Example #21
Source File: TestPointQueries.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** Boxed methods for primitive types should behave the same as unboxed: just sugar */
public void testPointIntSetBoxed() throws Exception {
  assertEquals(IntPoint.newSetQuery("foo", 1, 2, 3), IntPoint.newSetQuery("foo", Arrays.asList(1, 2, 3)));
  assertEquals(FloatPoint.newSetQuery("foo", 1F, 2F, 3F), FloatPoint.newSetQuery("foo", Arrays.asList(1F, 2F, 3F)));
  assertEquals(LongPoint.newSetQuery("foo", 1L, 2L, 3L), LongPoint.newSetQuery("foo", Arrays.asList(1L, 2L, 3L)));
  assertEquals(DoublePoint.newSetQuery("foo", 1D, 2D, 3D), DoublePoint.newSetQuery("foo", Arrays.asList(1D, 2D, 3D)));
}
 
Example #22
Source File: TestPointQueries.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testNextUp() {
  assertTrue(Double.compare(0d, DoublePoint.nextUp(-0d)) == 0);
  assertTrue(Double.compare(Double.MIN_VALUE, DoublePoint.nextUp(0d)) == 0);
  assertTrue(Double.compare(Double.POSITIVE_INFINITY, DoublePoint.nextUp(Double.MAX_VALUE)) == 0);
  assertTrue(Double.compare(Double.POSITIVE_INFINITY, DoublePoint.nextUp(Double.POSITIVE_INFINITY)) == 0);
  assertTrue(Double.compare(-Double.MAX_VALUE, DoublePoint.nextUp(Double.NEGATIVE_INFINITY)) == 0);

  assertTrue(Float.compare(0f, FloatPoint.nextUp(-0f)) == 0);
  assertTrue(Float.compare(Float.MIN_VALUE, FloatPoint.nextUp(0f)) == 0);
  assertTrue(Float.compare(Float.POSITIVE_INFINITY, FloatPoint.nextUp(Float.MAX_VALUE)) == 0);
  assertTrue(Float.compare(Float.POSITIVE_INFINITY, FloatPoint.nextUp(Float.POSITIVE_INFINITY)) == 0);
  assertTrue(Float.compare(-Float.MAX_VALUE, FloatPoint.nextUp(Float.NEGATIVE_INFINITY)) == 0);
}
 
Example #23
Source File: TestPointQueries.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testNextDown() {
  assertTrue(Double.compare(-0d, DoublePoint.nextDown(0d)) == 0);
  assertTrue(Double.compare(-Double.MIN_VALUE, DoublePoint.nextDown(-0d)) == 0);
  assertTrue(Double.compare(Double.NEGATIVE_INFINITY, DoublePoint.nextDown(-Double.MAX_VALUE)) == 0);
  assertTrue(Double.compare(Double.NEGATIVE_INFINITY, DoublePoint.nextDown(Double.NEGATIVE_INFINITY)) == 0);
  assertTrue(Double.compare(Double.MAX_VALUE, DoublePoint.nextDown(Double.POSITIVE_INFINITY)) == 0);

  assertTrue(Float.compare(-0f, FloatPoint.nextDown(0f)) == 0);
  assertTrue(Float.compare(-Float.MIN_VALUE, FloatPoint.nextDown(-0f)) == 0);
  assertTrue(Float.compare(Float.NEGATIVE_INFINITY, FloatPoint.nextDown(-Float.MAX_VALUE)) == 0);
  assertTrue(Float.compare(Float.NEGATIVE_INFINITY, FloatPoint.nextDown(Float.NEGATIVE_INFINITY)) == 0);
  assertTrue(Float.compare(Float.MAX_VALUE, FloatPoint.nextDown(Float.POSITIVE_INFINITY)) == 0);
}
 
Example #24
Source File: TestPointValues.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testInvalidDoublePointUsage() throws Exception {
  DoublePoint field = new DoublePoint("field", 17, 42);

  expectThrows(IllegalArgumentException.class, () -> {
    field.setDoubleValue(14);
  });

  expectThrows(IllegalStateException.class, () -> {
    field.numericValue();
  });
}
 
Example #25
Source File: BBoxStrategy.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private Query makeNumberTermQuery(String field, double number) {
  if (hasPointVals) {
    return DoublePoint.newExactQuery(field, number);
  } else if (legacyNumericFieldType != null) {
    BytesRefBuilder bytes = new BytesRefBuilder();
    LegacyNumericUtils.longToPrefixCoded(NumericUtils.doubleToSortableLong(number), 0, bytes);
    return new TermQuery(new Term(field, bytes.get()));
  }
  throw new UnsupportedOperationException("An index is required for this operation.");
}
 
Example #26
Source File: PointMerger.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
  double v = DoublePoint.decodeDimension(maxPackedValue, 0);
  if (v >= last) {
    return PointValues.Relation.CELL_CROSSES_QUERY;
  } else {
    return PointValues.Relation.CELL_OUTSIDE_QUERY;
  }
}
 
Example #27
Source File: TestPointFields.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testWhiteboxCreateFields() throws Exception {
  String[] typeNames = new String[]{"i", "l", "f", "d", "dt"};
  @SuppressWarnings({"rawtypes"})
  Class<?>[] expectedClasses = new Class[]{IntPoint.class, LongPoint.class, FloatPoint.class, DoublePoint.class, LongPoint.class};
  
  Date dateToTest = new Date();
  Object[][] values = new Object[][] {
    {42, "42"},
    {42, "42"},
    {42.123, "42.123"},
    {12345.6789, "12345.6789"},
    {dateToTest, new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT).format(dateToTest), "NOW"} // "NOW" won't be equal to the other dates
  };
  
  Set<String> typesTested = new HashSet<>();
  for (int i = 0; i < typeNames.length; i++) {
    for (String suffix:FIELD_SUFFIXES) {
      doWhiteboxCreateFields("whitebox_p_" + typeNames[i] + suffix, expectedClasses[i], values[i]);
      typesTested.add("*_p_" + typeNames[i] + suffix);
    }
  }
  Set<String> typesToTest = new HashSet<>();
  for (DynamicField dynField:h.getCore().getLatestSchema().getDynamicFields()) {
    if (dynField.getPrototype().getType() instanceof PointField) {
      typesToTest.add(dynField.getRegex());
    }
  }
  assertEquals("Missing types in the test", typesTested, typesToTest);
}
 
Example #28
Source File: DoubleQuery.java    From HongsCORE with MIT License 5 votes vote down vote up
@Override
public Query whr(String k, Object v) {
    if (v == null) {
        throw new NullPointerException("Query for "+k+" must be number, but null");
    }
    double  n2 = Synt.asDouble(v);
    Query   q2 = DoublePoint.newExactQuery("@"+k, n2);
    return  q2;
}
 
Example #29
Source File: NumberFieldMapper.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public Query termsQuery(String field, List<Object> values) {
    double[] v = new double[values.size()];
    for (int i = 0; i < values.size(); ++i) {
        v[i] = parse(values.get(i), false);
    }
    return DoublePoint.newSetQuery(field, v);
}
 
Example #30
Source File: NumberFieldMapper.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public Query rangeQuery(String field, Object lowerTerm, Object upperTerm,
                 boolean includeLower, boolean includeUpper,
                 boolean hasDocValues) {
    double l = Double.NEGATIVE_INFINITY;
    double u = Double.POSITIVE_INFINITY;
    if (lowerTerm != null) {
        l = parse(lowerTerm, false);
        if (includeLower == false) {
            l = DoublePoint.nextUp(l);
        }
    }
    if (upperTerm != null) {
        u = parse(upperTerm, false);
        if (includeUpper == false) {
            u = DoublePoint.nextDown(u);
        }
    }
    Query query = DoublePoint.newRangeQuery(field, l, u);
    if (hasDocValues) {
        Query dvQuery = SortedNumericDocValuesField.newSlowRangeQuery(field,
                NumericUtils.doubleToSortableLong(l),
                NumericUtils.doubleToSortableLong(u));
        query = new IndexOrDocValuesQuery(query, dvQuery);
    }
    return query;
}