Java Code Examples for org.apache.lucene.document.LongPoint#newRangeQuery()

The following examples show how to use org.apache.lucene.document.LongPoint#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: SeqNoFieldMapper.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower,
                        boolean includeUpper, QueryShardContext context) {
    long l = Long.MIN_VALUE;
    long u = Long.MAX_VALUE;
    if (lowerTerm != null) {
        l = parse(lowerTerm);
        if (includeLower == false) {
            if (l == Long.MAX_VALUE) {
                return new MatchNoDocsQuery();
            }
            ++l;
        }
    }
    if (upperTerm != null) {
        u = parse(upperTerm);
        if (includeUpper == false) {
            if (u == Long.MIN_VALUE) {
                return new MatchNoDocsQuery();
            }
            --u;
        }
    }
    return LongPoint.newRangeQuery(name(), l, u);
}
 
Example 2
Source File: LuceneQueryVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Query createLongRangeQuery(final String name, final Object value,
        final ConditionType type, final boolean minInclusive, final boolean maxInclusive) {
    final Long longValue = Long.valueOf(value.toString());
    Long min = getMin(type, longValue);
    if (min == null) {
        min = Long.MIN_VALUE;
    } else if (!minInclusive) {
        min = Math.addExact(min, 1L);
    }

    Long max = getMax(type, longValue);
    if (max == null) {
        max = Long.MAX_VALUE;
    } else if (!maxInclusive) {
        max = Math.addExact(max, -1L);
    }
    return LongPoint.newRangeQuery(name, min, max);
}
 
Example 3
Source File: LongQuery.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");
    }
    long n2, x2;
    if (n == null || "".equals(n)) {
        n2 = Long.MIN_VALUE;
    } else {
        n2 = Synt.asLong(n);
        if (!l) {
            n2 = n2 + 1;
        }
    }
    if (x == null || "".equals(x)) {
        x2 = Long.MAX_VALUE;
    } else {
        x2 = Synt.asLong(x);
        if (!g) {
            x2 = x2 - 1;
        }
    }
    Query   q2 = LongPoint.newRangeQuery("@"+k, n2, x2);
    return  q2;
}
 
Example 4
Source File: LongPointField.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) {
  long actualMin, actualMax;
  if (min == null) {
    actualMin = Long.MIN_VALUE;
  } else {
    actualMin = parseLongFromUser(field.getName(), min);
    if (!minInclusive) {
      if (actualMin == Long.MAX_VALUE) return new MatchNoDocsQuery();
      actualMin++;
    }
  }
  if (max == null) {
    actualMax = Long.MAX_VALUE;
  } else {
    actualMax = parseLongFromUser(field.getName(), max);
    if (!maxInclusive) {
      if (actualMax == Long.MIN_VALUE) return new MatchNoDocsQuery();
      actualMax--;
    }
  }
  return LongPoint.newRangeQuery(field.getName(), actualMin, actualMax);
}
 
Example 5
Source File: DatePointField.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) {
  long actualMin, actualMax;
  if (min == null) {
    actualMin = Long.MIN_VALUE;
  } else {
    actualMin = DateMathParser.parseMath(null, min).getTime();
    if (!minInclusive) {
      if (actualMin == Long.MAX_VALUE) return new MatchNoDocsQuery();
      actualMin++;
    }
  }
  if (max == null) {
    actualMax = Long.MAX_VALUE;
  } else {
    actualMax = DateMathParser.parseMath(null, max).getTime();
    if (!maxInclusive) {
      if (actualMax == Long.MIN_VALUE) return new MatchNoDocsQuery();
      actualMax--;
    }
  }
  return LongPoint.newRangeQuery(field.getName(), actualMin, actualMax);
}
 
