1 package org.apache.lucene.search; 2 3 18 19 import junit.framework.TestCase; 20 21 import java.util.Vector ; 22 23 import org.apache.lucene.index.Term; 24 import org.apache.lucene.index.IndexWriter; 25 import org.apache.lucene.queryParser.QueryParser; 26 import org.apache.lucene.store.RAMDirectory; 27 import org.apache.lucene.analysis.SimpleAnalyzer; 28 import org.apache.lucene.document.Document; 29 import org.apache.lucene.document.Field; 30 31 36 public class TestNot extends TestCase { 37 public TestNot(String name) { 38 super(name); 39 } 40 41 public void testNot() throws Exception { 42 RAMDirectory store = new RAMDirectory(); 43 IndexWriter writer = new IndexWriter(store, new SimpleAnalyzer(), true); 44 45 Document d1 = new Document(); 46 d1.add(Field.Text("field", "a b")); 47 48 writer.addDocument(d1); 49 writer.optimize(); 50 writer.close(); 51 52 Searcher searcher = new IndexSearcher(store); 53 Query query = QueryParser.parse("a NOT b", "field", new SimpleAnalyzer()); 54 Hits hits = searcher.search(query); 56 assertEquals(0, hits.length()); 57 } 58 } 59 | Popular Tags |