- Added tests for DateFilter.After method.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@149728 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Otis Gospodnetic 2002-04-19 20:29:19 +00:00
parent 4207787649
commit 8c70a95b15
1 changed files with 58 additions and 0 deletions

View File

@ -127,6 +127,64 @@ public class TestDateFilter
assertEquals(1, result.length());
// run queries with DateFilter
result = searcher.search(query1, df1);
assertEquals(0, result.length());
result = searcher.search(query1, df2);
assertEquals(0, result.length());
result = searcher.search(query2, df1);
assertEquals(1, result.length());
result = searcher.search(query2, df2);
assertEquals(0, result.length());
}
/**
*
*/
public static void testAfter()
throws IOException
{
// create an index
RAMDirectory indexStore = new RAMDirectory();
IndexWriter writer = new IndexWriter(indexStore, new SimpleAnalyzer(), true);
long now = System.currentTimeMillis();
Document doc = new Document();
// add time that is in the future
doc.add(Field.Text("datefield", DateField.timeToString(now - 888888)));
doc.add(Field.Text("body", "Today is a very sunny day in New York City"));
writer.addDocument(doc);
writer.optimize();
writer.close();
IndexSearcher searcher = new IndexSearcher(indexStore);
// filter that should preserve matches
DateFilter df1 = DateFilter.After("datefield", now);
// filter that should discard matches
DateFilter df2 = DateFilter.After("datefield", now + 999999);
// search something that doesn't exist with DateFilter
Query query1 = new TermQuery(new Term("body", "NoMatchForThis"));
// search for something that does exists
Query query2 = new TermQuery(new Term("body", "sunny"));
Hits result;
// ensure that queries return expected results without DateFilter first
result = searcher.search(query1);
assertEquals(0, result.length());
result = searcher.search(query2);
assertEquals(1, result.length());
// run queries with DateFilter
result = searcher.search(query1, df1);
assertEquals(0, result.length());