2 * Copyright 2004 The Apache Software Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 using Explanation
= Lucene
.Net
.Search
.Explanation
;
18 using Scorer
= Lucene
.Net
.Search
.Scorer
;
19 using Similarity
= Lucene
.Net
.Search
.Similarity
;
20 using Weight
= Lucene
.Net
.Search
.Weight
;
21 namespace Lucene
.Net
.Search
.Spans
25 class SpanScorer
:Scorer
28 private Weight weight
;
30 private float value_Renamed
;
32 private bool firstTime
= true;
33 private bool more
= true;
38 internal SpanScorer(Spans spans
, Weight weight
, Similarity similarity
, byte[] norms
) : base(similarity
)
43 this.value_Renamed
= weight
.Value
;
46 public override bool Next()
60 while (more
&& doc
== spans
.Doc())
62 int matchLength
= spans
.End() - spans
.Start();
63 freq
+= GetSimilarity().SloppyFreq(matchLength
);
67 return more
|| freq
!= 0.0f
;
70 public override int Doc()
75 public override float Score()
77 float raw
= GetSimilarity().Tf(freq
) * value_Renamed
; // raw score
78 return raw
* Similarity
.DecodeNorm(norms
[doc
]); // normalize
81 public override bool SkipTo(int target
)
83 more
= spans
.SkipTo(target
);
91 while (more
&& spans
.Doc() == target
)
93 freq
+= GetSimilarity().SloppyFreq(spans
.End() - spans
.Start());
97 return more
|| freq
!= 0.0f
;
100 public override Explanation
Explain(int doc
)
102 Explanation tfExplanation
= new Explanation();
106 float phraseFreq
= (Doc() == doc
)?freq
:0.0f
;
107 tfExplanation
.SetValue(GetSimilarity().Tf(phraseFreq
));
108 tfExplanation
.SetDescription("tf(phraseFreq=" + phraseFreq
+ ")");
110 return tfExplanation
;