Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: kinosearch: commits
r3881 - trunk/c_src/KinoSearch/Search/HitCollector
 

Index | Next | Previous | View Flat


marvin at rectangular

Sep 18, 2008, 8:48 PM


Views: 2626
Permalink
r3881 - trunk/c_src/KinoSearch/Search/HitCollector

Author: creamyg
Date: 2008-09-18 20:48:00 -0700 (Thu, 18 Sep 2008)
New Revision: 3881

Modified:
trunk/c_src/KinoSearch/Search/HitCollector/SortCollector.c
trunk/c_src/KinoSearch/Search/HitCollector/TopDocCollector.bp
trunk/c_src/KinoSearch/Search/HitCollector/TopDocCollector.c
Log:
Add a recyclable ScoreDoc/FieldDoc to TopDocCollector/SortCollector, so that
it can be reinserted with a new score and doc num, instead of needing to
construct a fresh ScoreDoc each insertion. This matters quite a bit when the
scores are constant, as with a TermScorer for a MatchPosting field.


Modified: trunk/c_src/KinoSearch/Search/HitCollector/SortCollector.c
===================================================================
--- trunk/c_src/KinoSearch/Search/HitCollector/SortCollector.c 2008-09-19 03:35:26 UTC (rev 3880)
+++ trunk/c_src/KinoSearch/Search/HitCollector/SortCollector.c 2008-09-19 03:48:00 UTC (rev 3881)
@@ -17,19 +17,15 @@
SortCollector*
SortColl_init(SortCollector *self, FieldDocCollator *collator, u32_t num_hits)
{
- HC_init((HitCollector*)self);
-
/* Init. */
- self->min_doc = -1;
- self->min_score = 0.0f;
- self->total_hits = 0;
- self->num_hits = 0;
+ TDColl_init((TopDocCollector*)self, num_hits);
+ self->min_doc = 0;

/* Assign. */
- self->num_hits = num_hits;
- self->collator = REFCOUNT_INC(collator);
+ self->collator = REFCOUNT_INC(collator);

/* Derive. */
+ REFCOUNT_DEC(self->hit_q);
self->hit_q = (HitQueue*)SortedHitQ_new(num_hits);

return self;
@@ -39,8 +35,7 @@
SortColl_destroy(SortCollector *self)
{
REFCOUNT_DEC(self->collator);
- REFCOUNT_DEC(self->hit_q);
- FREE_OBJ(self);
+ TDColl_destroy((TopDocCollector*)self);
}

void
@@ -57,18 +52,26 @@
return;
}
else {
- FieldDoc *const field_doc
- = FieldDoc_new(doc_num, tally->score, self->collator);
SortedHitQueue *const hit_q = (SortedHitQueue*)self->hit_q;

- SortedHitQ_Insert(hit_q, (Obj*)field_doc);
- REFCOUNT_DEC(field_doc);
+ if (self->bumped) {
+ FieldDoc *const field_doc = (FieldDoc*)self->bumped;
+ field_doc->doc_num = doc_num;
+ field_doc->score = tally->score;
+ self->bumped = (ScoreDoc*)HitQ_Jostle(hit_q, (Obj*)field_doc);
+ REFCOUNT_DEC(field_doc);
+ }
+ else {
+ FieldDoc *const field_doc
+ = FieldDoc_new(doc_num, tally->score, self->collator);
+ self->bumped = (ScoreDoc*)HitQ_Jostle(hit_q, (Obj*)field_doc);
+ REFCOUNT_DEC(field_doc);
+ }

/* Store the bubble score in a more accessible spot. */
- if (hit_q->size == hit_q->max_size) {
- FieldDoc *const least = (FieldDoc*)SortedHitQ_Peek(hit_q);
- self->min_doc = least->doc_num;
- self->min_score = least->score;
+ if (self->bumped) {
+ self->min_doc = self->bumped->doc_num;
+ self->min_score = self->bumped->score;
}
}
}

Modified: trunk/c_src/KinoSearch/Search/HitCollector/TopDocCollector.bp
===================================================================
--- trunk/c_src/KinoSearch/Search/HitCollector/TopDocCollector.bp 2008-09-19 03:35:26 UTC (rev 3880)
+++ trunk/c_src/KinoSearch/Search/HitCollector/TopDocCollector.bp 2008-09-19 03:48:00 UTC (rev 3881)
@@ -13,6 +13,7 @@
u32_t num_hits;
u32_t total_hits;
HitQueue *hit_q;
+ ScoreDoc *bumped;

static incremented TopDocCollector*
new(u32_t size);

Modified: trunk/c_src/KinoSearch/Search/HitCollector/TopDocCollector.c
===================================================================
--- trunk/c_src/KinoSearch/Search/HitCollector/TopDocCollector.c 2008-09-19 03:35:26 UTC (rev 3880)
+++ trunk/c_src/KinoSearch/Search/HitCollector/TopDocCollector.c 2008-09-19 03:48:00 UTC (rev 3881)
@@ -20,6 +20,7 @@
/* Init. */
self->min_score = 0.0;
self->total_hits = 0;
+ self->bumped = NULL;

/* Assign. */
self->num_hits = num_hits;
@@ -33,6 +34,7 @@
void
TDColl_destroy(TopDocCollector *self)
{
+ REFCOUNT_DEC(self->bumped);
REFCOUNT_DEC(self->hit_q);
FREE_OBJ(self);
}
@@ -45,21 +47,29 @@

/* Bail if the score doesn't exceed the minimum. */
if ( self->total_hits > self->num_hits
- && tally->score < self->min_score
+ && tally->score <= self->min_score
) {
return;
}
else if (self->num_hits > 0) {
- ScoreDoc *const score_doc = ScoreDoc_new(doc_num, tally->score);
- HitQueue *const hit_q = self->hit_q;
+ HitQueue *const hit_q = self->hit_q;

- HitQ_Insert(hit_q, (Obj*)score_doc);
- REFCOUNT_DEC(score_doc);
+ if (self->bumped) {
+ ScoreDoc *const score_doc = self->bumped;
+ score_doc->doc_num = doc_num;
+ score_doc->score = tally->score;
+ self->bumped = (ScoreDoc*)HitQ_Jostle(hit_q, (Obj*)score_doc);
+ REFCOUNT_DEC(score_doc);
+ }
+ else {
+ ScoreDoc *const score_doc = ScoreDoc_new(doc_num, tally->score);
+ self->bumped = (ScoreDoc*)HitQ_Jostle(hit_q, (Obj*)score_doc);
+ REFCOUNT_DEC(score_doc);
+ }

/* Store the bubble score in a more accessible spot. */
- if (hit_q->size == hit_q->max_size) {
- ScoreDoc *const least = (ScoreDoc*)HitQ_Peek(hit_q);
- self->min_score = least->score;
+ if (self->bumped) {
+ self->min_score = self->bumped->score;
}
}
}


_______________________________________________
kinosearch-commits mailing list
kinosearch-commits [at] rectangular
http://www.rectangular.com/mailman/listinfo/kinosearch-commits

Subject User Time
r3881 - trunk/c_src/KinoSearch/Search/HitCollector marvin at rectangular Sep 18, 2008, 8:48 PM

  Index | Next | Previous | View Flat
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.