mirror of https://github.com/apache/lucene.git
add testcase
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1177049 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ab5a62cf46
commit
02736c0976
|
@ -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;
|
||||
|
@ -83,6 +86,47 @@ public class TestQueryWrapperFilter extends LuceneTestCase {
|
|||
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();
|
||||
RandomIndexWriter writer = new RandomIndexWriter(random, dir);
|
||||
|
|
Loading…
Reference in New Issue