| 1 |
|
package org.apache.lucene.search; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
import junit.framework.TestCase; |
| 20 |
|
|
| 21 |
|
import org.apache.lucene.index.IndexWriter; |
| 22 |
|
import org.apache.lucene.queryParser.QueryParser; |
| 23 |
|
import org.apache.lucene.store.RAMDirectory; |
| 24 |
|
import org.apache.lucene.analysis.SimpleAnalyzer; |
| 25 |
|
import org.apache.lucene.document.Document; |
| 26 |
|
import org.apache.lucene.document.Field; |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
@author |
| 31 |
|
@version |
| 32 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 2 |
Complexity Density: 0.15 |
|
| 33 |
|
public class TestNot extends TestCase { |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 34 |
1
|
public TestNot(String name) {... |
| 35 |
1
|
super(name); |
| 36 |
|
} |
| 37 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1
PASS
|
|
| 38 |
1
|
public void testNot() throws Exception {... |
| 39 |
1
|
RAMDirectory store = new RAMDirectory(); |
| 40 |
1
|
IndexWriter writer = new IndexWriter(store, new SimpleAnalyzer(), true); |
| 41 |
|
|
| 42 |
1
|
Document d1 = new Document(); |
| 43 |
1
|
d1.add(new Field("field", "a b", Field.Store.YES, Field.Index.TOKENIZED)); |
| 44 |
|
|
| 45 |
1
|
writer.addDocument(d1); |
| 46 |
1
|
writer.optimize(); |
| 47 |
1
|
writer.close(); |
| 48 |
|
|
| 49 |
1
|
Searcher searcher = new IndexSearcher(store); |
| 50 |
1
|
QueryParser parser = new QueryParser("field", new SimpleAnalyzer()); |
| 51 |
1
|
Query query = parser.parse("a NOT b"); |
| 52 |
|
|
| 53 |
1
|
Hits hits = searcher.search(query); |
| 54 |
1
|
assertEquals(0, hits.length()); |
| 55 |
|
} |
| 56 |
|
} |