Example 6
Source File: DateFieldMapper.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public Query rangeQuery(Object lowerTerm,
                        Object upperTerm,
                        boolean includeLower,
                        boolean includeUpper,
                        ShapeRelation relation,
                        @Nullable DateTimeZone timeZone,
                        QueryShardContext context) {
    failIfNotIndexed();
    if (relation == ShapeRelation.DISJOINT) {
        throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() +
                "] does not support DISJOINT ranges");
    }
    long l, u;
    if (lowerTerm == null) {
        l = Long.MIN_VALUE;
    } else {
        l = (Long) lowerTerm;
        if (includeLower == false) {
            ++l;
        }
    }
    if (upperTerm == null) {
        u = Long.MAX_VALUE;
    } else {
        u = (Long) upperTerm;
        if (includeUpper == false) {
            --u;
        }
    }
    Query query = LongPoint.newRangeQuery(name(), l, u);
    if (hasDocValues()) {
        Query dvQuery = SortedNumericDocValuesField.newSlowRangeQuery(name(), l, u);
        query = new IndexOrDocValuesQuery(query, dvQuery);
    }
    return query;
}
 
Example 7
Source File: LuceneQueryConverter.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private Query toRangeQuery(RangeLong range) {
  return LongPoint.newRangeQuery(
      range.getField(),
      range.hasMin() ?
        range.getMinInclusive() ? range.getMin()
        : (range.getMin() + 1L)
      : -Long.MAX_VALUE,
      range.hasMax() ?
        range.getMaxInclusive() ? range.getMax()
        : (range.getMax() - 1L)
      : Long.MAX_VALUE );
}
 
Example 8
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) {
    long l = Long.MIN_VALUE;
    long u = Long.MAX_VALUE;
    if (lowerTerm != null) {
        l = parse(lowerTerm, true);
        // if the lower bound is decimal:
        // - if the bound is positive then we increment it:
        //      if lowerTerm=1.5 then the (inclusive) bound becomes 2
        // - if the bound is negative then we leave it as is:
        //      if lowerTerm=-1.5 then the (inclusive) bound becomes -1 due to the call to longValue
        boolean lowerTermHasDecimalPart = hasDecimalPart(lowerTerm);
        if ((lowerTermHasDecimalPart == false && includeLower == false) ||
                (lowerTermHasDecimalPart && signum(lowerTerm) > 0)) {
            if (l == Long.MAX_VALUE) {
                return new MatchNoDocsQuery();
            }
            ++l;
        }
    }
    if (upperTerm != null) {
        u = parse(upperTerm, true);
        boolean upperTermHasDecimalPart = hasDecimalPart(upperTerm);
        if ((upperTermHasDecimalPart == false && includeUpper == false) ||
                (upperTermHasDecimalPart && signum(upperTerm) < 0)) {
            if (u == Long.MIN_VALUE) {
                return new MatchNoDocsQuery();
            }
            --u;
        }
    }
    Query query = LongPoint.newRangeQuery(field, l, u);
    if (hasDocValues) {
        Query dvQuery = SortedNumericDocValuesField.newSlowRangeQuery(field, l, u);
        query = new IndexOrDocValuesQuery(query, dvQuery);
    }
    return query;
}
 
Example 9
Source File: LuceneChangesSnapshot.java    From crate with Apache License 2.0 5 votes vote down vote up
private TopDocs searchOperations(ScoreDoc after) throws IOException {
    final Query rangeQuery = LongPoint.newRangeQuery(SeqNoFieldMapper.NAME, Math.max(fromSeqNo, lastSeenSeqNo), toSeqNo);
    final Sort sortedBySeqNoThenByTerm = new Sort(
        new SortField(SeqNoFieldMapper.NAME, SortField.Type.LONG),
        new SortField(SeqNoFieldMapper.PRIMARY_TERM_NAME, SortField.Type.LONG, true)
    );
    return indexSearcher.searchAfter(after, rangeQuery, searchBatchSize, sortedBySeqNoThenByTerm);
}
 
Example 10
Source File: EventIndexTask.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Re-indexes the documents given. The IndexableDocument's provided are required to have the IndexDirectory provided.
 */
