
marvin at rectangular
Sep 18, 2008, 9:20 PM
Post #1 of 1
(2436 views)
Permalink
|
|
r3882 - trunk/c_src/KinoSearch/Posting
|
|
Author: creamyg Date: 2008-09-18 21:20:03 -0700 (Thu, 18 Sep 2008) New Revision: 3882 Modified: trunk/c_src/KinoSearch/Posting/MatchPosting.bp trunk/c_src/KinoSearch/Posting/MatchPosting.c Log: Factor in TF and IDF (but not boost) in MatchPostingScorer. This is only for testing and benchmarking purposes -- MatchPostingScorer should really produce a constant score. Modified: trunk/c_src/KinoSearch/Posting/MatchPosting.bp =================================================================== --- trunk/c_src/KinoSearch/Posting/MatchPosting.bp 2008-09-19 03:48:00 UTC (rev 3881) +++ trunk/c_src/KinoSearch/Posting/MatchPosting.bp 2008-09-19 04:20:03 UTC (rev 3882) @@ -52,9 +52,17 @@ class KinoSearch::Posting::MatchPostingScorer cnick MatchPostScorer extends KinoSearch::Search::TermScorer { + float *score_cache; + static MatchPostingScorer* init(MatchPostingScorer *self, Similarity *similarity, PostingList *posting_list, Compiler *compiler); + + public Tally* + Tally(MatchPostingScorer *self); + + void + Destroy(MatchPostingScorer *self); } /* Copyright 2007-2008 Marvin Humphrey Modified: trunk/c_src/KinoSearch/Posting/MatchPosting.c =================================================================== --- trunk/c_src/KinoSearch/Posting/MatchPosting.c 2008-09-19 03:48:00 UTC (rev 3881) +++ trunk/c_src/KinoSearch/Posting/MatchPosting.c 2008-09-19 04:20:03 UTC (rev 3882) @@ -9,6 +9,7 @@ #include "KinoSearch/Posting/RawPosting.h" #include "KinoSearch/Search/Similarity.h" #include "KinoSearch/Search/Compiler.h" +#include "KinoSearch/Search/Tally.h" #include "KinoSearch/Store/InStream.h" #include "KinoSearch/Util/MemoryPool.h" @@ -116,12 +117,44 @@ MatchPostingScorer* MatchPostScorer_init(MatchPostingScorer *self, Similarity *sim, - PostingList *plist, Compiler *compiler) + PostingList *plist, Compiler *compiler) { - return (MatchPostingScorer*)TermScorer_init((TermScorer*)self, sim, - plist, 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; } +Tally* +MatchPostScorer_tally(MatchPostingScorer* self) +{ + Tally *const tally = self->tally; + MatchPosting *const posting = (MatchPosting*)self->posting; + const u32_t freq = posting->freq; + + /* Calculate initial score based on frequency of term. */ + tally->score = (freq < TERMSCORER_SCORE_CACHE_SIZE) + ? self->score_cache[freq] /* cache hit */ + : Sim_TF(self->sim, (float)freq) * self->weight; + + return tally; +} + +void +MatchPostScorer_destroy(MatchPostingScorer *self) +{ + free(self->score_cache); + TermScorer_destroy((TermScorer*)self); +} + /* Copyright 2007-2008 Marvin Humphrey * * This program is free software; you can redistribute it and/or modify _______________________________________________ kinosearch-commits mailing list kinosearch-commits [at] rectangular http://www.rectangular.com/mailman/listinfo/kinosearch-commits
|