KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > search > ExactPhraseScorer


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 JavaDoc;
20 import org.apache.lucene.index.*;
21
22 final class ExactPhraseScorer extends PhraseScorer {
23
24   ExactPhraseScorer(Weight weight, TermPositions[] tps, int[] positions, Similarity similarity,
25                     byte[] norms) {
26     super(weight, tps, positions, similarity, norms);
27   }
28
29   protected final float phraseFreq() throws IOException JavaDoc {
30     // sort list with pq
31
for (PhrasePositions pp = first; pp != null; pp = pp.next) {
32       pp.firstPosition();
33       pq.put(pp); // build pq from list
34
}
35     pqToList(); // rebuild list from pq
36

37     int freq = 0;
38     do { // find position w/ all terms
39
while (first.position < last.position) { // scan forward in first
40
do {
41       if (!first.nextPosition())
42         return (float)freq;
43     } while (first.position < last.position);
44     firstToLast();
45       }
46       freq++; // all equal: a match
47
} while (last.nextPosition());
48   
49     return (float)freq;
50   }
51 }
52
Popular Tags