void reIndex(final List<IndexableDocument> toIndex, final CommitPreference commitPreference) throws IOException {
    if (toIndex.isEmpty()) {
        return;
    }

    final Map<File, List<IndexableDocument>> docsByIndexDir = toIndex.stream().collect(Collectors.groupingBy(IndexableDocument::getIndexDirectory));
    for (final Map.Entry<File, List<IndexableDocument>> entry : docsByIndexDir.entrySet()) {
        final File indexDirectory = entry.getKey();
        final List<IndexableDocument> documentsForIndex = entry.getValue();

        final EventIndexWriter indexWriter = indexManager.borrowIndexWriter(indexDirectory);
        try {
            // Remove any documents that already exist in this index that are overlapping.
            long minId = Long.MAX_VALUE;
            long maxId = Long.MIN_VALUE;

            for (final IndexableDocument doc : toIndex) {
                final long eventId = doc.getDocument().getField(SearchableFields.Identifier.getSearchableFieldName()).numericValue().longValue();
                if (eventId < minId) {
                    minId = eventId;
                }
                if (eventId > maxId) {
                    maxId = eventId;
                }
            }

            final Query query = LongPoint.newRangeQuery(SearchableFields.Identifier.getSearchableFieldName(), minId, maxId);
            indexWriter.getIndexWriter().deleteDocuments(query);

            final List<Document> documents = documentsForIndex.stream()
                .map(IndexableDocument::getDocument)
                .collect(Collectors.toList());

            indexWriter.index(documents, commitThreshold);
        } finally {
            indexManager.returnIndexWriter(indexWriter, CommitPreference.FORCE_COMMIT.equals(commitPreference), false);
        }
    }
}
 
Example 11
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 12
Source File: LongRangeGroupSelectorTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected Query filterQuery(LongRange groupValue) {
  if (groupValue == null) {
    return new BooleanQuery.Builder()
        .add(new MatchAllDocsQuery(), BooleanClause.Occur.FILTER)
        .add(new DocValuesFieldExistsQuery("long"), BooleanClause.Occur.MUST_NOT)
        .build();
  }
  return LongPoint.newRangeQuery("long", groupValue.min, groupValue.max - 1);
}
 
Example 13
Source File: TestLRUQueryCache.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void testSkipCachingForRangeQuery() throws IOException {
  Directory dir = newDirectory();
  final RandomIndexWriter w = new RandomIndexWriter(random(), dir);
  Document doc1 = new Document();
  doc1.add(new StringField("name", "tom", Store.YES));
  doc1.add(new LongPoint("age", 15));
  doc1.add(new SortedNumericDocValuesField("age", 15));
  Document doc2 = new Document();
  doc2.add(new StringField("name", "alice", Store.YES));
  doc2.add(new LongPoint("age", 20));
  doc2.add(new SortedNumericDocValuesField("age", 20));
  w.addDocuments(Arrays.asList(doc1, doc2));
  final IndexReader reader = w.getReader();
  final IndexSearcher searcher = newSearcher(reader);
  searcher.setQueryCachingPolicy(ALWAYS_CACHE);
  w.close();

  // lead cost is 1, cost of subQuery1 is 1, cost of subQuery2 is 2
  BooleanQuery.Builder bq = new BooleanQuery.Builder();
  TermQuery subQuery1 = new TermQuery(new Term("name", "tom"));
  IndexOrDocValuesQuery subQuery2 = new IndexOrDocValuesQuery(
      LongPoint.newRangeQuery("age", 10, 30),
      SortedNumericDocValuesField.newSlowRangeQuery("age", 10, 30));
  BooleanQuery query = bq.add(subQuery1, Occur.FILTER).add(subQuery2, Occur.FILTER).build();
  Set<Query> cacheSet = new HashSet<>();

  // only term query is cached
  final LRUQueryCache partCache = new LRUQueryCache(1000000, 10000000, context -> true, 1);
  searcher.setQueryCache(partCache);
  searcher.search(query, 1);
  cacheSet.add(subQuery1);
  assertEquals(cacheSet, new HashSet<>(partCache.cachedQueries()));

  // both queries are cached
  final LRUQueryCache allCache = new LRUQueryCache(1000000, 10000000, context -> true, Float.POSITIVE_INFINITY);
  searcher.setQueryCache(allCache);
  searcher.search(query, 1);
  cacheSet.add(subQuery2);
  assertEquals(cacheSet, new HashSet<>(allCache.cachedQueries()));

  reader.close();
  dir.close();
}
 
