|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MultiTermQuery | Line # 38 | 29 | 12 | 83% |
0.82978725
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (10) | |||
| Result | |||
|
0.42553192
|
org.apache.lucene.search.TestWildcard.testQuestionmark
org.apache.lucene.search.TestWildcard.testQuestionmark
|
1 PASS | |
|
0.42553192
|
org.apache.lucene.search.TestWildcard.testAsterisk
org.apache.lucene.search.TestWildcard.testAsterisk
|
1 PASS | |
|
0.27659574
|
org.apache.lucene.queryParser.TestMultiFieldQueryParser.testSimple
org.apache.lucene.queryParser.TestMultiFieldQueryParser.testSimple
|
1 PASS | |
|
0.27659574
|
org.apache.lucene.queryParser.TestQueryParser.testEscaped
org.apache.lucene.queryParser.TestQueryParser.testEscaped
|
1 PASS | |
|
0.23404256
|
org.apache.lucene.search.TestWildcard.testEquals
org.apache.lucene.search.TestWildcard.testEquals
|
1 PASS | |
|
0.23404256
|
org.apache.lucene.queryParser.TestQueryParser.testWildcard
org.apache.lucene.queryParser.TestQueryParser.testWildcard
|
1 PASS | |
|
0.08510638
|
org.apache.lucene.search.TestFuzzyQuery.testFuzzinessLong
org.apache.lucene.search.TestFuzzyQuery.testFuzzinessLong
|
1 PASS | |
|
0.08510638
|
org.apache.lucene.search.TestFuzzyQuery.testFuzziness
org.apache.lucene.search.TestFuzzyQuery.testFuzziness
|
1 PASS | |
|
0.08510638
|
org.apache.lucene.queryParser.TestMultiFieldQueryParser.testAnalyzerReturningNull
org.apache.lucene.queryParser.TestMultiFieldQueryParser.testAnalyzerReturningNull
|
1 PASS | |
|
0.08510638
|
org.apache.lucene.search.TestMultiSearcherRanking.testFuzzyQuery
org.apache.lucene.search.TestMultiSearcherRanking.testFuzzyQuery
|
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 | ||
| 21 | import org.apache.lucene.index.IndexReader; | |
| 22 | import org.apache.lucene.index.Term; | |
| 23 | import org.apache.lucene.util.ToStringUtils; | |
| 24 | ||
| 25 | /** | |
| 26 | * A {@link Query} that matches documents containing a subset of terms provided | |
| 27 | * by a {@link FilteredTermEnum} enumeration. | |
| 28 | * <P> | |
| 29 | * <code>MultiTermQuery</code> is not designed to be used by itself. | |
| 30 | * <BR> | |
| 31 | * The reason being that it is not intialized with a {@link FilteredTermEnum} | |
| 32 | * enumeration. A {@link FilteredTermEnum} enumeration needs to be provided. | |
| 33 | * <P> | |
| 34 | * For example, {@link WildcardQuery} and {@link FuzzyQuery} extend | |
| 35 | * <code>MultiTermQuery</code> to provide {@link WildcardTermEnum} and | |
| 36 | * {@link FuzzyTermEnum}, respectively. | |
| 37 | */ | |
| 38 | public abstract class MultiTermQuery extends Query { | |
| 39 | private Term term; | |
| 40 | ||
| 41 | /** Constructs a query for terms matching <code>term</code>. */ | |
| 42 | 99 |
public MultiTermQuery(Term term) { |
| 43 | 99 | this.term = term; |
| 44 | } | |
| 45 | ||
| 46 | /** Returns the pattern term. */ | |
| 47 | 75 |
public Term getTerm() { return term; } |
| 48 | ||
| 49 | /** Construct the enumeration to be used, expanding the pattern term. */ | |
| 50 | protected abstract FilteredTermEnum getEnum(IndexReader reader) | |
| 51 | throws IOException; | |
| 52 | ||
| 53 | 17 |
public Query rewrite(IndexReader reader) throws IOException { |
| 54 | 17 | FilteredTermEnum enumerator = getEnum(reader); |
| 55 | 17 | BooleanQuery query = new BooleanQuery(true); |
| 56 | 17 | try { |
| 57 | 17 | do { |
| 58 | 22 | Term t = enumerator.term(); |
| 59 | 22 | if (t != null) { |
| 60 | 18 | TermQuery tq = new TermQuery(t); // found a match |
| 61 | 18 | tq.setBoost(getBoost() * enumerator.difference()); // set the boost |
| 62 | 18 | query.add(tq, BooleanClause.Occur.SHOULD); // add to query |
| 63 | } | |
| 64 | 22 | } while (enumerator.next()); |
| 65 | } finally { | |
| 66 | 17 | enumerator.close(); |
| 67 | } | |
| 68 | 17 | return query; |
| 69 | } | |
| 70 | ||
| 71 | /** Prints a user-readable version of this query. */ | |
| 72 | 18 |
public String toString(String field) { |
| 73 | 18 | StringBuffer buffer = new StringBuffer(); |
| 74 | 18 | if (!term.field().equals(field)) { |
| 75 | 5 | buffer.append(term.field()); |
| 76 | 5 | buffer.append(":"); |
| 77 | } | |
| 78 | 18 | buffer.append(term.text()); |
| 79 | 18 | buffer.append(ToStringUtils.boost(getBoost())); |
| 80 | 18 | return buffer.toString(); |
| 81 | } | |
| 82 | ||
| 83 | 4 |
public boolean equals(Object o) { |
| 84 | 0 | if (this == o) return true; |
| 85 | 0 | if (!(o instanceof MultiTermQuery)) return false; |
| 86 | ||
| 87 | 4 | final MultiTermQuery multiTermQuery = (MultiTermQuery) o; |
| 88 | ||
| 89 | 0 | if (!term.equals(multiTermQuery.term)) return false; |
| 90 | ||
| 91 | 4 | return getBoost() == multiTermQuery.getBoost(); |
| 92 | } | |
| 93 | ||
| 94 | 0 |
public int hashCode() { |
| 95 | 0 | return term.hashCode() + Float.floatToRawIntBits(getBoost()); |
| 96 | } | |
| 97 | } | |
|
||||||||||