01: package org.apache.lucene.search;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: import org.apache.lucene.util.LuceneTestCase;
21:
22: import org.apache.lucene.index.IndexWriter;
23: import org.apache.lucene.queryParser.QueryParser;
24: import org.apache.lucene.store.RAMDirectory;
25: import org.apache.lucene.analysis.SimpleAnalyzer;
26: import org.apache.lucene.document.Document;
27: import org.apache.lucene.document.Field;
28:
29: /** Similarity unit test.
30: *
31: *
32: * @version $Revision: 583534 $
33: */
34: public class TestNot extends LuceneTestCase {
35: public TestNot(String name) {
36: super (name);
37: }
38:
39: public void testNot() throws Exception {
40: RAMDirectory store = new RAMDirectory();
41: IndexWriter writer = new IndexWriter(store,
42: new SimpleAnalyzer(), true);
43:
44: Document d1 = new Document();
45: d1.add(new Field("field", "a b", Field.Store.YES,
46: Field.Index.TOKENIZED));
47:
48: writer.addDocument(d1);
49: writer.optimize();
50: writer.close();
51:
52: Searcher searcher = new IndexSearcher(store);
53: QueryParser parser = new QueryParser("field",
54: new SimpleAnalyzer());
55: Query query = parser.parse("a NOT b");
56: //System.out.println(query);
57: Hits hits = searcher.search(query);
58: assertEquals(0, hits.length());
59: }
60: }
|