LUCENE-6245: Force Filter subclasses to implement toString API from Query

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1659982 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan Ernst 2015-02-15 19:07:30 +00:00
parent 8c1c170468
commit 1dc2cbf25e
43 changed files with 210 additions and 37 deletions

View File

@ -117,6 +117,9 @@ API Changes
* LUCENE-1518: Make Filter extend Query and return 0 as score.
(Uwe Schindler, Adrien Grand)
* LUCENE-6245: Force Filter subclasses to implement toString API from Query.
(Ryan Ernst)
Other
* LUCENE-6193: Collapse identical catch branches in try-catch statements.

View File

@ -55,9 +55,9 @@ public final class DocTermOrdsRewriteMethod extends MultiTermQuery.RewriteMethod
}
@Override
public String toString() {
public String toString(String field) {
// query.toString should be ok for the filter, too, if the query boost is 1.0f
return query.toString();
return query.toString(field);
}
@Override

View File

@ -55,9 +55,9 @@ public final class DocValuesRewriteMethod extends MultiTermQuery.RewriteMethod {
}
@Override
public String toString() {
public String toString(String field) {
// query.toString should be ok for the filter, too, if the query boost is 1.0f
return query.toString();
return query.toString(field);
}
@Override

View File

@ -75,11 +75,6 @@ public abstract class Filter extends Query {
return System.identityHashCode(this);
}
@Override
public String toString(String field) {
return getClass().getSimpleName();
}
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
return new Weight(this) {

View File

@ -52,9 +52,9 @@ public class MultiTermQueryWrapperFilter<Q extends MultiTermQuery> extends Filte
}
@Override
public String toString() {
public String toString(String field) {
// query.toString should be ok for the filter, too, if the query boost is 1.0f
return query.toString();
return query.toString(field);
}
@Override

View File

@ -31,9 +31,9 @@ public class PrefixFilter extends MultiTermQueryWrapperFilter<PrefixQuery> {
public Term getPrefix() { return query.getPrefix(); }
/** Prints a user-readable version of this query. */
/** Prints a user-readable version of this filter. */
@Override
public String toString () {
public String toString(String field) {
StringBuilder buffer = new StringBuilder();
buffer.append("PrefixFilter(");
buffer.append(getPrefix().toString());

View File

@ -65,7 +65,7 @@ public abstract class Query implements Cloneable {
/** Prints a query to a string. */
@Override
public String toString() {
public final String toString() {
return toString("");
}

View File

@ -137,6 +137,11 @@ final class JustCompileSearch {
public DocIdSet getDocIdSet(LeafReaderContext context, Bits acceptDocs) {
return null;
}
@Override
public String toString(String field) {
return "JustCompileFilter";
}
}
static final class JustCompileFilteredDocIdSet extends FilteredDocIdSet {

View File

@ -32,6 +32,11 @@ public class MockFilter extends Filter {
return new BitDocIdSet(bits);
}
@Override
public String toString(String field) {
return "MockFilter";
}
public void clear() {
wasCalled = false;
}

View File

@ -38,4 +38,9 @@ public class SingleDocTestFilter extends Filter {
if (acceptDocs != null && !acceptDocs.get(doc)) bits.clear(doc);
return new BitDocIdSet(bits);
}
@Override
public String toString(String field) {
return "SingleDocTestFilter(" + doc + ")";
}
}

View File

@ -181,6 +181,10 @@ public class TestCachingWrapperFilter extends LuceneTestCase {
public DocIdSet getDocIdSet(LeafReaderContext context, Bits acceptDocs) {
return null;
}
@Override
public String toString(String field) {
return "nullDocIdSetFilter";
}
};
CachingWrapperFilter cacher = new CachingWrapperFilter(filter, MAYBE_CACHE_POLICY);
@ -214,6 +218,10 @@ public class TestCachingWrapperFilter extends LuceneTestCase {
}
};
}
@Override
public String toString(String field) {
return "nullDocIdSetIteratorFilter";
}
};
CachingWrapperFilter cacher = new CachingWrapperFilter(filter, FilterCachingPolicy.ALWAYS_CACHE);
@ -267,6 +275,10 @@ public class TestCachingWrapperFilter extends LuceneTestCase {
public DocIdSet getDocIdSet(LeafReaderContext context, Bits acceptDocs) {
return new BitDocIdSet(new FixedBitSet(context.reader().maxDoc()));
}
@Override
public String toString(String field) {
return "cacheableFilter";
}
}, true);
reader.close();

View File

@ -127,6 +127,10 @@ public class TestDocIdSet extends LuceneTestCase {
public DocIdSet getDocIdSet(LeafReaderContext context, Bits acceptDocs) {
return null;
}
@Override
public String toString(String field) {
return "nullDocIdSetFilter";
}
};
Assert.assertEquals(0, searcher.search(new MatchAllDocsQuery(), f, 10).totalHits);
@ -169,6 +173,10 @@ public class TestDocIdSet extends LuceneTestCase {
}
};
}
@Override
public String toString(String field) {
return "nullDocIdSetFilter";
}
};
Assert.assertEquals(0, searcher.search(new MatchAllDocsQuery(), f, 10).totalHits);

View File

@ -113,6 +113,10 @@ public class TestFilteredQuery extends LuceneTestCase {
if (acceptDocs.get(3)) bitset.set(3);
return new BitDocIdSet(bitset);
}
@Override
public String toString(String field) {
return "staticFilterB";
}
};
}
@ -194,6 +198,10 @@ public class TestFilteredQuery extends LuceneTestCase {
bitset.set(0, Math.min(5, bitset.length()));
return new BitDocIdSet(bitset);
}
@Override
public String toString(String field) {
return "staticFilterA";
}
};
}
@ -480,6 +488,10 @@ public class TestFilteredQuery extends LuceneTestCase {
};
}
@Override
public String toString(String field) {
return "filterField0";
}
}, FilteredQuery.QUERY_FIRST_FILTER_STRATEGY);
TopDocs search = searcher.search(query, 10);
@ -559,7 +571,13 @@ public class TestFilteredQuery extends LuceneTestCase {
};
}
};
}
@Override
public String toString(String field) {
return "filterField0";
}
}, queryFirst ? FilteredQuery.LEAP_FROG_QUERY_FIRST_STRATEGY : random()
.nextBoolean() ? FilteredQuery.RANDOM_ACCESS_FILTER_STRATEGY

