src/ext/default.c
/* HAMMING - Scorer using Hamming distance between the query payload and the document payload. Only
 * works if both have the payloads the same length */
Scorer using Hamming distance between the query payload and the document payload. Only
works if both have the payloads the same length
Scorer using Hamming distance between the query payload and the document payload . Only works if both have the payloads the same length
static double HammingDistanceScorer(const ScoringFunctionArgs *ctx, const RSIndexResult *h,
                                    const RSDocumentMetadata *dmd, double minScore) {
  if (!dmd->payload || !dmd->payload->len || dmd->payload->len != ctx->qdatalen) {
    return 0;
  }
  size_t ret = 0;
  size_t len = ctx->qdatalen;
  const unsigned char *a = (unsigned char *)ctx->qdata;
  const unsigned char *b = (unsigned char *)dmd->payload->data;
  for (size_t i = 0; i < len; i++) {
    ret += bitsinbyte[(unsigned char)(a[i] ^ b[i])];
  }
  return 1.0 / (double)(ret + 1);
}
static double HammingDistanceScorer ( const ScoringFunctionArgs * ctx , const RSIndexResult * h , const RSDocumentMetadata * dmd , double minScore ) { if ( ! dmd -> payload || ! dmd -> payload -> len || dmd -> payload -> len != ctx -> qdatalen ) { return 0 ; } size_t ret = 0 ; size_t len = ctx -> qdatalen ; const unsigned char * a = ( unsigned char * ) ctx -> qdata ; const unsigned char * b = ( unsigned char * ) dmd -> payload -> data ; for ( size_t i = 0 ; i < len ; i ++ ) { ret += bitsinbyte [ ( unsigned char ) ( a [ i ] ^ b [ i ] ) ] ; } return 1.0 / ( double ) ( ret + 1 ) ; }
HAMMING - Scorer using Hamming distance between the query payload and the document payload.
HAMMING - Scorer using Hamming distance between the query payload and the document payload .
// the strings must be of the same length > 0 // if the strings are not aligned to 64 bit - calculate the diff byte by // we inverse the distance, and add 1 to make sure a distance of 0 yields a perfect score of 1