Java Code Examples for org.apache.lucene.document.DoublePoint

The following examples show how to use org.apache.lucene.document.DoublePoint. These examples are extracted from open source projects. 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 Project: dremio-oss   Source File: SimpleDocumentWriter.java    License: 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 2
Source Project: lucene-solr   Source File: TestMemoryIndex.java    License: 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 3
Source Project: lucene-solr   Source File: TestMemoryIndex.java    License: 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 4
Source Project: lucene-solr   Source File: BBoxStrategy.java    License: 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 5
Source Project: lucene-solr   Source File: PointVectorStrategy.java    License: 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 6
Source Project: lucene-solr   Source File: TestPointQueries.java    License: 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 7
Source Project: lucene-solr   Source File: TestPointQueries.java    License: 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 8
Source Project: lucene-solr   Source File: TestPointQueries.java    License: 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 9
Source Project: lucene-solr   Source File: PointVectorStrategy.java    License: 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 10
Source Project: lucene-solr   Source File: BBoxStrategy.java    License: 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 11
Source Project: lucene-solr   Source File: PointMerger.java    License: 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 12
Source Project: lucene-solr   Source File: NumericFieldType.java    License: 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 13
Source Project: lucene-solr   Source File: DoublePointField.java    License: 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 14
Source Project: HongsCORE   Source File: DoubleQuery.java    License: 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 15
Source Project: cxf   Source File: LuceneQueryVisitor.java    License: 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 Project: crate   Source File: NumberFieldMapper.java    License: 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 17
Source Project: jstarcraft-core   Source File: NumberIndexConverter.java    License: 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 Project: dremio-oss   Source File: LuceneQueryConverter.java    License: Apache License 2.0 5 votes vote down vote up
private Query toRangeQuery(RangeDouble range) {
  return DoublePoint.newRangeQuery(
      range.getField(),
      range.hasMin() ?
        range.getMinInclusive() ? range.getMin()
        : Math.nextUp(range.getMin())
      : Double.NEGATIVE_INFINITY,
      range.hasMax() ?
        range.getMaxInclusive() ? range.getMax()
        : Math.nextAfter(range.getMax(), -Double.MAX_VALUE)
      : Double.POSITIVE_INFINITY );
}
 
Example 19
Source Project: lucene-solr   Source File: DoubleRangeGroupSelectorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void addGroupField(Document document, int id) {
  if (rarely()) {
    return;   // missing value
  }
  // numbers between 0 and 1000, groups are 100 wide from 100 to 900
  double value = random().nextDouble() * 1000;
  document.add(new DoublePoint("double", value));
  document.add(new NumericDocValuesField("double", Double.doubleToLongBits(value)));
}
 
Example 20
Source Project: lucene-solr   Source File: DoubleRangeGroupSelectorTest.java    License: 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 21
Source Project: lucene-solr   Source File: TestJoinUtil.java    License: Apache License 2.0 5 votes vote down vote up
private void addLinkFields(final Random random, Document document, final String fieldName, String linkValue,
    boolean multipleValuesPerDocument, boolean globalOrdinalJoin) {
  document.add(newTextField(random, fieldName, linkValue, Field.Store.NO));

  final int linkInt = Integer.parseUnsignedInt(linkValue,16);
  document.add(new IntPoint(fieldName + "INT", linkInt));
  document.add(new FloatPoint(fieldName + "FLOAT", linkInt));

  final long linkLong = linkInt<<32 | linkInt;
  document.add(new LongPoint(fieldName + "LONG", linkLong));
  document.add(new DoublePoint(fieldName + "DOUBLE", linkLong));

  if (multipleValuesPerDocument) {
    document.add(new SortedSetDocValuesField(fieldName, new BytesRef(linkValue)));
    document.add(new SortedNumericDocValuesField(fieldName+ "INT", linkInt));
    document.add(new SortedNumericDocValuesField(fieldName+ "FLOAT", Float.floatToRawIntBits(linkInt)));
    document.add(new SortedNumericDocValuesField(fieldName+ "LONG", linkLong));
    document.add(new SortedNumericDocValuesField(fieldName+ "DOUBLE", Double.doubleToRawLongBits(linkLong)));
  } else {
    document.add(new SortedDocValuesField(fieldName, new BytesRef(linkValue)));
    document.add(new NumericDocValuesField(fieldName+ "INT", linkInt));
    document.add(new FloatDocValuesField(fieldName+ "FLOAT", linkInt));
    document.add(new NumericDocValuesField(fieldName+ "LONG", linkLong));
    document.add(new DoubleDocValuesField(fieldName+ "DOUBLE", linkLong));
  }
  if (globalOrdinalJoin) {
    document.add(new SortedDocValuesField("join_field", new BytesRef(linkValue)));
  }
}
 
