Java Code Examples for org.apache.lucene.document.DoublePoint#newExactQuery()

The following examples show how to use org.apache.lucene.document.DoublePoint#newExactQuery() . 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: 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 2
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 3
Source File: TestMemoryIndexAgainstDirectory.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void testPointValuesMemoryIndexVsNormalIndex() throws Exception {
  int size = atLeast(12);

  List<Integer> randomValues = new ArrayList<>();

  Document doc = new Document();
  for (Integer randomInteger : random().ints(size).toArray()) {
    doc.add(new IntPoint("int", randomInteger));
    randomValues.add(randomInteger);
    doc.add(new LongPoint("long", randomInteger));
    doc.add(new FloatPoint("float", randomInteger));
    doc.add(new DoublePoint("double", randomInteger));
  }

  MockAnalyzer mockAnalyzer = new MockAnalyzer(random());
  MemoryIndex memoryIndex = MemoryIndex.fromDocument(doc, mockAnalyzer);
  IndexSearcher memoryIndexSearcher = memoryIndex.createSearcher();

  Directory dir = newDirectory();
  IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random(), mockAnalyzer));
  writer.addDocument(doc);
  writer.close();
  IndexReader controlIndexReader = DirectoryReader.open(dir);
  IndexSearcher controlIndexSearcher = new IndexSearcher(controlIndexReader);

  Supplier<Integer> valueSupplier = () -> randomValues.get(random().nextInt(randomValues.size()));
  Query[] queries = new Query[] {
      IntPoint.newExactQuery("int", valueSupplier.get()),
      LongPoint.newExactQuery("long", valueSupplier.get()),
      FloatPoint.newExactQuery("float", valueSupplier.get()),
      DoublePoint.newExactQuery("double", valueSupplier.get()),
      IntPoint.newSetQuery("int", valueSupplier.get(), valueSupplier.get()),
      LongPoint.newSetQuery("long", valueSupplier.get(), valueSupplier.get()),
      FloatPoint.newSetQuery("float", valueSupplier.get(), valueSupplier.get()),
      DoublePoint.newSetQuery("double", valueSupplier.get(), valueSupplier.get()),
      IntPoint.newRangeQuery("int", valueSupplier.get(), valueSupplier.get()),
      LongPoint.newRangeQuery("long", valueSupplier.get(), valueSupplier.get()),
      FloatPoint.newRangeQuery("float", valueSupplier.get(), valueSupplier.get()),
      DoublePoint.newRangeQuery("double", valueSupplier.get(), valueSupplier.get())
  };
  for (Query query : queries) {
    assertEquals(controlIndexSearcher.count(query), controlIndexSearcher.count(query));
  }

  memoryIndexSearcher.getIndexReader().close();
  controlIndexReader.close();
  dir.close();
}
 
Example 4
Source File: BBoxStrategy.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private Query makeNumberTermQuery(String field, double number) {
  if (hasPointVals) {
    return DoublePoint.newExactQuery(field, number);
  }
  throw new UnsupportedOperationException("An index is required for this operation.");
}
 
Example 5
Source File: TestPointQueries.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void testPointExactEquals() {
  Query q1, q2;

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

  assertTrue(q1 instanceof PointRangeQuery && q2 instanceof PointRangeQuery);
  PointRangeQuery pq1 = (PointRangeQuery) q1;
  PointRangeQuery pq2 = (PointRangeQuery) q2;

  assertTrue(Arrays.equals(pq1.getLowerPoint(), pq2.getLowerPoint()));
  assertTrue(Arrays.equals(pq1.getUpperPoint(), pq2.getUpperPoint()));

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

  assertTrue(q1 instanceof PointRangeQuery && q2 instanceof PointRangeQuery);
  pq1 = (PointRangeQuery) q1;
  pq2 = (PointRangeQuery) q2;

  assertTrue(Arrays.equals(pq1.getLowerPoint(), pq2.getLowerPoint()));
  assertTrue(Arrays.equals(pq1.getUpperPoint(), pq2.getUpperPoint()));

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

  assertTrue(q1 instanceof PointRangeQuery && q2 instanceof PointRangeQuery);
  pq1 = (PointRangeQuery) q1;
  pq2 = (PointRangeQuery) q2;

  assertTrue(Arrays.equals(pq1.getLowerPoint(), pq2.getLowerPoint()));
  assertTrue(Arrays.equals(pq1.getUpperPoint(), pq2.getUpperPoint()));

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

  assertTrue(q1 instanceof PointRangeQuery && q2 instanceof PointRangeQuery);
  pq1 = (PointRangeQuery) q1;
  pq2 = (PointRangeQuery) q2;

  assertTrue(Arrays.equals(pq1.getLowerPoint(), pq2.getLowerPoint()));
  assertTrue(Arrays.equals(pq1.getUpperPoint(), pq2.getUpperPoint()));

  byte[] ones = new byte[5];
  Arrays.fill(ones, (byte) 0xff);
  q1 = BinaryPoint.newExactQuery("a", ones);
  q2 = BinaryPoint.newExactQuery("a", ones);
  assertEquals(q1, q2);
  assertEquals(q1.hashCode(), q2.hashCode());
  byte[] other = ones.clone();
  other[2] = (byte) 5;
  assertFalse(q1.equals(BinaryPoint.newExactQuery("a", other)));

  assertTrue(q1 instanceof PointRangeQuery && q2 instanceof PointRangeQuery);
  pq1 = (PointRangeQuery) q1;
  pq2 = (PointRangeQuery) q2;

  assertTrue(Arrays.equals(pq1.getLowerPoint(), pq2.getLowerPoint()));
  assertTrue(Arrays.equals(pq1.getUpperPoint(), pq2.getUpperPoint()));
}
 
Example 6
Source File: DoublePointField.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
protected Query getExactQuery(SchemaField field, String externalVal) {
  return DoublePoint.newExactQuery(field.getName(), parseDoubleFromUser(field.getName(), externalVal));
}
 
Example 7
Source File: NumberFieldMapper.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public Query termQuery(String field, Object value) {
    double v = parse(value, false);
    return DoublePoint.newExactQuery(field, v);
}