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.
18 using Explanation
= Lucene
.Net
.Search
.Explanation
;
19 using Scorer
= Lucene
.Net
.Search
.Scorer
;
20 using Similarity
= Lucene
.Net
.Search
.Similarity
;
21 using Weight
= Lucene
.Net
.Search
.Weight
;
23 namespace Lucene
.Net
.Search
.Spans
27 class SpanScorer
: Scorer
30 private Weight weight
;
32 private float value_Renamed
;
34 private bool firstTime
= true;
35 private bool more
= true;
40 internal SpanScorer(Spans spans
, Weight weight
, Similarity similarity
, byte[] norms
) : base(similarity
)
45 this.value_Renamed
= weight
.GetValue();
48 public override bool Next()
62 while (more
&& doc
== spans
.Doc())
64 int matchLength
= spans
.End() - spans
.Start();
65 freq
+= GetSimilarity().SloppyFreq(matchLength
);
69 return more
|| freq
!= 0.0f
;
72 public override int Doc()
77 public override float Score()
79 float raw
= GetSimilarity().Tf(freq
) * value_Renamed
; // raw score
80 return raw
* Similarity
.DecodeNorm(norms
[doc
]); // normalize
83 public override bool SkipTo(int target
)
85 more
= spans
.SkipTo(target
);
93 while (more
&& spans
.Doc() == target
)
95 freq
+= GetSimilarity().SloppyFreq(spans
.End() - spans
.Start());
99 return more
|| freq
!= 0.0f
;
102 public override Explanation
Explain(int doc
)
104 Explanation tfExplanation
= new Explanation();
108 float phraseFreq
= (Doc() == doc
)?freq
:0.0f
;
109 tfExplanation
.SetValue(GetSimilarity().Tf(phraseFreq
));
110 tfExplanation
.SetDescription("tf(phraseFreq=" + phraseFreq
+ ")");
112 return tfExplanation
;