Example 14
Source File: TestDocValuesQueries.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private void doTestDuelPointRangeSortedRangeQuery(boolean sortedSet, int maxValuesPerDoc) throws IOException {
  final int iters = atLeast(10);
  for (int iter = 0; iter < iters; ++iter) {
    Directory dir = newDirectory();
    RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
    final int numDocs = atLeast(100);
    for (int i = 0; i < numDocs; ++i) {
      Document doc = new Document();
      final int numValues = TestUtil.nextInt(random(), 0, maxValuesPerDoc);
      for (int j = 0; j < numValues; ++j) {
        final long value = TestUtil.nextLong(random(), -100, 10000);
        byte[] encoded = new byte[Long.BYTES];
        LongPoint.encodeDimension(value, encoded, 0);
        if (sortedSet) {
          doc.add(new SortedSetDocValuesField("dv", new BytesRef(encoded)));
        } else {
          doc.add(new SortedDocValuesField("dv", new BytesRef(encoded)));
        }
        doc.add(new LongPoint("idx", value));
      }
      iw.addDocument(doc);
    }
    if (random().nextBoolean()) {
      iw.deleteDocuments(LongPoint.newRangeQuery("idx", 0L, 10L));
    }
    final IndexReader reader = iw.getReader();
    final IndexSearcher searcher = newSearcher(reader, false);
    iw.close();

    for (int i = 0; i < 100; ++i) {
      long min = random().nextBoolean() ? Long.MIN_VALUE : TestUtil.nextLong(random(), -100, 10000);
      long max = random().nextBoolean() ? Long.MAX_VALUE : TestUtil.nextLong(random(), -100, 10000);
      byte[] encodedMin = new byte[Long.BYTES];
      byte[] encodedMax = new byte[Long.BYTES];
      LongPoint.encodeDimension(min, encodedMin, 0);
      LongPoint.encodeDimension(max, encodedMax, 0);
      boolean includeMin = true;
      boolean includeMax = true;
      if (random().nextBoolean()) {
        includeMin = false;
        min++;
      }
      if (random().nextBoolean()) {
        includeMax = false;
        max--;
      }
      final Query q1 = LongPoint.newRangeQuery("idx", min, max);
      final Query q2;
      if (sortedSet) {
        q2 = SortedSetDocValuesField.newSlowRangeQuery("dv",
            min == Long.MIN_VALUE && random().nextBoolean() ? null : new BytesRef(encodedMin),
            max == Long.MAX_VALUE && random().nextBoolean() ? null : new BytesRef(encodedMax),
            includeMin, includeMax);
      } else {
        q2 = SortedDocValuesField.newSlowRangeQuery("dv",
            min == Long.MIN_VALUE && random().nextBoolean() ? null : new BytesRef(encodedMin),
            max == Long.MAX_VALUE && random().nextBoolean() ? null : new BytesRef(encodedMax),
            includeMin, includeMax);
      }
      assertSameMatches(searcher, q1, q2, false);
    }

    reader.close();
    dir.close();
  }
}
 
