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 java.io.IOException;
21: import org.apache.lucene.index.*;
22:
23: final class ExactPhraseScorer extends PhraseScorer {
24:
25: ExactPhraseScorer(Weight weight, TermPositions[] tps,
26: int[] offsets, Similarity similarity, byte[] norms) {
27: super (weight, tps, offsets, similarity, norms);
28: }
29:
30: protected final float phraseFreq() throws IOException {
31: // sort list with pq
32: pq.clear();
33: for (PhrasePositions pp = first; pp != null; pp = pp.next) {
34: pp.firstPosition();
35: pq.put(pp); // build pq from list
36: }
37: pqToList(); // rebuild list from pq
38:
39: // for counting how many times the exact phrase is found in current document,
40: // just count how many times all PhrasePosition's have exactly the same position.
41: int freq = 0;
42: do { // find position w/ all terms
43: while (first.position < last.position) { // scan forward in first
44: do {
45: if (!first.nextPosition())
46: return (float) freq;
47: } while (first.position < last.position);
48: firstToLast();
49: }
50: freq++; // all equal: a match
51: } while (last.nextPosition());
52:
53: return (float) freq;
54: }
55: }
|