Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-1818: QueryWrapperFilter using createWeight rather than weight

Mark Robert Millera77168d3c97d
diff --git a/CHANGES.txt b/CHANGES.txt
index c4d5f6489bf..53d0a914afb 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -61,7 +61,8 @@ Changes in backwards compatibility policy
Going forward Searchable will be kept for convenience only and may
be changed between minor releases without any deprecation
process. It is not recommended that you implement it, but rather extend
- Searcher. (Shai Erera, Chris Hostetter, Mark Miller via Mike McCandless)
+ Searcher.
+ (Shai Erera, Chris Hostetter, Martin Ruckli, Mark Miller via Mike McCandless)
4. LUCENE-1422, LUCENE-1693: The new TokenStream API (see below) using
Attributes has some backwards breaks in rare cases.
@@ -320,7 +321,7 @@ API Changes
out of order when used with a Collector that can accept docs out of order.
Finally, Weight#explain now also takes a the top-level searcher, sub-reader
and sub-docID.
- (Shai Erera, Chris Hostetter, Mark Miller via Mike McCandless)
+ (Shai Erera, Chris Hostetter, Martin Ruckli, Mark Miller via Mike McCandless)
25. LUCENE-1466: Changed Tokenizer.input to be a CharStream; added
CharFilter and MappingCharFilter, which allows chaining & mapping
diff --git a/src/java/org/apache/lucene/search/QueryWrapperFilter.java b/src/java/org/apache/lucene/search/QueryWrapperFilter.java
index 4879448b687..0b46d72f8cc 100644
--- a/src/java/org/apache/lucene/search/QueryWrapperFilter.java
+++ b/src/java/org/apache/lucene/search/QueryWrapperFilter.java
@@ -69,7 +69,7 @@ public class QueryWrapperFilter extends Filter {
}
public DocIdSet getDocIdSet(final IndexReader reader) throws IOException {
- final Weight weight = query.createWeight(new IndexSearcher(reader));
+ final Weight weight = query.weight(new IndexSearcher(reader));
return new DocIdSet() {
public DocIdSetIterator iterator() throws IOException {
return weight.scorer(reader, true, false);
diff --git a/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java b/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java
new file mode 100644
index 00000000000..02957d0f2ef
--- /dev/null
+++ b/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java
@@ -0,0 +1,53 @@
+package org.apache.lucene.search;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.Field.Index;
+import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause.Occur;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestQueryWrapperFilter extends LuceneTestCase {
+
+ public void testBasic() throws Exception {
+ Directory dir = new RAMDirectory();
+ IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(), true,
+ IndexWriter.MaxFieldLength.LIMITED);
+ Document doc = new Document();
+ doc.add(new Field("field", "value", Store.NO, Index.ANALYZED));
+ writer.addDocument(doc);
+ writer.close();
+
+ TermQuery termQuery = new TermQuery(new Term("field", "value"));
+
+ // should not throw exception with primitive query
+ QueryWrapperFilter qwf = new QueryWrapperFilter(termQuery);
+
+ IndexSearcher searcher = new IndexSearcher(dir, true);
+ TopDocs hits = searcher.search(new MatchAllDocsQuery(), qwf, 10);
+ assertEquals(1, hits.totalHits);
+
+ // should not throw exception with non primitive query
+ BooleanQuery booleanQuery = new BooleanQuery();
+ booleanQuery.add(termQuery, Occur.MUST);
+ booleanQuery.add(new TermQuery(new Term("field", "missing")),
+ Occur.MUST_NOT);
+ qwf = new QueryWrapperFilter(termQuery);
+
+ hits = searcher.search(new MatchAllDocsQuery(), qwf, 10);
+ assertEquals(1, hits.totalHits);
+
+ // should not throw exception with Query that doesn't implement
+ // Query#createWeight
+ qwf = new QueryWrapperFilter(new FuzzyQuery(new Term("field", "valu")));
+
+ hits = searcher.search(new MatchAllDocsQuery(), qwf, 10);
+ assertEquals(1, hits.totalHits);
+
+ }
+}