Example 15
Source File: TestDocValuesQueries.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private void doTestDuelPointRangeNumericRangeQuery(boolean sortedNumeric, int maxValuesPerDoc) throws IOException {
  final int iters = atLeast(10);
  for (int iter = 0; iter < iters; ++iter) {
    Directory dir = newDirectory();
    RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
    final int numDocs = atLeast(100);
    for (int i = 0; i < numDocs; ++i) {
      Document doc = new Document();
      final int numValues = TestUtil.nextInt(random(), 0, maxValuesPerDoc);
      for (int j = 0; j < numValues; ++j) {
        final long value = TestUtil.nextLong(random(), -100, 10000);
        if (sortedNumeric) {
          doc.add(new SortedNumericDocValuesField("dv", value));
        } else {
          doc.add(new NumericDocValuesField("dv", value));
        }
        doc.add(new LongPoint("idx", value));
      }
      iw.addDocument(doc);
    }
    if (random().nextBoolean()) {
      iw.deleteDocuments(LongPoint.newRangeQuery("idx", 0L, 10L));
    }
    final IndexReader reader = iw.getReader();
    final IndexSearcher searcher = newSearcher(reader, false);
    iw.close();

    for (int i = 0; i < 100; ++i) {
      final long min = random().nextBoolean() ? Long.MIN_VALUE : TestUtil.nextLong(random(), -100, 10000);
      final long max = random().nextBoolean() ? Long.MAX_VALUE : TestUtil.nextLong(random(), -100, 10000);
      final Query q1 = LongPoint.newRangeQuery("idx", min, max);
      final Query q2;
      if (sortedNumeric) {
        q2 = SortedNumericDocValuesField.newSlowRangeQuery("dv", min, max);
      } else {
        q2 = NumericDocValuesField.newSlowRangeQuery("dv", min, max);
      }
      assertSameMatches(searcher, q1, q2, false);
    }

    reader.close();
    dir.close();
  }
}
 
Example 16
Source File: TestIndexSortSortedNumericDocValuesRangeQuery.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void testSameHitsAsPointRangeQuery() throws IOException {
  final int iters = atLeast(10);
  for (int iter = 0; iter < iters; ++iter) {
    Directory dir = newDirectory();

    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    boolean reverse = random().nextBoolean();
    SortField sortField = new SortedNumericSortField("dv", SortField.Type.LONG, reverse);
    sortField.setMissingValue(random().nextLong());
    iwc.setIndexSort(new Sort(sortField));

    RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc);

    final int numDocs = atLeast(100);
    for (int i = 0; i < numDocs; ++i) {
      Document doc = new Document();
      final int numValues = TestUtil.nextInt(random(), 0, 1);
      for (int j = 0; j < numValues; ++j) {
        final long value = TestUtil.nextLong(random(), -100, 10000);
        doc.add(new SortedNumericDocValuesField("dv", value));
        doc.add(new LongPoint("idx", value));
      }
      iw.addDocument(doc);
    }
    if (random().nextBoolean()) {
      iw.deleteDocuments(LongPoint.newRangeQuery("idx", 0L, 10L));
    }
    final IndexReader reader = iw.getReader();
    final IndexSearcher searcher = newSearcher(reader, false);
    iw.close();

    for (int i = 0; i < 100; ++i) {
      final long min = random().nextBoolean() ? Long.MIN_VALUE : TestUtil.nextLong(random(), -100, 10000);
      final long max = random().nextBoolean() ? Long.MAX_VALUE : TestUtil.nextLong(random(), -100, 10000);
      final Query q1 = LongPoint.newRangeQuery("idx", min, max);
      final Query q2 = createQuery("dv", min, max);
      assertSameHits(searcher, q1, q2, false);
    }

    reader.close();
    dir.close();
  }
}
 
Example 17
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 18
Source File: LuceneQueryConverter.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private Query toTermLongQuery(SearchQuery.TermLong term) {
  return LongPoint.newRangeQuery(
    term.getField(),
    term.getValue(),
    term.getValue());
}
 
Example 19
Source File: AbstractSearchQueryBuilderImpl.java    From yes-cart with Apache License 2.0 2 votes vote down vote up
/**
 * Create range query.
 *
 * @param field field name
 * @param low from value (inclusive)
 * @param high to value (exclusive)
 *
 * @return range query
 */
protected Query createRangeQuery(final String field, final Long low, final Long high) {
    return LongPoint.newRangeQuery(field, low != null ? low : Long.MIN_VALUE, high != null ? Math.addExact(high, -1) : Long.MAX_VALUE);
}
 
Example 20
Source File: SoftDeletesPolicy.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a soft-deletes retention query that will be used in {@link org.apache.lucene.index.SoftDeletesRetentionMergePolicy}
 * Documents including tombstones are soft-deleted and matched this query will be retained and won't cleaned up by merges.
 */
Query getRetentionQuery() {
    return LongPoint.newRangeQuery(SeqNoFieldMapper.NAME, getMinRetainedSeqNo(), Long.MAX_VALUE);
}