View File

@ -101,6 +101,11 @@ public class TestFilteredSearch extends LuceneTestCase {
}
return set.cardinality() == 0 ? null : new BitDocIdSet(set);
}
@Override
public String toString(String field) {
return "SimpleDocIdSetFilter";
}
}
}

View File

@ -350,6 +350,11 @@ public class TestLRUFilterCache extends LuceneTestCase {
return null;
}
@Override
public String toString(String field) {
return "DummyFilter";
}
}
// Test what happens when the cache contains only filters and doc id sets

View File

@ -149,6 +149,10 @@ public class TestScorerPerf extends LuceneTestCase {
assertNull("acceptDocs should be null, as we have an index without deletions", acceptDocs);
return new BitDocIdSet(rnd);
}
@Override
public String toString(String field) {
return "randomBitSetFilter";
}
});
bq.add(q, BooleanClause.Occur.MUST);
if (validate) {

View File

@ -263,5 +263,10 @@ public class TestSortRandom extends LuceneTestCase {
return new BitDocIdSet(bits);
}
@Override
public String toString(String field) {
return "RandomFilter(density=" + density + ")";
}
}
}

View File

@ -105,7 +105,7 @@ public final class DoubleRange extends Range {
return new Filter() {
@Override
public String toString() {
public String toString(String field) {
return "Filter(" + DoubleRange.this.toString() + ")";
}

View File

@ -97,7 +97,7 @@ public final class LongRange extends Range {
return new Filter() {
@Override
public String toString() {
public String toString(String field) {
return "Filter(" + LongRange.this.toString() + ")";
}

View File

@ -660,6 +660,10 @@ public class TestDrillSideways extends FacetTestCase {
}
return new BitDocIdSet(bits);
}
@Override
public String toString(String field) {
return "drillSidewaysTestFilter";
}
};
} else {
filter = null;

View File

@ -943,6 +943,10 @@ public class FieldQueryTest extends AbstractTestCase {
throws IOException {
return null;
}
@Override
public String toString(String field) {
return "filterToBeFlattened";
}
});
query.setBoost(boost);
FieldQuery fq = new FieldQuery( query, true, true );

View File

@ -81,7 +81,7 @@ public class BitDocIdSetCachingWrapperFilter extends BitDocIdSetFilter implement
}
@Override
public String toString() {
public String toString(String field) {
return filter.toString();
}

View File

@ -293,5 +293,10 @@ public class TestFieldCacheSortRandom extends LuceneTestCase {
return new BitDocIdSet(bits);
}
@Override
public String toString(String field) {
return "RandomFilter(density=" + density + ")";
}
}
}

View File

@ -96,6 +96,10 @@ public class BooleanFilterTest extends LuceneTestCase {
public DocIdSet getDocIdSet(LeafReaderContext context, Bits acceptDocs) {
return new BitDocIdSet(new FixedBitSet(context.reader().maxDoc()));
}
@Override
public String toString(String field) {
return "emptyFilter";
}
};
}
@ -105,6 +109,10 @@ public class BooleanFilterTest extends LuceneTestCase {
public DocIdSet getDocIdSet(LeafReaderContext context, Bits acceptDocs) {
return null;
}
@Override
public String toString(String field) {
return "nullDISFilter";
}
};
}
@ -114,6 +122,10 @@ public class BooleanFilterTest extends LuceneTestCase {
public DocIdSet getDocIdSet(LeafReaderContext context, Bits acceptDocs) {
return DocIdSet.EMPTY;
}
@Override
public String toString(String field) {
return "nullDISIFilter";
}
};
}

