use of org.apache.lucene.search.TermRangeQuery in project lucene-solr by apache.
the class TestForTooMuchCloning method test.
// Make sure we don't clone IndexInputs too frequently
// during merging and searching:
public void test() throws Exception {
final MockDirectoryWrapper dir = newMockDirectory();
final TieredMergePolicy tmp = new TieredMergePolicy();
tmp.setMaxMergeAtOnce(2);
final RandomIndexWriter w = new RandomIndexWriter(random(), dir, newIndexWriterConfig(new MockAnalyzer(random())).setMaxBufferedDocs(2).setMergePolicy(tmp));
final int numDocs = 20;
for (int docs = 0; docs < numDocs; docs++) {
StringBuilder sb = new StringBuilder();
for (int terms = 0; terms < 100; terms++) {
sb.append(TestUtil.randomRealisticUnicodeString(random()));
sb.append(' ');
}
final Document doc = new Document();
doc.add(new TextField("field", sb.toString(), Field.Store.NO));
w.addDocument(doc);
}
final IndexReader r = w.getReader();
w.close();
//System.out.println("merge clone count=" + cloneCount);
assertTrue("too many calls to IndexInput.clone during merging: " + dir.getInputCloneCount(), dir.getInputCloneCount() < 500);
final IndexSearcher s = newSearcher(r);
// important: set this after newSearcher, it might have run checkindex
final int cloneCount = dir.getInputCloneCount();
// dir.setVerboseClone(true);
// MTQ that matches all terms so the AUTO_REWRITE should
// cutover to filter rewrite and reuse a single DocsEnum
// across all terms;
final TopDocs hits = s.search(new TermRangeQuery("field", new BytesRef(), new BytesRef(""), true, true), 10);
assertTrue(hits.totalHits > 0);
final int queryCloneCount = dir.getInputCloneCount() - cloneCount;
//System.out.println("query clone count=" + queryCloneCount);
assertTrue("too many calls to IndexInput.clone during TermRangeQuery: " + queryCloneCount, queryCloneCount < 50);
r.close();
dir.close();
}
use of org.apache.lucene.search.TermRangeQuery in project lucene-solr by apache.
the class TermRangeQueryNodeBuilder method build.
@Override
public TermRangeQuery build(QueryNode queryNode) throws QueryNodeException {
TermRangeQueryNode rangeNode = (TermRangeQueryNode) queryNode;
FieldQueryNode upper = rangeNode.getUpperBound();
FieldQueryNode lower = rangeNode.getLowerBound();
String field = StringUtils.toString(rangeNode.getField());
String lowerText = lower.getTextAsString();
String upperText = upper.getTextAsString();
if (lowerText.length() == 0) {
lowerText = null;
}
if (upperText.length() == 0) {
upperText = null;
}
TermRangeQuery rangeQuery = TermRangeQuery.newStringRange(field, lowerText, upperText, rangeNode.isLowerInclusive(), rangeNode.isUpperInclusive());
MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod) queryNode.getTag(MultiTermRewriteMethodProcessor.TAG_ID);
if (method != null) {
rangeQuery.setRewriteMethod(method);
}
return rangeQuery;
}
use of org.apache.lucene.search.TermRangeQuery in project lucene-solr by apache.
the class FieldQueryTest method testRangeQuery.
public void testRangeQuery() throws Exception {
makeIndexStrMV();
defgMultiTermQueryTest(new TermRangeQuery(F, new BytesRef("d"), new BytesRef("e"), true, true));
}
use of org.apache.lucene.search.TermRangeQuery in project lucene-solr by apache.
the class TestQPHelper method testConstantScoreAutoRewrite.
public void testConstantScoreAutoRewrite() throws Exception {
StandardQueryParser qp = new StandardQueryParser(new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false));
Query q = qp.parse("foo*bar", "field");
assertTrue(q instanceof WildcardQuery);
assertEquals(MultiTermQuery.CONSTANT_SCORE_REWRITE, ((MultiTermQuery) q).getRewriteMethod());
q = qp.parse("foo*", "field");
assertTrue(q instanceof PrefixQuery);
assertEquals(MultiTermQuery.CONSTANT_SCORE_REWRITE, ((MultiTermQuery) q).getRewriteMethod());
q = qp.parse("[a TO z]", "field");
assertTrue(q instanceof TermRangeQuery);
assertEquals(MultiTermQuery.CONSTANT_SCORE_REWRITE, ((MultiTermQuery) q).getRewriteMethod());
}
use of org.apache.lucene.search.TermRangeQuery in project lucene-solr by apache.
the class ICUCollationField method getRangeQuery.
@Override
public Query getRangeQuery(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.newRangeQuery(field.getName(), low, high, minInclusive, maxInclusive);
} else {
return new TermRangeQuery(field.getName(), low, high, minInclusive, maxInclusive);
}
}
Aggregations