Java Code Examples for org.apache.lucene.document.SortedSetDocValuesField#newSlowRangeQuery()

The following examples show how to use org.apache.lucene.document.SortedSetDocValuesField#newSlowRangeQuery() . 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: TestIndexSortSortedNumericDocValuesRangeQuery.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testToString() {
  Query q1 = createQuery("foo", 3, 5);
  assertEquals("foo:[3 TO 5]", q1.toString());
  assertEquals("[3 TO 5]", q1.toString("foo"));
  assertEquals("foo:[3 TO 5]", q1.toString("bar"));

  Query q2 = SortedSetDocValuesField.newSlowRangeQuery("foo", new BytesRef("bar"), new BytesRef("baz"), true, true);
  assertEquals("foo:[[62 61 72] TO [62 61 7a]]", q2.toString());
  q2 = SortedSetDocValuesField.newSlowRangeQuery("foo", new BytesRef("bar"), new BytesRef("baz"), false, true);
  assertEquals("foo:{[62 61 72] TO [62 61 7a]]", q2.toString());
  q2 = SortedSetDocValuesField.newSlowRangeQuery("foo", new BytesRef("bar"), new BytesRef("baz"), false, false);
  assertEquals("foo:{[62 61 72] TO [62 61 7a]}", q2.toString());
  q2 = SortedSetDocValuesField.newSlowRangeQuery("foo", new BytesRef("bar"), null, true, true);
  assertEquals("foo:[[62 61 72] TO *}", q2.toString());
  q2 = SortedSetDocValuesField.newSlowRangeQuery("foo", null, new BytesRef("baz"), true, true);
  assertEquals("foo:{* TO [62 61 7a]]", q2.toString());
  assertEquals("{* TO [62 61 7a]]", q2.toString("foo"));
  assertEquals("foo:{* TO [62 61 7a]]", q2.toString("bar"));
}
 
Example 2
Source File: TestDocValuesQueries.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testToString() {
  Query q1 = SortedNumericDocValuesField.newSlowRangeQuery("foo", 3, 5);
  assertEquals("foo:[3 TO 5]", q1.toString());
  assertEquals("[3 TO 5]", q1.toString("foo"));
  assertEquals("foo:[3 TO 5]", q1.toString("bar"));

  Query q2 = SortedSetDocValuesField.newSlowRangeQuery("foo", new BytesRef("bar"), new BytesRef("baz"), true, true);
  assertEquals("foo:[[62 61 72] TO [62 61 7a]]", q2.toString());
  q2 = SortedSetDocValuesField.newSlowRangeQuery("foo", new BytesRef("bar"), new BytesRef("baz"), false, true);
  assertEquals("foo:{[62 61 72] TO [62 61 7a]]", q2.toString());
  q2 = SortedSetDocValuesField.newSlowRangeQuery("foo", new BytesRef("bar"), new BytesRef("baz"), false, false);
  assertEquals("foo:{[62 61 72] TO [62 61 7a]}", q2.toString());
  q2 = SortedSetDocValuesField.newSlowRangeQuery("foo", new BytesRef("bar"), null, true, true);
  assertEquals("foo:[[62 61 72] TO *}", q2.toString());
  q2 = SortedSetDocValuesField.newSlowRangeQuery("foo", null, new BytesRef("baz"), true, true);
  assertEquals("foo:{* TO [62 61 7a]]", q2.toString());
  assertEquals("{* TO [62 61 7a]]", q2.toString("foo"));
  assertEquals("foo:{* TO [62 61 7a]]", q2.toString("bar"));
}
 