View File

@ -37,15 +37,10 @@ abstract class RewriteQuery<SQ extends SrndQuery> extends Query {
@Override
abstract public Query rewrite(IndexReader reader) throws IOException;
@Override
public String toString() {
return toString(null);
}
@Override
public String toString(String field) {
return getClass().getName()
+ (field == null ? "" : "(unused: " + field + ")")
+ (field.isEmpty() ? "" : "(unused: " + field + ")")
+ "(" + fieldName
+ ", " + srndQuery.toString()
+ ", " + qf.toString()

View File

@ -159,5 +159,10 @@ public class NumericRangeFilterBuilder implements FilterBuilder {
return null;
}
@Override
public String toString(String field) {
return "NoMatchFilter()";
}
}
}

View File

@ -205,6 +205,15 @@ public class DuplicateFilter extends Filter {
fieldName != null && fieldName.equals(other.fieldName);
}
@Override
public String toString(String field) {
return "DuplicateFilter(" +
"fieldName=" + fieldName +"," +
"keepMode=" + (keepMode == KeepMode.KM_USE_FIRST_OCCURRENCE ? "first" : "last") + "," +
"processingMode=" + (processingMode == ProcessingMode.PM_FAST_INVALIDATION ? "fast" : "full") +
")";
}
@Override
public int hashCode() {
int hash = 217;

View File

@ -643,5 +643,10 @@ public class TestTermAutomatonQuery extends LuceneTestCase {
return new BitDocIdSet(bits);
}
@Override
public String toString(String field) {
return "RandomFilter(seed=" + seed + ",density=" + density + ")";
}
}
}

View File

@ -74,6 +74,16 @@ public class ContainsPrefixTreeFilter extends AbstractPrefixTreeFilter {
return super.hashCode() + (multiOverlappingIndexedShapes ? 1 : 0);
}
@Override
public String toString(String field) {
return "ContainsPrefixTreeFilter(" +
// TODO: print something about the shape?
"fieldName=" + fieldName + "," +
"detailLevel=" + detailLevel + "," +
"multiOverlappingIndexedShapes=" + multiOverlappingIndexedShapes +
")";
}
@Override
public DocIdSet getDocIdSet(LeafReaderContext context, Bits acceptDocs) throws IOException {
return new ContainsVisitor(context, acceptDocs).visit(grid.getWorldCell(), acceptDocs);

View File

@ -84,4 +84,15 @@ public class IntersectsPrefixTreeFilter extends AbstractVisitingPrefixTreeFilter
}.getDocIdSet();
}
@Override
public String toString(String field) {
return "IntersectsPrefixTreeFilter(" +
// TODO: print something about the shape?
"fieldName=" + fieldName + "," +
"detailLevel=" + detailLevel + "," +
"prefixGridScanLevel=" + prefixGridScanLevel + "," +
"hasIndexedLeaves=" + hasIndexedLeaves +
")";
}
}

View File

