lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject cvs commit: jakarta-lucene/src/test/org/apache/lucene/search TestDateFilter.java
Date Fri, 19 Apr 2002 20:29:19 GMT
otis        02/04/19 13:29:19

  Modified:    src/test/org/apache/lucene/search TestDateFilter.java
  Log:
  - Added tests for DateFilter.After method.
  
  Revision  Changes    Path
  1.2       +59 -1     jakarta-lucene/src/test/org/apache/lucene/search/TestDateFilter.java
  
  Index: TestDateFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/search/TestDateFilter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestDateFilter.java	19 Apr 2002 20:15:25 -0000	1.1
  +++ TestDateFilter.java	19 Apr 2002 20:29:19 -0000	1.2
  @@ -73,7 +73,7 @@
     * DateFilter JUnit tests.
     *
     * @author Otis Gospodnetic
  -  * @version $Revision: 1.1 $
  +  * @version $Revision: 1.2 $
     */
   public class TestDateFilter
       extends TestCase
  @@ -110,6 +110,64 @@
   
   	// filter that should discard matches
   	DateFilter df2 = DateFilter.Before("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());
  +
  +	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"));
  
  
  

--
To unsubscribe, e-mail:   <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>


Mime
View raw message