Example 3
Source File: TestDocValuesQueries.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testEquals() {
  Query q1 = SortedNumericDocValuesField.newSlowRangeQuery("foo", 3, 5);
  QueryUtils.checkEqual(q1, SortedNumericDocValuesField.newSlowRangeQuery("foo", 3, 5));
  QueryUtils.checkUnequal(q1, SortedNumericDocValuesField.newSlowRangeQuery("foo", 3, 6));
  QueryUtils.checkUnequal(q1, SortedNumericDocValuesField.newSlowRangeQuery("foo", 4, 5));
  QueryUtils.checkUnequal(q1, SortedNumericDocValuesField.newSlowRangeQuery("bar", 3, 5));

  Query q2 = SortedSetDocValuesField.newSlowRangeQuery("foo", new BytesRef("bar"), new BytesRef("baz"), true, true);
  QueryUtils.checkEqual(q2, SortedSetDocValuesField.newSlowRangeQuery("foo", new BytesRef("bar"), new BytesRef("baz"), true, true));
  QueryUtils.checkUnequal(q2, SortedSetDocValuesField.newSlowRangeQuery("foo", new BytesRef("baz"), new BytesRef("baz"), true, true));
  QueryUtils.checkUnequal(q2, SortedSetDocValuesField.newSlowRangeQuery("foo", new BytesRef("bar"), new BytesRef("bar"), true, true));
  QueryUtils.checkUnequal(q2, SortedSetDocValuesField.newSlowRangeQuery("quux", new BytesRef("bar"), new BytesRef("baz"), true, true));
}
 
Example 4
Source File: ICUCollationField.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected Query getSpecializedRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) {
  String f = field.getName();
  BytesRef low = part1 == null ? null : getCollationKey(f, part1);
  BytesRef high = part2 == null ? null : getCollationKey(f, part2);
  if (!field.indexed() && field.hasDocValues()) {
    return SortedSetDocValuesField.newSlowRangeQuery(
        field.getName(), low, high, minInclusive, maxInclusive);
  } else {
    return new TermRangeQuery(field.getName(), low, high, minInclusive, maxInclusive);
  }
}
 
Example 5
Source File: CollationField.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected Query getSpecializedRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) {
  String f = field.getName();
  BytesRef low = part1 == null ? null : getCollationKey(f, part1);
  BytesRef high = part2 == null ? null : getCollationKey(f, part2);
  if (!field.indexed() && field.hasDocValues()) {
    return SortedSetDocValuesField.newSlowRangeQuery(
        field.getName(), low, high, minInclusive, maxInclusive);
  } else {
    return new TermRangeQuery(field.getName(), low, high, minInclusive, maxInclusive);
  }
}
 
Example 6
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 7
Source File: FieldType.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a Query instance for doing range searches on this field type. {@link org.apache.solr.search.SolrQueryParser}
 * currently passes <code>part1</code> and <code>part2</code> as null if they are '*' respectively. <code>minInclusive</code> and <code>maxInclusive</code> are both true
 * currently by SolrQueryParser but that may change in the future. Also, other QueryParser implementations may have
 * different semantics.
 * <p>
 * Sub-classes should override this method to provide their own range query implementation. They should strive to
 * handle nulls in <code>part1</code> and/or <code>part2</code> as well as unequal <code>minInclusive</code> and <code>maxInclusive</code> parameters gracefully.
 * <p>
 * This method does not, and should not, check for or handle existence queries, please look at {@link #getRangeQuery} for that logic.
 *
 * @param parser       the {@link org.apache.solr.search.QParser} calling the method
 * @param field        the schema field
 * @param part1        the lower boundary of the range, nulls are allowed.
 * @param part2        the upper boundary of the range, nulls are allowed
 * @param minInclusive whether the minimum of the range is inclusive or not
 * @param maxInclusive whether the maximum of the range is inclusive or not
 *  @return a Query instance to perform range search according to given parameters
 *
 */
protected Query getSpecializedRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) {
  // TODO: change these all to use readableToIndexed/bytes instead (e.g. for unicode collation)
  final BytesRef miValue = part1 == null ? null : new BytesRef(toInternal(part1));
  final BytesRef maxValue = part2 == null ? null : new BytesRef(toInternal(part2));

  if (field.hasDocValues() && !field.indexed()) {
    return SortedSetDocValuesField.newSlowRangeQuery(
        field.getName(),
        miValue, maxValue,
        minInclusive, maxInclusive);
  } else {
    SolrRangeQuery rangeQuery = new SolrRangeQuery(
        field.getName(),
        miValue, maxValue,
        minInclusive, maxInclusive);
    return rangeQuery;
  }
}