|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TestBooleanMinShouldMatch | Line # 35 | 163 | 32 | 91.9% |
0.9186603
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| (14) | |||
| Result | |||
|
0.22966507
|
org.apache.lucene.search.TestBooleanMinShouldMatch.testRandomQueries
org.apache.lucene.search.TestBooleanMinShouldMatch.testRandomQueries
|
1 PASS | |
|
0.086124405
|
org.apache.lucene.search.TestBooleanMinShouldMatch.testSomeReqSomeProhibAndSomeOptional
org.apache.lucene.search.TestBooleanMinShouldMatch.testSomeReqSomeProhibAndSomeOptional
|
1 PASS | |
|
0.086124405
|
org.apache.lucene.search.TestBooleanMinShouldMatch.testMinHigherThenNumOptional
org.apache.lucene.search.TestBooleanMinShouldMatch.testMinHigherThenNumOptional
|
1 PASS | |
|
0.08133971
|
org.apache.lucene.search.TestBooleanMinShouldMatch.testSomeReqOneProhibAndSomeOptional
org.apache.lucene.search.TestBooleanMinShouldMatch.testSomeReqOneProhibAndSomeOptional
|
1 PASS | |
|
0.08133971
|
org.apache.lucene.search.TestBooleanMinShouldMatch.testOneReqSomeProhibAndSomeOptional
org.apache.lucene.search.TestBooleanMinShouldMatch.testOneReqSomeProhibAndSomeOptional
|
1 PASS | |
|
0.07655502
|
org.apache.lucene.search.TestBooleanMinShouldMatch.testOneReqOneProhibAndSomeOptional
org.apache.lucene.search.TestBooleanMinShouldMatch.testOneReqOneProhibAndSomeOptional
|
1 PASS | |
|
0.07177033
|
org.apache.lucene.search.TestBooleanMinShouldMatch.testSomeReqAndSomeOptional
org.apache.lucene.search.TestBooleanMinShouldMatch.testSomeReqAndSomeOptional
|
1 PASS | |
|
0.07177033
|
org.apache.lucene.search.TestBooleanMinShouldMatch.testSomeProhibAndSomeOptional
org.apache.lucene.search.TestBooleanMinShouldMatch.testSomeProhibAndSomeOptional
|
1 PASS | |
|
0.066985644
|
org.apache.lucene.search.TestBooleanMinShouldMatch.testOneProhibAndSomeOptional
org.apache.lucene.search.TestBooleanMinShouldMatch.testOneProhibAndSomeOptional
|
1 PASS | |
|
0.066985644
|
org.apache.lucene.search.TestBooleanMinShouldMatch.testAllOptional
org.apache.lucene.search.TestBooleanMinShouldMatch.testAllOptional
|
1 PASS | |
|
0.066985644
|
org.apache.lucene.search.TestBooleanMinShouldMatch.testOneReqAndSomeOptional
org.apache.lucene.search.TestBooleanMinShouldMatch.testOneReqAndSomeOptional
|
1 PASS | |
|
0.066985644
|
org.apache.lucene.search.TestBooleanMinShouldMatch.testMinEqualToNumOptional
org.apache.lucene.search.TestBooleanMinShouldMatch.testMinEqualToNumOptional
|
1 PASS | |
|
0.062200956
|
org.apache.lucene.search.TestBooleanMinShouldMatch.testOneOptionalEqualToMin
org.apache.lucene.search.TestBooleanMinShouldMatch.testOneOptionalEqualToMin
|
1 PASS | |
|
0.057416268
|
org.apache.lucene.search.TestBooleanMinShouldMatch.testNoOptionalButMin
org.apache.lucene.search.TestBooleanMinShouldMatch.testNoOptionalButMin
|
1 PASS | |
| 1 | package org.apache.lucene.search; | |
| 2 | ||
| 3 | /** | |
| 4 | * Copyright 2005 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 | ||
| 20 | import junit.framework.TestCase; | |
| 21 | import org.apache.lucene.analysis.WhitespaceAnalyzer; | |
| 22 | import org.apache.lucene.document.Document; | |
| 23 | import org.apache.lucene.document.Field; | |
| 24 | import org.apache.lucene.index.IndexReader; | |
| 25 | import org.apache.lucene.index.IndexWriter; | |
| 26 | import org.apache.lucene.index.Term; | |
| 27 | import org.apache.lucene.store.Directory; | |
| 28 | import org.apache.lucene.store.RAMDirectory; | |
| 29 | ||
| 30 | import java.text.DecimalFormat; | |
| 31 | import java.util.Random; | |
| 32 | ||
| 33 | /** Test that BooleanQuery.setMinimumNumberShouldMatch works. | |
| 34 | */ | |
| 35 | public class TestBooleanMinShouldMatch extends TestCase { | |
| 36 | ||
| 37 | ||
| 38 | public Directory index; | |
| 39 | public IndexReader r; | |
| 40 | public IndexSearcher s; | |
| 41 | ||
| 42 | 14 |
public void setUp() throws Exception { |
| 43 | ||
| 44 | ||
| 45 | 14 | String[] data = new String [] { |
| 46 | "A 1 2 3 4 5 6", | |
| 47 | "Z 4 5 6", | |
| 48 | null, | |
| 49 | "B 2 4 5 6", | |
| 50 | "Y 3 5 6", | |
| 51 | null, | |
| 52 | "C 3 6", | |
| 53 | "X 4 5 6" | |
| 54 | }; | |
| 55 | ||
| 56 | 14 | index = new RAMDirectory(); |
| 57 | 14 | IndexWriter writer = new IndexWriter(index, |
| 58 | new WhitespaceAnalyzer(), | |
| 59 | true); | |
| 60 | ||
| 61 | 126 | for (int i = 0; i < data.length; i++) { |
| 62 | 112 | Document doc = new Document(); |
| 63 | 112 | doc.add(new Field("id", String.valueOf(i), Field.Store.YES, Field.Index.UN_TOKENIZED));//Field.Keyword("id",String.valueOf(i))); |
| 64 | 112 | doc.add(new Field("all", "all", Field.Store.YES, Field.Index.UN_TOKENIZED));//Field.Keyword("all","all")); |
| 65 | 112 | if (null != data[i]) { |
| 66 | 84 | doc.add(new Field("data", data[i], Field.Store.YES, Field.Index.TOKENIZED));//Field.Text("data",data[i])); |
| 67 | } | |
| 68 | 112 | writer.addDocument(doc); |
| 69 | } | |
| 70 | ||
| 71 | 14 | writer.optimize(); |
| 72 | 14 | writer.close(); |
| 73 | ||
| 74 | 14 | r = IndexReader.open(index); |
| 75 | 14 | s = new IndexSearcher(r); |
| 76 | ||
| 77 | //System.out.println("Set up " + getName()); | |
| 78 | } | |
| 79 | ||
| 80 | 13 |
public void verifyNrHits(Query q, int expected) throws Exception { |
| 81 | 13 | Hits h = s.search(q); |
| 82 | 13 | if (expected != h.length()) { |
| 83 | 0 | printHits(getName(), h); |
| 84 | } | |
| 85 | 13 | assertEquals("result count", expected, h.length()); |
| 86 | 13 | QueryUtils.check(q,s); |
| 87 | } | |
| 88 | ||
| 89 | 1 |
public void testAllOptional() throws Exception { |
| 90 | ||
| 91 | 1 | BooleanQuery q = new BooleanQuery(); |
| 92 | 5 | for (int i = 1; i <=4; i++) { |
| 93 | 4 | q.add(new TermQuery(new Term("data",""+i)), BooleanClause.Occur.SHOULD);//false, false); |
| 94 | } | |
| 95 | 1 | q.setMinimumNumberShouldMatch(2); // match at least two of 4 |
| 96 | 1 | verifyNrHits(q, 2); |
| 97 | } | |
| 98 | ||
| 99 | 1 |
public void testOneReqAndSomeOptional() throws Exception { |
| 100 | ||
| 101 | /* one required, some optional */ | |
| 102 | 1 | BooleanQuery q = new BooleanQuery(); |
| 103 | 1 | q.add(new TermQuery(new Term("all", "all" )), BooleanClause.Occur.MUST);//true, false); |
| 104 | 1 | q.add(new TermQuery(new Term("data", "5" )), BooleanClause.Occur.SHOULD);//false, false); |
| 105 | 1 | q.add(new TermQuery(new Term("data", "4" )), BooleanClause.Occur.SHOULD);//false, false); |
| 106 | 1 | q.add(new TermQuery(new Term("data", "3" )), BooleanClause.Occur.SHOULD);//false, false); |
| 107 | ||
| 108 | 1 | q.setMinimumNumberShouldMatch(2); // 2 of 3 optional |
| 109 | ||
| 110 | 1 | verifyNrHits(q, 5); |
| 111 | } | |
| 112 | ||
| 113 | 1 |
public void testSomeReqAndSomeOptional() throws Exception { |
| 114 | ||
| 115 | /* two required, some optional */ | |
| 116 | 1 | BooleanQuery q = new |