@ -116,6 +116,11 @@ public class PrefixTreeFacetCounter {
// traversal code. TODO consider refactoring if/when it makes sense (more use cases than this)
new AbstractVisitingPrefixTreeFilter(queryShape, strategy.getFieldName(), tree, facetLevel, scanLevel,
!strategy.isPointsOnly()) {
@Override
public String toString(String field) {
return "anonPrefixTreeFilter";
}
@Override
public DocIdSet getDocIdSet(LeafReaderContext context, Bits acceptDocs) throws IOException {

View File

@ -90,6 +90,17 @@ public class WithinPrefixTreeFilter extends AbstractVisitingPrefixTreeFilter {
result = 31 * result + (bufferedQueryShape != null ? bufferedQueryShape.hashCode() : 0);
return result;
}
@Override
public String toString(String field) {
return "WithinPrefixTreeFilter(" +
// TODO: print something about the shape?
"fieldName=" + fieldName + "," +
"detailLevel=" + detailLevel + "," +
"prefixGridScanLevel=" + prefixGridScanLevel + "," +
"hasIndexedLeaves=" + hasIndexedLeaves +
")";
}
/** Returns a new shape that is larger than shape by at distErr.
*/

View File

@ -196,6 +196,13 @@ public class SerializedDVStrategy extends SpatialStrategy {
public int hashCode() {
return predicateValueSource.hashCode();
}
@Override
public String toString(String field) {
return "PredicateValueSourceFilter(" +
predicateValueSource.toString() +
")";
}
}//PredicateValueSourceFilter
/**

View File

@ -62,4 +62,14 @@ public class ValueSourceFilter extends Filter {
}
};
}
@Override
public String toString(String field) {
return "ValueSourceFilter(" +
"startingFilter=" + startingFilter.toString(field) + "," +
"source=" + source.toString() + "," +
"min=" + min + "," +
"max=" + max +
")";
}
}

View File

@ -358,6 +358,10 @@ public class BitDocSet extends DocSetBase {
}, acceptDocs2);
}
@Override
public String toString(String field) {
return "BitSetDocTopFilter";
}
};
}
}

View File

@ -229,6 +229,10 @@ abstract class DocSetBase implements DocSet {
}, acceptDocs2);
}
@Override
public String toString(String field) {
return "DocSetTopFilter";
}
};
}

View File

@ -150,6 +150,7 @@ public class ReRankQParserPlugin extends QParserPlugin {
return new ReRankCollector(reRankDocs, length, reRankQuery, reRankWeight, cmd, searcher, boostedPriority);
}
@Override
public String toString(String s) {
return "{!rerank mainQuery='"+mainQuery.toString()+
"' reRankQuery='"+reRankQuery.toString()+
@ -157,10 +158,6 @@ public class ReRankQParserPlugin extends QParserPlugin {
" reRankWeigh="+reRankWeight+"}";
}
public String toString() {
return toString(null);
}
public Query rewrite(IndexReader reader) throws IOException {
return wrap(this.mainQuery.rewrite(reader));

View File

@ -2456,6 +2456,11 @@ class FilterImpl extends Filter {
return new FilterSet(sub, context);
}
@Override
public String toString(String field) {
return "SolrFilter";
}
private class FilterSet extends DocIdSet {
DocIdSet docIdSet;
LeafReaderContext context;

View File

@ -779,6 +779,10 @@ public class SortedIntDocSet extends DocSetBase {
}, acceptDocs2);
}
@Override
public String toString(String field) {
return "SortedIntDocSetTopFilter";
}
};
}

View File

@ -98,7 +98,7 @@ public class ValueSourceRangeFilter extends SolrFilter {
}
@Override
public String toString() {
public String toString(String field) {
StringBuilder sb = new StringBuilder();
sb.append("frange(");
sb.append(valueSource);

View File

@ -47,11 +47,6 @@ public class IgnoreAcceptDocsQuery extends Query {
return q.getBoost();
}
@Override
public String toString() {
return q.toString();
}
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
Weight inner = q.createWeight(searcher, needsScores);

View File

@ -126,10 +126,7 @@ public class TestRankQueryPlugin extends QParserPlugin {
return q.getBoost();
}
public String toString() {
return q.toString();
}
@Override
public String toString(String field) {
return q.toString(field);
}

View File

@ -239,6 +239,10 @@ public class TestSort extends SolrTestCaseJ4 {
public DocIdSet getDocIdSet(LeafReaderContext context, Bits acceptDocs) {
return BitsFilteredDocIdSet.wrap(randSet(context.reader().maxDoc()), acceptDocs);
}
@Override
public String toString(String field) {
return "TestSortFilter";
}
};
int top = r.nextInt((ndocs>>3)+1)+1;