Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

add testcase

Michael McCandless02736c09768a
diff --git a/lucene/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java b/lucene/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java
index 8225510c07c..d0d8ee2a027 100644
--- a/lucene/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java
+++ b/lucene/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java
@@ -16,8 +16,11 @@ package org.apache.lucene.search;
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+import java.util.HashSet;
+import java.util.Set;
import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
import org.apache.lucene.document.StringField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.IndexReader;
@@ -82,6 +85,47 @@ public class TestQueryWrapperFilter extends LuceneTestCase {
reader.close();
dir.close();
}
+
+ public void testRandom() throws Exception {
+ final Directory d = newDirectory();
+ final RandomIndexWriter w = new RandomIndexWriter(random, d);
+ w.w.getConfig().setMaxBufferedDocs(17);
+ final int numDocs = atLeast(100);
+ final Set<String> aDocs = new HashSet<String>();
+ for(int i=0;i<numDocs;i++) {
+ final Document doc = new Document();
+ final String v;
+ if (random.nextInt(5) == 4) {
+ v = "a";
+ aDocs.add(""+i);
+ } else {
+ v = "b";
+ }
+ final Field f = newField("field", v, StringField.TYPE_UNSTORED);
+ doc.add(f);
+ doc.add(newField("id", ""+i, StringField.TYPE_STORED));
+ w.addDocument(doc);
+ }
+
+ final int numDelDocs = atLeast(10);
+ for(int i=0;i<numDelDocs;i++) {
+ final String delID = ""+random.nextInt(numDocs);
+ w.deleteDocuments(new Term("id", delID));
+ aDocs.remove(delID);
+ }
+
+ final IndexReader r = w.getReader();
+ w.close();
+ final TopDocs hits = new IndexSearcher(r).search(new MatchAllDocsQuery(),
+ new QueryWrapperFilter(new TermQuery(new Term("field", "a"))),
+ numDocs);
+ assertEquals(aDocs.size(), hits.totalHits);
+ for(ScoreDoc sd: hits.scoreDocs) {
+ assertTrue(aDocs.contains(r.document(sd.doc).get("id")));
+ }
+ r.close();
+ d.close();
+ }
public void testThousandDocuments() throws Exception {
Directory dir = newDirectory();