Lucene.Net
3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
Main Page
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Properties
Pages
core
Search
Scorer.cs
Go to the documentation of this file.
1
/*
2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*/
17
18
using
System;
19
using
Lucene.Net.Index;
20
21
namespace
Lucene.Net.Search
22
{
23
24
/// <summary> Expert: Common scoring functionality for different types of queries.
25
///
26
/// <p/>
27
/// A <c>Scorer</c> iterates over documents matching a
28
/// query in increasing order of doc Id.
29
/// <p/>
30
/// <p/>
31
/// Document scores are computed using a given <c>Similarity</c>
32
/// implementation.
33
/// <p/>
34
///
35
/// <p/><b>NOTE</b>: The values Float.Nan,
36
/// Float.NEGATIVE_INFINITY and Float.POSITIVE_INFINITY are
37
/// not valid scores. Certain collectors (eg <see cref="TopScoreDocCollector" />
38
///) will not properly collect hits
39
/// with these scores.
40
/// </summary>
41
public
abstract
class
Scorer
:
DocIdSetIterator
42
{
43
private
Similarity
similarity;
44
45
/// <summary>Constructs a Scorer.</summary>
46
/// <param name="similarity">The <c>Similarity</c> implementation used by this scorer.
47
/// </param>
48
protected
internal
Scorer
(
Similarity
similarity)
49
{
50
this.similarity = similarity;
51
}
52
53
/// <summary>Returns the Similarity implementation used by this scorer. </summary>
54
public
virtual
Similarity
Similarity
55
{
56
get
{
return
this.similarity; }
57
}
58
59
/// <summary>Scores and collects all matching documents.</summary>
60
/// <param name="collector">The collector to which all matching documents are passed.
61
/// </param>
62
public
virtual
void
Score(
Collector
collector)
63
{
64
collector.
SetScorer
(
this
);
65
int
doc;
66
while
((doc = NextDoc()) != NO_MORE_DOCS)
67
{
68
collector.
Collect
(doc);
69
}
70
}
71
72
/// <summary> Expert: Collects matching documents in a range. Hook for optimization.
73
/// Note, <paramref name="firstDocID" /> is added to ensure that <see cref="DocIdSetIterator.NextDoc()" />
74
/// was called before this method.
75
///
76
/// </summary>
77
/// <param name="collector">The collector to which all matching documents are passed.
78
/// </param>
79
/// <param name="max">Do not score documents past this.
80
/// </param>
81
/// <param name="firstDocID">
82
/// The first document ID (ensures <see cref="DocIdSetIterator.NextDoc()" /> is called before
83
/// this method.
84
/// </param>
85
/// <returns> true if more matching documents may remain.
86
/// </returns>
87
public
/*protected internal*/
virtual
bool
Score(
Collector
collector,
int
max,
int
firstDocID)
88
{
89
collector.
SetScorer
(
this
);
90
int
doc = firstDocID;
91
while
(doc < max)
92
{
93
collector.
Collect
(doc);
94
doc = NextDoc();
95
}
96
return
doc != NO_MORE_DOCS;
97
}
98
99
/// <summary>Returns the score of the current document matching the query.
100
/// Initially invalid, until <see cref="DocIdSetIterator.NextDoc()" /> or <see cref="DocIdSetIterator.Advance(int)" />
101
/// is called the first time, or when called from within
102
/// <see cref="Collector.Collect(int)" />.
103
/// </summary>
104
public
abstract
float
Score();
105
}
106
}
Generated on Thu Jan 3 2013 02:34:12 for Lucene.Net by
1.8.3