src/ext/default.c
/* recursively calculate score for each token, summing up sub tokens */
recursively calculate score for each token, summing up sub tokens
recursively calculate score for each token summing up sub tokens
static double bm25Recursive(const ScoringFunctionArgs *ctx, const RSIndexResult *r,
                            const RSDocumentMetadata *dmd) {
  static const float b = 0.5;
  static const float k1 = 1.2;
  double f = (double)r->freq;
  if (r->type == RSResultType_Term) {
    double idf = (r->term.term ? r->term.term->idf : 0);
    double ret = idf * f / (f + k1 * (1.0f - b + b * ctx->indexStats.avgDocLen));
    return ret;
  }
  if (r->type & (RSResultType_Intersection | RSResultType_Union)) {
    double ret = 0;
    for (int i = 0; i < r->agg.numChildren; i++) {
      ret += bm25Recursive(ctx, r->agg.children[i], dmd);
    }
    return r->weight * ret;
  }
  return r->weight * (r->freq ? f / (f + k1 * (1.0f - b + b * ctx->indexStats.avgDocLen)) : 0);
}
static double bm25Recursive ( const ScoringFunctionArgs * ctx , const RSIndexResult * r , const RSDocumentMetadata * dmd ) { static const float b = 0.5 ; static const float k1 = 1.2 ; double f = ( double ) r -> freq ; if ( r -> type == RSResultType_Term ) { double idf = ( r -> term . term ? r -> term . term -> idf : 0 ) ; double ret = idf * f / ( f + k1 * ( 1.0f - b + b * ctx -> indexStats . avgDocLen ) ) ; return ret ; } if ( r -> type & ( RSResultType_Intersection | RSResultType_Union ) ) { double ret = 0 ; for ( int i = 0 ; i < r -> agg . numChildren ; i ++ ) { ret += bm25Recursive ( ctx , r -> agg . children [ i ] , dmd ) ; } return r -> weight * ret ; } return r -> weight * ( r -> freq ? f / ( f + k1 * ( 1.0f - b + b * ctx -> indexStats . avgDocLen ) ) : 0 ) ; }
recursively calculate score for each token, summing up sub tokens
recursively calculate score for each token summing up sub tokens
// default for virtual type -just disregard the idf