Java Code Examples for org.apache.lucene.document.DoublePoint#newRangeQuery()
The following examples show how to use
org.apache.lucene.document.DoublePoint#newRangeQuery() .
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 | 6 votes |
/** * 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 2
Source File: PointVectorStrategy.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * 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 3
Source File: PointVectorStrategy.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * 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 |
/** * 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: DoublePointField.java From lucene-solr with Apache License 2.0 | 6 votes |
@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 6
Source File: DoubleQuery.java From HongsCORE with MIT License | 6 votes |
@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 7
Source File: LuceneQueryVisitor.java From cxf with Apache License 2.0 | 6 votes |
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 8
Source File: LuceneQueryConverter.java From dremio-oss with Apache License 2.0 | 5 votes |
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 9
Source File: DoubleRangeGroupSelectorTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@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 10
Source File: PointRangeQueryBuilder.java From lucene-solr with Apache License 2.0 | 5 votes |
@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 11
Source File: TestPointQueries.java From lucene-solr with Apache License 2.0 | 5 votes |
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 12
Source File: NumberFieldMapper.java From crate with Apache License 2.0 | 5 votes |
@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; }
Example 13
Source File: APIStatisticDetailPage.java From fiery with Apache License 2.0 | 4 votes |
@RequestMapping(value = "/apistatisticdetail", method = RequestMethod.GET) public String currentlog(Model model, @RequestParam(value = "url", required = false, defaultValue = "") String keyword, @RequestParam(value = "topdatarange", required = false, defaultValue = "") String dataRange) { //date list List<String> timelist = DateTimeHelper.getDateTimeListForPage(fieryConfig.getKeepdataday()); model.addAttribute("datelist", timelist); model.addAttribute("datelist_selected", dataRange); //now the date render long shardtime = DateTimeHelper.getTimesMorning(DateTimeHelper.getBeforeDay(Integer.parseInt(dataRange))); ConcurrentHashMap<String, APIStatisticStruct> urllist = apiStatisticTimeSet.getDaySharder(shardtime, false); //data range Integer dataRangeInt = 0; if (dataRange.trim().length() == 0) { dataRange = "0"; } model.addAttribute("topdatarange", dataRange); try { dataRangeInt = Integer.parseInt(dataRange); } catch (Exception e) { e.printStackTrace(); log.error(e.getMessage()); return "apistatisticdetail"; } Long startRange = DateTimeHelper.getTimesMorning(DateTimeHelper.getCurrentTime()) - (dataRangeInt * 86400); TermQuery termQuery = new TermQuery(new Term("url", keyword.trim())); Query rangeQuery = DoublePoint.newRangeQuery("time", startRange, startRange + 86400); //rangeStart BooleanQuery query = new BooleanQuery.Builder() .add(termQuery, BooleanClause.Occur.MUST) .add(rangeQuery, BooleanClause.Occur.MUST) .build(); /* //term query String queryString = "url:\"" + keyword.trim() + "\" AND time_raw:[" + startRange + " TO " + (startRange + 86400) + "]"; log.info("queryString:" + queryString); Query query; QueryParser parser = new QueryParser("url,time_raw", new StandardAnalyzer()); try { query = parser.parse(queryString); } catch (Exception e) { e.printStackTrace(); log.error(e.getMessage()); return "apistatisticdetail"; } */ /* Query query; Term term = new Term("url", keyword.trim()); query = new TermQuery(term); */ Sort sort = new Sort(new SortField("elapsed_ms", SortField.Type.DOUBLE, true)); ResponseJson result = indexHelper.searchByQuery(startRange, query, 0, 1000, sort); model.addAttribute("resultlist", result.getResult()); model.addAttribute("url", keyword); return "apistatisticdetail"; }
Example 14
Source File: LuceneQueryConverter.java From dremio-oss with Apache License 2.0 | 4 votes |
private Query toTermDoubleQuery(SearchQuery.TermDouble term) { return DoublePoint.newRangeQuery( term.getField(), term.getValue(), term.getValue()); }
Example 15
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(); }