Java Code Examples for org.apache.lucene.document.LongPoint#newExactQuery()
The following examples show how to use
org.apache.lucene.document.LongPoint#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: LongQuery.java From HongsCORE with MIT License | 5 votes |
@Override public Query whr(String k, Object v) { if (v == null) { throw new NullPointerException("Query for "+k+" must be number, but null"); } long n2 = Synt.asLong(v); Query q2 = LongPoint.newExactQuery("@"+k, n2); return q2; }
Example 2
Source File: NumberFieldMapper.java From crate with Apache License 2.0 | 5 votes |
@Override public Query termQuery(String field, Object value) { if (hasDecimalPart(value)) { return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part"); } long v = parse(value, true); return LongPoint.newExactQuery(field, v); }
Example 3
Source File: TestMemoryIndexAgainstDirectory.java From lucene-solr with Apache License 2.0 | 4 votes |
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: TestPointQueries.java From lucene-solr with Apache License 2.0 | 4 votes |
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 5
Source File: DatePointField.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override protected Query getExactQuery(SchemaField field, String externalVal) { return LongPoint.newExactQuery(field.getName(), DateMathParser.parseMath(null, externalVal).getTime()); }
Example 6
Source File: LongPointField.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override protected Query getExactQuery(SchemaField field, String externalVal) { return LongPoint.newExactQuery(field.getName(), parseLongFromUser(field.getName(), externalVal)); }
Example 7
Source File: SeqNoFieldMapper.java From crate with Apache License 2.0 | 4 votes |
@Override public Query termQuery(Object value, @Nullable QueryShardContext context) { long v = parse(value); return LongPoint.newExactQuery(name(), v); }
Example 8
Source File: AbstractSearchQueryBuilderImpl.java From yes-cart with Apache License 2.0 | 2 votes |
/** * Create range query. * * @param field field name * @param value value * * @return range query */ protected Query createNumericQuery(final String field, final long value) { return LongPoint.newExactQuery(field, value); }