Example 22
Source Project: lucene-solr   Source File: TestMultiRangeQueries.java    License: Apache License 2.0 5 votes vote down vote up
public void testDoubleRandomMultiRangeQuery() throws IOException {
  final int numDims = TestUtil.nextInt(random(), 1, 3);
  final int numVals = TestUtil.nextInt(random(), 3, 8);
  Directory dir = newDirectory();
  RandomIndexWriter w = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  double[] value = new double[numDims];
  for (int i = 0; i < numDims; ++i) {
    value[i] = TestUtil.nextInt(random(), 1, 10);
  }
  doc.add(new DoublePoint("point", value));
  w.addDocument(doc);
  IndexReader reader = w.getReader();
  IndexSearcher searcher = new IndexSearcher(reader);
  searcher.setQueryCache(null);
  DoublePointMultiRangeBuilder builder = new DoublePointMultiRangeBuilder("point", numDims);
  for (int j = 0;j < numVals; j++) {
    double[] lowerBound = new double[numDims];
    double[] upperBound = new double[numDims];
    for (int i = 0; i < numDims; ++i) {
      lowerBound[i] = value[i] - random().nextInt(1);
      upperBound[i] = value[i] + random().nextInt(1);
    }
    builder.add(lowerBound, upperBound);
  }

  Query query = builder.build();
  searcher.search(query, Integer.MAX_VALUE);

  reader.close();
  w.close();
  dir.close();
}
 
Example 23
Source Project: lucene-solr   Source File: PointRangeQueryBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Query getQuery(Element e) throws ParserException {
  String field = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
  final String lowerTerm = DOMUtils.getAttribute(e, "lowerTerm", null);
  final String upperTerm = DOMUtils.getAttribute(e, "upperTerm", null);

  String type = DOMUtils.getAttribute(e, "type", "int");
  try {
    if (type.equalsIgnoreCase("int")) {
      return IntPoint.newRangeQuery(field,
          (lowerTerm == null ? Integer.MIN_VALUE : Integer.parseInt(lowerTerm)),
          (upperTerm == null ? Integer.MAX_VALUE : Integer.parseInt(upperTerm)));
    } else if (type.equalsIgnoreCase("long")) {
      return LongPoint.newRangeQuery(field,
          (lowerTerm == null ? Long.MIN_VALUE : Long.parseLong(lowerTerm)),
          (upperTerm == null ? Long.MAX_VALUE : Long.parseLong(upperTerm)));
    } else if (type.equalsIgnoreCase("double")) {
      return DoublePoint.newRangeQuery(field,
          (lowerTerm == null ? Double.NEGATIVE_INFINITY : Double.parseDouble(lowerTerm)),
          (upperTerm == null ? Double.POSITIVE_INFINITY : Double.parseDouble(upperTerm)));
    } else if (type.equalsIgnoreCase("float")) {
      return FloatPoint.newRangeQuery(field,
          (lowerTerm == null ? Float.NEGATIVE_INFINITY : Float.parseFloat(lowerTerm)),
          (upperTerm == null ? Float.POSITIVE_INFINITY : Float.parseFloat(upperTerm)));
    } else {
      throw new ParserException("type attribute must be one of: [long, int, double, float]");
    }
  } catch (NumberFormatException nfe) {
    throw new ParserException("Could not parse lowerTerm or upperTerm into a number", nfe);
  }
}
 
Example 24
Source Project: lucene-solr   Source File: TestPointQueryParser.java    License: Apache License 2.0 5 votes vote down vote up
public void testDoubles() throws Exception {
  StandardQueryParser parser = new StandardQueryParser();
  Map<String,PointsConfig> pointsConfig = new HashMap<>();
  pointsConfig.put("doubleField", new PointsConfig(NumberFormat.getNumberInstance(Locale.ROOT), Double.class));
  parser.setPointsConfigMap(pointsConfig);
  
  assertEquals(DoublePoint.newRangeQuery("doubleField", 1.5D, 3.6D),
               parser.parse("doubleField:[1.5 TO 3.6]", "body"));
  assertEquals(DoublePoint.newRangeQuery("doubleField", 1.5D, 1.5D),
               parser.parse("doubleField:1.5", "body"));
}
 
Example 25
Source Project: lucene-solr   Source File: TestPointQueries.java    License: 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 26
Source Project: lucene-solr   Source File: TestPointQueries.java    License: 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 27
Source Project: lucene-solr   Source File: TestPointQueries.java    License: 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 28
Source Project: lucene-solr   Source File: TestPointQueries.java    License: 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 29
Source Project: lucene-solr   Source File: TestPointQueries.java    License: 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 30
Source Project: lucene-solr   Source File: TestPointValues.java    License: 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();
  });
}