KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > search > TestNot


1 package org.apache.lucene.search;
2
3 /**
4  * Copyright 2004 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import junit.framework.TestCase;
20
21 import java.util.Vector JavaDoc;
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 /** Similarity unit test.
32  *
33  * @author Doug Cutting
34  * @version $Revision: 1.3 $
35  */

36 public class TestNot extends TestCase {
37   public TestNot(String JavaDoc name) {
38     super(name);
39   }
40
41   public void testNot() throws Exception JavaDoc {
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     //System.out.println(query);
55
Hits hits = searcher.search(query);
56     assertEquals(0, hits.length());
57   }
58 }
59
Popular Tags