mirror of https://github.com/apache/lucene.git
test case cleanup - no need to catch unexpected exceptions in test cases, let it fail
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150052 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
aad53f0dba
commit
1e5eccf552
|
@ -1,11 +1,8 @@
|
|||
package org.apache.lucene.search;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.lucene.analysis.WhitespaceAnalyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.store.Directory;
|
||||
|
@ -14,128 +11,98 @@ import org.apache.lucene.store.RAMDirectory;
|
|||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author goller
|
||||
*/
|
||||
public class TestRangeQuery extends TestCase {
|
||||
|
||||
private int docCount = 0;
|
||||
private int docCount = 0;
|
||||
|
||||
public TestRangeQuery() {
|
||||
super();
|
||||
}
|
||||
public void testExclusive() throws Exception {
|
||||
Directory dir = new RAMDirectory();
|
||||
Query query = new RangeQuery(new Term("content", "A"), new Term("content", "C"), false);
|
||||
Hits hits = null;
|
||||
|
||||
public void testNotInclusive()
|
||||
{
|
||||
Directory dir = new RAMDirectory();
|
||||
IndexWriter writer = null;
|
||||
Searcher searcher = null;
|
||||
Query query = new RangeQuery(new Term("content", "A"), new Term("content", "C"), false);
|
||||
Hits hits = null;
|
||||
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
||||
addDoc(writer, "A");
|
||||
addDoc(writer, "B");
|
||||
addDoc(writer, "C");
|
||||
addDoc(writer, "D");
|
||||
writer.close();
|
||||
|
||||
try {
|
||||
IndexSearcher searcher = new IndexSearcher(dir);
|
||||
hits = searcher.search(query);
|
||||
assertEquals(1, hits.length());
|
||||
searcher.close();
|
||||
|
||||
writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
||||
addDoc(writer, "A");
|
||||
addDoc(writer, "B");
|
||||
addDoc(writer, "C");
|
||||
addDoc(writer, "D");
|
||||
writer.close();
|
||||
writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
||||
addDoc(writer, "A");
|
||||
addDoc(writer, "B");
|
||||
addDoc(writer, "D");
|
||||
writer.close();
|
||||
|
||||
searcher = new IndexSearcher(dir);
|
||||
hits = searcher.search(query);
|
||||
assertEquals(1, hits.length());
|
||||
searcher.close();
|
||||
searcher = new IndexSearcher(dir);
|
||||
hits = searcher.search(query);
|
||||
assertEquals(1, hits.length());
|
||||
searcher.close();
|
||||
|
||||
writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
||||
addDoc(writer, "A");
|
||||
addDoc(writer, "B");
|
||||
addDoc(writer, "D");
|
||||
writer.close();
|
||||
writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
|
||||
addDoc(writer, "C");
|
||||
writer.close();
|
||||
|
||||
searcher = new IndexSearcher(dir);
|
||||
hits = searcher.search(query);
|
||||
assertEquals(1, hits.length());
|
||||
searcher.close();
|
||||
searcher = new IndexSearcher(dir);
|
||||
hits = searcher.search(query);
|
||||
assertEquals(1, hits.length());
|
||||
searcher.close();
|
||||
}
|
||||
|
||||
writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
|
||||
addDoc(writer, "C");
|
||||
writer.close();
|
||||
public void testInclusive() throws Exception {
|
||||
Directory dir = new RAMDirectory();
|
||||
IndexWriter writer = null;
|
||||
Searcher searcher = null;
|
||||
Query query = new RangeQuery(new Term("content", "A"), new Term("content", "C"), true);
|
||||
Hits hits = null;
|
||||
|
||||
searcher = new IndexSearcher(dir);
|
||||
hits = searcher.search(query);
|
||||
assertEquals(1, hits.length());
|
||||
searcher.close();
|
||||
writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
||||
addDoc(writer, "A");
|
||||
addDoc(writer, "B");
|
||||
addDoc(writer, "C");
|
||||
addDoc(writer, "D");
|
||||
writer.close();
|
||||
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
searcher = new IndexSearcher(dir);
|
||||
hits = searcher.search(query);
|
||||
assertEquals(3, hits.length());
|
||||
searcher.close();
|
||||
|
||||
}
|
||||
writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
||||
addDoc(writer, "A");
|
||||
addDoc(writer, "B");
|
||||
addDoc(writer, "D");
|
||||
writer.close();
|
||||
|
||||
public void testInclusive()
|
||||
{
|
||||
Directory dir = new RAMDirectory();
|
||||
IndexWriter writer = null;
|
||||
Searcher searcher = null;
|
||||
Query query = new RangeQuery(new Term("content", "A"), new Term("content", "C"), true);
|
||||
Hits hits = null;
|
||||
searcher = new IndexSearcher(dir);
|
||||
hits = searcher.search(query);
|
||||
assertEquals(2, hits.length());
|
||||
searcher.close();
|
||||
|
||||
try {
|
||||
writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
|
||||
addDoc(writer, "C");
|
||||
writer.close();
|
||||
|
||||
writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
||||
addDoc(writer, "A");
|
||||
addDoc(writer, "B");
|
||||
addDoc(writer, "C");
|
||||
addDoc(writer, "D");
|
||||
writer.close();
|
||||
searcher = new IndexSearcher(dir);
|
||||
hits = searcher.search(query);
|
||||
assertEquals(3, hits.length());
|
||||
searcher.close();
|
||||
}
|
||||
|
||||
searcher = new IndexSearcher(dir);
|
||||
hits = searcher.search(query);
|
||||
assertEquals(3, hits.length());
|
||||
searcher.close();
|
||||
private void addDoc(IndexWriter writer, String content) throws Exception {
|
||||
Document doc = new Document();
|
||||
|
||||
writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
||||
addDoc(writer, "A");
|
||||
addDoc(writer, "B");
|
||||
addDoc(writer, "D");
|
||||
writer.close();
|
||||
doc.add(Field.Keyword("id", "id" + docCount));
|
||||
doc.add(Field.UnStored("content", content));
|
||||
|
||||
searcher = new IndexSearcher(dir);
|
||||
hits = searcher.search(query);
|
||||
assertEquals(2, hits.length());
|
||||
searcher.close();
|
||||
|
||||
writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
|
||||
addDoc(writer, "C");
|
||||
writer.close();
|
||||
|
||||
searcher = new IndexSearcher(dir);
|
||||
hits = searcher.search(query);
|
||||
assertEquals(3, hits.length());
|
||||
searcher.close();
|
||||
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void addDoc(IndexWriter writer, String content)
|
||||
{
|
||||
Document doc = new Document();
|
||||
|
||||
doc.add(Field.Keyword("id","id" + docCount));
|
||||
doc.add(Field.UnStored("content", content));
|
||||
|
||||
try {
|
||||
writer.addDocument(doc);
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
docCount++;
|
||||
}
|
||||
writer.addDocument(doc);
|
||||
docCount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue