Пример #1
0
float
MatchPostScorer_score(MatchPostingScorer* self) 
{
    MatchPosting *const posting = (MatchPosting*)self->posting;
    const u32_t  freq           = posting->freq;
    float score = (freq < TERMSCORER_SCORE_CACHE_SIZE) 
        ? self->score_cache[freq] /* cache hit */
        : Sim_TF(self->sim, (float)freq) * self->weight;
    return score;
}
Пример #2
0
ScorePostingMatcher*
ScorePostMatcher_init(ScorePostingMatcher *self, Similarity *sim,
                      PostingList *plist, Compiler *compiler) {
    // Init.
    TermMatcher_init((TermMatcher*)self, sim, plist, compiler);
    ScorePostingMatcherIVARS *const ivars = ScorePostMatcher_IVARS(self);

    // Fill score cache.
    ivars->score_cache = (float*)MALLOCATE(TERMMATCHER_SCORE_CACHE_SIZE * sizeof(float));
    for (uint32_t i = 0; i < TERMMATCHER_SCORE_CACHE_SIZE; i++) {
        ivars->score_cache[i] = Sim_TF(sim, (float)i) * ivars->weight;
    }

    return self;
}
Пример #3
0
MatchPostingScorer*
MatchPostScorer_init(MatchPostingScorer *self, Similarity *sim,
                     PostingList *plist, Compiler *compiler)
{
    u32_t i;

    /* Init. */
    TermScorer_init((TermScorer*)self, sim, plist, compiler);

    /* Fill score cache. */
    self->score_cache = MALLOCATE(TERMSCORER_SCORE_CACHE_SIZE, float);
    for (i = 0; i < TERMSCORER_SCORE_CACHE_SIZE; i++) {
        self->score_cache[i] = Sim_TF(sim, (float)i) * self->weight;
    }

    return self;
}
Пример #4
0
float
ScorePostMatcher_Score_IMP(ScorePostingMatcher* self) {
    ScorePostingMatcherIVARS *const ivars = ScorePostMatcher_IVARS(self);
    ScorePostingIVARS *const posting_ivars
        = ScorePost_IVARS((ScorePosting*)ivars->posting);
    const uint32_t freq = posting_ivars->freq;

    // Calculate initial score based on frequency of term.
    float score = (freq < TERMMATCHER_SCORE_CACHE_SIZE)
                  ? ivars->score_cache[freq] // cache hit
                  : Sim_TF(ivars->sim, (float)freq) * ivars->weight;

    // Factor in field-length normalization and doc/field/prox boost.
    score *= posting_ivars->weight;

    return score;
}