14
14
// You should have received a copy of the GNU Affero General Public License
15
15
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
16
17
+ //! Scorers are used to compute the ranking signals in the ranking pipeline.
18
+ //!
19
+ //! Each scorer computes a single signal which is then used to rank the pages.
20
+
17
21
pub mod embedding;
18
22
pub mod inbound_similarity;
19
23
pub mod lambdamart;
@@ -26,14 +30,23 @@ use crate::ranking::{SignalCalculation, SignalCoefficients, SignalEnum};
26
30
27
31
use super :: { RankableWebpage , Top } ;
28
32
33
+ /// A ranking stage that computes some signals for each page.
34
+ ///
35
+ /// This trait is implemented for all scorers.
36
+ /// Most of the time you will want to implement the [`RankingStage`] trait instead,
37
+ /// but this trait gives you more control over the ranking pipeline.
29
38
pub trait FullRankingStage : Send + Sync {
30
39
type Webpage : RankableWebpage ;
31
40
41
+ /// Compute the signal for each page.
32
42
fn compute ( & self , webpages : & mut [ Self :: Webpage ] ) ;
33
- fn top_n ( & self ) -> Top {
43
+
44
+ /// The number of pages to return from this part of the pipeline.
45
+ fn top ( & self ) -> Top {
34
46
Top :: Unlimited
35
47
}
36
48
49
+ /// Update the score for each page.
37
50
fn update_scores ( & self , webpages : & mut [ Self :: Webpage ] , coefficients : & SignalCoefficients ) {
38
51
for webpage in webpages. iter_mut ( ) {
39
52
webpage. set_raw_score ( webpage. signals ( ) . iter ( ) . fold ( 0.0 , |acc, ( signal, calc) | {
@@ -42,16 +55,21 @@ pub trait FullRankingStage: Send + Sync {
42
55
}
43
56
}
44
57
58
+ /// Rank the pages by their score.
45
59
fn rank ( & self , webpages : & mut [ Self :: Webpage ] ) {
46
60
webpages. sort_by ( |a, b| b. score ( ) . partial_cmp ( & a. score ( ) ) . unwrap ( ) ) ;
47
61
}
48
62
}
49
63
64
+ /// A ranking stage that computes a single signal for each page.
50
65
pub trait RankingStage : Send + Sync {
51
66
type Webpage : RankableWebpage ;
52
67
68
+ /// Compute the signal for a single page.
53
69
fn compute ( & self , webpage : & Self :: Webpage ) -> ( SignalEnum , SignalCalculation ) ;
54
- fn top_n ( & self ) -> Top {
70
+
71
+ /// The number of pages to return from this part of the pipeline.
72
+ fn top ( & self ) -> Top {
55
73
Top :: Unlimited
56
74
}
57
75
}
69
87
}
70
88
}
71
89
72
- fn top_n ( & self ) -> Top {
73
- self . top_n ( )
90
+ fn top ( & self ) -> Top {
91
+ self . top ( )
74
92
}
75
93
}
0 commit comments