Skip to content
Snippets Groups Projects
Commit 7148de1f authored by Teodor Sigaev's avatar Teodor Sigaev
Browse files

Prevent to divide by zero and range out of 0..1

parent a91fa390
No related branches found
No related tags found
No related merge requests found
......@@ -288,6 +288,7 @@ calc_rank(float *w, tsvector * t, QUERYTYPE * q, int4 method)
{
ITEM *item = GETQUERY(q);
float res = 0.0;
int len;
if (!t->size || !q->size)
return 0.0;
......@@ -303,10 +304,11 @@ calc_rank(float *w, tsvector * t, QUERYTYPE * q, int4 method)
case 0:
break;
case 1:
res /= log((float) cnt_length(t));
res /= log( (float)(cnt_length(t)+1) ) / log(2.0);
break;
case 2:
res /= (float) cnt_length(t);
len = cnt_length(t);
if ( len > 0 ) res /= (float)len;
break;
default:
/* internal error */
......@@ -609,10 +611,11 @@ rank_cd(PG_FUNCTION_ARGS)
case 0:
break;
case 1:
res /= log((float) cnt_length(txt));
res /= log( (float)(cnt_length(txt)+1) );
break;
case 2:
res /= (float) cnt_length(txt);
len = cnt_length(txt);
if ( len > 0 ) res /= (float)len;
break;
default:
/* internal error */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment