Mailing List Archive

r3799 - in trunk: c_src/KinoSearch/Search perl/t
Author: creamyg
Date: 2008-08-29 21:25:27 -0700 (Fri, 29 Aug 2008)
New Revision: 3799

Modified:
trunk/c_src/KinoSearch/Search/NOTScorer.bp
trunk/c_src/KinoSearch/Search/NOTScorer.c
trunk/c_src/KinoSearch/Search/ORQuery.c
trunk/c_src/KinoSearch/Search/ORScorer.bp
trunk/c_src/KinoSearch/Search/ORScorer.c
trunk/c_src/KinoSearch/Search/RequiredOptionalScorer.bp
trunk/c_src/KinoSearch/Search/RequiredOptionalScorer.c
trunk/perl/t/518-or_scorer.t
Log:
Make ORScorer, RequiredOptionalScorer, and NOTScorer subclasses of PolyScorer.
Change scoring routines for ORScorer and RequiredOptionalScorer so that they
apply the Sim_Coord() bonus.


Modified: trunk/c_src/KinoSearch/Search/NOTScorer.bp
===================================================================
--- trunk/c_src/KinoSearch/Search/NOTScorer.bp 2008-08-30 02:00:52 UTC (rev 3798)
+++ trunk/c_src/KinoSearch/Search/NOTScorer.bp 2008-08-30 04:25:27 UTC (rev 3799)
@@ -3,7 +3,7 @@
/** Return the inverse of a Scorer's set. Scores are always 0.
*/

-class KinoSearch::Search::NOTScorer extends KinoSearch::Search::Scorer {
+class KinoSearch::Search::NOTScorer extends KinoSearch::Search::PolyScorer {

Scorer *negated_scorer;
IndexReader *reader;

Modified: trunk/c_src/KinoSearch/Search/NOTScorer.c
===================================================================
--- trunk/c_src/KinoSearch/Search/NOTScorer.c 2008-08-30 02:00:52 UTC (rev 3798)
+++ trunk/c_src/KinoSearch/Search/NOTScorer.c 2008-08-30 04:25:27 UTC (rev 3799)
@@ -17,7 +17,11 @@
NOTScorer*
NOTScorer_init(NOTScorer *self, Scorer *negated_scorer, IndexReader *reader)
{
- Scorer_init((Scorer*)self, NULL);
+ Schema *schema = IxReader_Get_Schema(reader);
+ Similarity *sim = Schema_Fetch_Sim(schema, NULL);
+ VArray *children = VA_new(1);
+ VA_Push(children, (Obj*)negated_scorer);
+ PolyScorer_init((PolyScorer*)self, children, sim);

/* Assign. */
self->negated_scorer = REFCOUNT_INC(negated_scorer);
@@ -42,7 +46,7 @@
REFCOUNT_DEC(self->negated_scorer);
REFCOUNT_DEC(self->reader);
REFCOUNT_DEC(self->tally);
- Scorer_destroy((Scorer*)self);
+ PolyScorer_destroy((PolyScorer*)self);
}

i32_t

Modified: trunk/c_src/KinoSearch/Search/ORQuery.c
===================================================================
--- trunk/c_src/KinoSearch/Search/ORQuery.c 2008-08-30 02:00:52 UTC (rev 3798)
+++ trunk/c_src/KinoSearch/Search/ORQuery.c 2008-08-30 04:25:27 UTC (rev 3799)
@@ -101,8 +101,8 @@
return subscorer;
}
else {
- ORScorer *retval = ORScorer_new(Compiler_Get_Similarity(self),
- subscorers);
+ ORScorer *retval = ORScorer_new(subscorers,
+ Compiler_Get_Similarity(self));
REFCOUNT_DEC(subscorers);
return (Scorer*)retval;
}

Modified: trunk/c_src/KinoSearch/Search/ORScorer.bp
===================================================================
--- trunk/c_src/KinoSearch/Search/ORScorer.bp 2008-08-30 02:00:52 UTC (rev 3798)
+++ trunk/c_src/KinoSearch/Search/ORScorer.bp 2008-08-30 04:25:27 UTC (rev 3799)
@@ -7,22 +7,20 @@
* whenever they match the same document.
*/

-class KinoSearch::Search::ORScorer extends KinoSearch::Search::Scorer {
+class KinoSearch::Search::ORScorer extends KinoSearch::Search::PolyScorer {

Tally *tally;
- VArray *subscorers;
ScorerDocQueue *q;
- u32_t num_subs;
float *scores;
i32_t doc_num;

/* Constructors/initializers.
*/
static incremented ORScorer*
- new(Similarity *similarity, VArray* sub_scorers);
+ new(VArray *children, Similarity *similarity);

static ORScorer*
- init(ORScorer *self, Similarity *similarity, VArray* subscorers);
+ init(ORScorer *self, VArray *children, Similarity *similarity);

void
Destroy(ORScorer *self);

Modified: trunk/c_src/KinoSearch/Search/ORScorer.c
===================================================================
--- trunk/c_src/KinoSearch/Search/ORScorer.c 2008-08-30 02:00:52 UTC (rev 3798)
+++ trunk/c_src/KinoSearch/Search/ORScorer.c 2008-08-30 04:25:27 UTC (rev 3799)
@@ -16,35 +16,27 @@
advance_after_current(ORScorer *self);

ORScorer*
-ORScorer_new(Similarity *sim, VArray *subscorers)
+ORScorer_new(VArray *children, Similarity *sim)
{
ORScorer *self = (ORScorer*)CREATE(NULL, ORSCORER);
- return ORScorer_init(self, sim, subscorers);
+ return ORScorer_init(self, children, sim);
}

ORScorer*
-ORScorer_init(ORScorer *self, Similarity *sim, VArray *subscorers)
+ORScorer_init(ORScorer *self, VArray *children, Similarity *sim)
{
u32_t i;

- Scorer_init((Scorer*)self, sim);
-
- /* Assign. */
- self->subscorers = REFCOUNT_INC(subscorers);
-
/* Init. */
+ PolyScorer_init((PolyScorer*)self, children, sim);
self->doc_num = 0;
self->tally = Tally_new();
- self->q = NULL;
+ self->scores = MALLOCATE(self->num_kids, float);

- /* Derive. */
- self->num_subs = subscorers->size;
- self->scores = MALLOCATE(self->num_subs, float);
-
/* Initialize ScorerDocQueue. */
- self->q = ScorerDocQ_new(subscorers->size);
- for (i = 0; i < subscorers->size; i++) {
- Scorer *scorer = (Scorer*)VA_Fetch(subscorers, i);
+ self->q = ScorerDocQ_new(children->size);
+ for (i = 0; i < children->size; i++) {
+ Scorer *scorer = (Scorer*)VA_Fetch(children, i);
if (Scorer_Next(scorer)) {
ScorerDocQ_Put(self->q, scorer);
}
@@ -58,9 +50,8 @@
{
REFCOUNT_DEC(self->tally);
REFCOUNT_DEC(self->q);
- REFCOUNT_DEC(self->subscorers);
free(self->scores);
- Scorer_destroy((Scorer*)self);
+ PolyScorer_destroy((PolyScorer*)self);
}

i32_t
@@ -70,7 +61,8 @@
}

static i32_t
-advance_after_current(ORScorer *self) {
+advance_after_current(ORScorer *self)
+{
ScorerDocQueue *const q = self->q;
float *const scores = self->scores;
Tally *const tally = self->tally;
@@ -150,11 +142,12 @@
Tally *const tally = self->tally;
float *const scores = self->scores;

- /* Accumulate score. */
+ /* Accumulate score, then factor in coord bonus. */
tally->score = 0.0;
for (i = 0; i < tally->num_matchers; i++) {
tally->score += scores[i];
}
+ tally->score *= self->coord_factors[tally->num_matchers];

return self->tally;
}

Modified: trunk/c_src/KinoSearch/Search/RequiredOptionalScorer.bp
===================================================================
--- trunk/c_src/KinoSearch/Search/RequiredOptionalScorer.bp 2008-08-30 02:00:52 UTC (rev 3798)
+++ trunk/c_src/KinoSearch/Search/RequiredOptionalScorer.bp 2008-08-30 04:25:27 UTC (rev 3799)
@@ -4,7 +4,7 @@
*/

class KinoSearch::Search::RequiredOptionalScorer cnick ReqOptScorer
- extends KinoSearch::Search::Scorer {
+ extends KinoSearch::Search::PolyScorer {

Tally *tally;
Scorer *req_scorer; /* required scorer */

Modified: trunk/c_src/KinoSearch/Search/RequiredOptionalScorer.c
===================================================================
--- trunk/c_src/KinoSearch/Search/RequiredOptionalScorer.c 2008-08-30 02:00:52 UTC (rev 3798)
+++ trunk/c_src/KinoSearch/Search/RequiredOptionalScorer.c 2008-08-30 04:25:27 UTC (rev 3799)
@@ -18,7 +18,10 @@
ReqOptScorer_init(RequiredOptionalScorer *self, Similarity *similarity,
Scorer *required_scorer, Scorer *optional_scorer)
{
- Scorer_init((Scorer*)self, similarity);
+ VArray *children = VA_new(2);
+ VA_Push(children, (Obj*)required_scorer);
+ VA_Push(children, (Obj*)optional_scorer);
+ PolyScorer_init((PolyScorer*)self, children, similarity);

/* Assign. */
self->req_scorer = REFCOUNT_INC(required_scorer);
@@ -26,7 +29,8 @@

/* Init. */
self->opt_scorer_first_time = true;
- self->tally = Tally_new();
+ self->tally = Tally_new();
+ self->tally->num_matchers = 2; /* only used when both match */

return self;
}
@@ -37,7 +41,7 @@
REFCOUNT_DEC(self->tally);
REFCOUNT_DEC(self->req_scorer);
REFCOUNT_DEC(self->opt_scorer);
- Scorer_destroy((Scorer*)self);
+ PolyScorer_destroy((PolyScorer*)self);
}

i32_t
@@ -92,9 +96,7 @@
Tally *const or_tally = Scorer_Tally(self->opt_scorer);

tally->score = and_tally->score + or_tally->score;
- tally->num_matchers
- = and_tally->num_matchers + or_tally->num_matchers;
-
+ tally->score *= self->coord_factors[2];
return tally;
}
else {

Modified: trunk/perl/t/518-or_scorer.t
===================================================================
--- trunk/perl/t/518-or_scorer.t 2008-08-30 02:00:52 UTC (rev 3798)
+++ trunk/perl/t/518-or_scorer.t 2008-08-30 04:25:27 UTC (rev 3799)
@@ -37,7 +37,7 @@

my $or_scorer = KinoSearch::Search::ORScorer->new(
similarity => $sim,
- subscorers => $subscorers,
+ children => $subscorers,
);
my $collector = KinoSearch::Search::HitCollector::TopDocCollector->new(
size => 100 );


_______________________________________________
kinosearch-commits mailing list
kinosearch-commits@rectangular.com
http://www.rectangular.com/mailman/listinfo/kinosearch-commits