|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MultiPhraseQuery | Line # 40 | 61 | 30 | 88% |
0.8796296
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MultiPhraseQuery.MultiPhraseWeight | Line # 127 | 60 | 16 | 94.3% |
0.9425287
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (20) | |||
| Result | |||
|
0.8051282
|
org.apache.lucene.search.TestSimpleExplanations.testMPQ6
org.apache.lucene.search.TestSimpleExplanations.testMPQ6
|
1 PASS | |
|
0.7846154
|
org.apache.lucene.search.TestSimpleExplanations.testMPQ2
org.apache.lucene.search.TestSimpleExplanations.testMPQ2
|
1 PASS | |
|
0.7846154
|
org.apache.lucene.search.TestSimpleExplanations.testMPQ1
org.apache.lucene.search.TestSimpleExplanations.testMPQ1
|
1 PASS | |
|
0.7641026
|
org.apache.lucene.search.TestSimpleExplanations.testMPQ3
org.apache.lucene.search.TestSimpleExplanations.testMPQ3
|
1 PASS | |
|
0.73846155
|
org.apache.lucene.search.TestSimpleExplanations.testMPQ5
org.apache.lucene.search.TestSimpleExplanations.testMPQ5
|
1 PASS | |
|
0.73846155
|
org.apache.lucene.search.TestSimpleExplanations.testMPQ2
org.apache.lucene.search.TestSimpleExplanations.testMPQ2
|
1 PASS | |
|
0.73333335
|
org.apache.lucene.search.TestComplexExplanations.testMPQ7
org.apache.lucene.search.TestComplexExplanations.testMPQ7
|
1 PASS | |
|
0.71794873
|
org.apache.lucene.search.TestSimpleExplanations.testMPQ4
org.apache.lucene.search.TestSimpleExplanations.testMPQ4
|
1 PASS | |
|
0.6974359
|
org.apache.lucene.search.TestComplexExplanations.testMPQ7
org.apache.lucene.search.TestComplexExplanations.testMPQ7
|
1 PASS | |
|
0.6923077
|
org.apache.lucene.search.TestSimpleExplanations.testMPQ5
org.apache.lucene.search.TestSimpleExplanations.testMPQ5
|
1 PASS | |
|
0.6717949
|
org.apache.lucene.search.TestSimpleExplanations.testMPQ4
org.apache.lucene.search.TestSimpleExplanations.testMPQ4
|
1 PASS | |
|
0.5897436
|
org.apache.lucene.search.TestMultiPhraseQuery.testPhrasePrefix
org.apache.lucene.search.TestMultiPhraseQuery.testPhrasePrefix
|
1 PASS | |
|
0.3794872
|
org.apache.lucene.search.TestPhrasePrefixQuery.testPhrasePrefix
org.apache.lucene.search.TestPhrasePrefixQuery.testPhrasePrefix
|
1 PASS | |
|
0.3794872
|
org.apache.lucene.search.TestMultiPhraseQuery.testPhrasePrefixWithBooleanQuery
org.apache.lucene.search.TestMultiPhraseQuery.testPhrasePrefixWithBooleanQuery
|
1 PASS | |
|
0.30769232
|
org.apache.lucene.queryParser.TestMultiAnalyzer.testMultiAnalyzer
org.apache.lucene.queryParser.TestMultiAnalyzer.testMultiAnalyzer
|
1 PASS | |
|
0.2871795
|
org.apache.lucene.search.TestSimpleExplanations.testMPQ6
org.apache.lucene.search.TestSimpleExplanations.testMPQ6
|
1 PASS | |
|
0.2871795
|
org.apache.lucene.queryParser.TestMultiAnalyzer.testMultiAnalyzerWithSubclassOfQueryParser
org.apache.lucene.queryParser.TestMultiAnalyzer.testMultiAnalyzerWithSubclassOfQueryParser
|
1 PASS | |
|
0.26666668
|
org.apache.lucene.search.TestSimpleExplanations.testMPQ1
org.apache.lucene.search.TestSimpleExplanations.testMPQ1
|
1 PASS | |
|
0.25641027
|
org.apache.lucene.search.TestSimpleExplanations.testMPQ3
org.apache.lucene.search.TestSimpleExplanations.testMPQ3
|
1 PASS | |
|
0.13846155
|
org.apache.lucene.search.TestMultiPhraseQuery.testBooleanQueryContainingSingleTermPrefixQuery
org.apache.lucene.search.TestMultiPhraseQuery.testBooleanQueryContainingSingleTermPrefixQuery
|
1 PASS | |
| 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 java.io.IOException; | |
| 20 | import java.util.*; | |
| 21 | ||
| 22 | import org.apache.lucene.index.IndexReader; | |
| 23 | import org.apache.lucene.index.MultipleTermPositions; | |
| 24 | import org.apache.lucene.index.Term; | |
| 25 | import org.apache.lucene.index.TermPositions; | |
| 26 | import org.apache.lucene.search.Query; | |
| 27 | import org.apache.lucene.util.ToStringUtils; | |
| 28 | ||
| 29 | /** | |
| 30 | * MultiPhraseQuery is a generalized version of PhraseQuery, with an added | |
| 31 | * method {@link #add(Term[])}. | |
| 32 | * To use this class, to search for the phrase "Microsoft app*" first use | |
| 33 | * add(Term) on the term "Microsoft", then find all terms that have "app" as | |
| 34 | * prefix using IndexReader.terms(Term), and use MultiPhraseQuery.add(Term[] | |
| 35 | * terms) to add them to the query. | |
| 36 | * | |
| 37 | * @author Anders Nielsen | |
| 38 | * @version 1.0 | |
| 39 | */ | |
| 40 | public class MultiPhraseQuery extends Query { | |
| 41 | private String field; | |
| 42 | private ArrayList termArrays = new ArrayList(); | |
| 43 | private Vector positions = new Vector(); | |
| 44 | ||
| 45 | private int slop = 0; | |
| 46 | ||
| 47 | /** Sets the phrase slop for this query. | |
| 48 | * @see PhraseQuery#setSlop(int) | |
| 49 | */ | |
| 50 | 27 |
public void setSlop(int s) { slop = s; } |
| 51 | ||
| 52 | /** Sets the phrase slop for this query. | |
| 53 | * @see PhraseQuery#getSlop() | |
| 54 | */ | |
| 55 | 0 |
public int getSlop() { return slop; } |
| 56 | ||
| 57 | /** Add a single term at the next position in the phrase. | |
| 58 | * @see PhraseQuery#add(Term) | |
| 59 | */ | |
| 60 | 8 |
public void add(Term term) { add(new Term[]{term}); } |
| 61 | ||
| 62 | /** Add multiple terms at the next position in the phrase. Any of the terms | |
| 63 | * may match. | |
| 64 | * | |
| 65 | * @see PhraseQuery#add(Term) | |
| 66 | */ | |
| 67 | 67 |
public void add(Term[] terms) { |
| 68 | 67 | int position = 0; |
| 69 | 67 | if (positions.size() > 0) |
| 70 | 34 | position = ((Integer) positions.lastElement()).intValue() + 1; |
| 71 | ||
| 72 | 67 | add(terms, position); |
| 73 | } | |
| 74 | ||
| 75 | /** | |
| 76 | * Allows to specify the relative position of terms within the phrase. | |
| 77 | * | |
| 78 | * @see PhraseQuery#add(Term, int) | |
| 79 | * @param terms | |
| 80 | * @param position | |
| 81 | */ | |
| 82 | 67 |
public void add(Term[] terms, int position) { |
| 83 | 67 | if (termArrays.size() == 0) |
| 84 | 33 | field = terms[0].field(); |
| 85 | ||
| 86 | 168 | for (int i = 0; i < terms.length; i++) { |
| 87 | 102 | if (terms[i].field() != field) { |
| 88 | 1 | throw new IllegalArgumentException( |
| 89 | "All phrase terms must be in the same field (" + field + "): " | |
| 90 | + terms[i]); | |
| 91 | } | |
| 92 | } | |
| 93 | ||
| 94 | 66 | termArrays.add(terms); |
| 95 | 66 | positions.addElement(new Integer(position)); |
| 96 | } | |
| 97 | ||
| 98 | /** | |
| 99 | * Retu | |