Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8ea2c02

Browse files
committed
correct distnce calcs
1 parent790c362 commit8ea2c02

File tree

4 files changed

+69
-31
lines changed

4 files changed

+69
-31
lines changed

‎expected/rum.out

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ SELECT rum_ts_distance(a, to_tsquery('pg_catalog.english', 'way')), *
9696
ORDER BY a <-> to_tsquery('pg_catalog.english', 'way');
9797
rum_ts_distance | t | a
9898
-----------------+--------------------------------------------------------------------------+---------------------------------------------------------------
99-
0.0607927 | my appreciation of you in a more complimentary way than by sending this | 'appreci':2 'complimentari':8 'send':12 'way':9
100-
0.0607927 | itself. Put on your “specs” and look at the castle, half way up the | 'castl':10 'half':11 'look':7 'put':2 'spec':5 'way':12
101-
0.0607927 | so well that only a fragment, as it were, gave way. It still hangs as if | 'fragment':6 'gave':10 'hang':14 'still':13 'way':11 'well':2
102-
0.0607927 | thinking--“to go or not to go?” We are this far on the way. Reached | 'far':11 'go':3,7 'reach':15 'think':1 'way':14
99+
16.4493 | my appreciation of you in a more complimentary way than by sending this | 'appreci':2 'complimentari':8 'send':12 'way':9
100+
16.4493 | itself. Put on your “specs” and look at the castle, half way up the | 'castl':10 'half':11 'look':7 'put':2 'spec':5 'way':12
101+
16.4493 | so well that only a fragment, as it were, gave way. It still hangs as if | 'fragment':6 'gave':10 'hang':14 'still':13 'way':11 'well':2
102+
16.4493 | thinking--“to go or not to go?” We are this far on the way. Reached | 'far':11 'go':3,7 'reach':15 'think':1 'way':14
103103
(4 rows)
104104

105105
SELECT rum_ts_distance(a, to_tsquery('pg_catalog.english', 'way & (go | half)')), *
@@ -108,10 +108,22 @@ SELECT rum_ts_distance(a, to_tsquery('pg_catalog.english', 'way & (go | half)'))
108108
ORDER BY a <-> to_tsquery('pg_catalog.english', 'way & (go | half)');
109109
rum_ts_distance | t | a
110110
-----------------+---------------------------------------------------------------------+---------------------------------------------------------
111-
0.103556 | thinking--“to go or not to go?” We are this far on the way. Reached | 'far':11 'go':3,7 'reach':15 'think':1 'way':14
112-
0.0991032 | itself. Put on your “specs” and look at the castle, half way up the | 'castl':10 'half':11 'look':7 'put':2 'spec':5 'way':12
111+
9.65659 | thinking--“to go or not to go?” We are this far on the way. Reached | 'far':11 'go':3,7 'reach':15 'think':1 'way':14
112+
10.0905 | itself. Put on your “specs” and look at the castle, half way up the | 'castl':10 'half':11 'look':7 'put':2 'spec':5 'way':12
113113
(2 rows)
114114

115+
SELECT rum_ts_distance(a, to_tsquery('pg_catalog.english', 'way & (go | half)')), *
116+
FROM test_rum
117+
ORDER BY a <-> to_tsquery('pg_catalog.english', 'way & (go | half)') limit 5;
118+
rum_ts_distance | t | a
119+
-----------------+--------------------------------------------------------------------------+-------------------------------------------------------------------
120+
9.65659 | thinking--“to go or not to go?” We are this far on the way. Reached | 'far':11 'go':3,7 'reach':15 'think':1 'way':14
121+
10.0905 | itself. Put on your “specs” and look at the castle, half way up the | 'castl':10 'half':11 'look':7 'put':2 'spec':5 'way':12
122+
1e+20 | so well that only a fragment, as it were, gave way. It still hangs as if | 'fragment':6 'gave':10 'hang':14 'still':13 'way':11 'well':2
123+
1e+20 | my appreciation of you in a more complimentary way than by sending this | 'appreci':2 'complimentari':8 'send':12 'way':9
124+
1e+20 | but is an ancient structure (1592) in the Renaissance style, and one of | '1592':6 'ancient':4 'one':12 'renaiss':9 'structur':5 'style':10
125+
(5 rows)
126+
115127
INSERT INTO test_rum (t) VALUES ('foo bar foo the over foo qq bar');
116128
INSERT INTO test_rum (t) VALUES ('345 qwerty copyright');
117129
INSERT INTO test_rum (t) VALUES ('345 qwerty');

‎rum_ts_utils.c

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ PG_FUNCTION_INFO_V1(rum_tsquery_timestamp_consistent);
3030
PG_FUNCTION_INFO_V1(rum_tsquery_distance);
3131
PG_FUNCTION_INFO_V1(rum_ts_distance);
3232

33-
staticfloatcalc_rank_pos_and(float*w,Datum*addInfo,bool*addInfoIsNull,
34-
intsize);
35-
staticfloatcalc_rank_pos_or(float*w,Datum*addInfo,bool*addInfoIsNull,
36-
intsize);
33+
staticfloatcalc_rank_pos_and(float*w,bool*check,
34+
Datum*addInfo,bool*addInfoIsNull,intsize);
35+
staticfloatcalc_rank_pos_or(float*w,bool*check,
36+
Datum*addInfo,bool*addInfoIsNull,intsize);
3737

3838
staticintcount_pos(char*ptr,intlen);
3939
staticchar*decompress_pos(char*ptr,uint16*pos);
@@ -330,7 +330,7 @@ count_pos(char *ptr, int len)
330330
}
331331

332332
staticfloat
333-
calc_rank_pos_and(float*w,Datum*addInfo,bool*addInfoIsNull,intsize)
333+
calc_rank_pos_and(float*w,bool*check,Datum*addInfo,bool*addInfoIsNull,intsize)
334334
{
335335
inti,
336336
k,
@@ -345,13 +345,13 @@ calc_rank_pos_and(float *w, Datum *addInfo, bool *addInfoIsNull, int size)
345345
char*ptrt,*ptrc;
346346

347347
if (size<2)
348-
{
349-
returncalc_rank_pos_or(w,addInfo,addInfoIsNull,size);
350-
}
351-
WEP_SETPOS(POSNULL.pos[0],MAXENTRYPOS-1);
348+
returncalc_rank_pos_or(w,check,addInfo,addInfoIsNull,size);
352349

353350
for (i=0;i<size;i++)
354351
{
352+
if (!check[i])
353+
continue;
354+
355355
if (!addInfoIsNull[i])
356356
{
357357
dimt=count_pos(VARDATA_ANY(addInfo[i]),VARSIZE_ANY_EXHDR(addInfo[i]));
@@ -371,15 +371,21 @@ calc_rank_pos_and(float *w, Datum *addInfo, bool *addInfoIsNull, int size)
371371
post=0;
372372
for (l=0;l<dimt;l++)
373373
{
374-
ptrt=decompress_pos(ptrt,&post);
374+
if (ptrt== (char*)POSNULL.pos)
375+
post=POSNULL.pos[0];
376+
else
377+
ptrt=decompress_pos(ptrt,&post);
375378
ct=0;
376379
if (!addInfoIsNull[k])
377380
ptrc= (char*)VARDATA_ANY(addInfo[k]);
378381
else
379382
ptrc= (char*)POSNULL.pos;
380383
for (p=0;p<lenct;p++)
381384
{
382-
ptrc=decompress_pos(ptrc,&ct);
385+
if (ptrc== (char*)POSNULL.pos)
386+
ct=POSNULL.pos[0];
387+
else
388+
ptrc=decompress_pos(ptrc,&ct);
383389
dist=Abs((int)WEP_GETPOS(post)- (int)WEP_GETPOS(ct));
384390
if (dist|| (dist==0&& (ptrt== (char*)POSNULL.pos||ptrc== (char*)POSNULL.pos)))
385391
{
@@ -399,7 +405,7 @@ calc_rank_pos_and(float *w, Datum *addInfo, bool *addInfoIsNull, int size)
399405
}
400406

401407
staticfloat
402-
calc_rank_pos_or(float*w,Datum*addInfo,bool*addInfoIsNull,intsize)
408+
calc_rank_pos_or(float*w,bool*check,Datum*addInfo,bool*addInfoIsNull,intsize)
403409
{
404410
WordEntryPospost;
405411
int32dimt,
@@ -414,6 +420,9 @@ calc_rank_pos_or(float *w, Datum *addInfo, bool *addInfoIsNull, int size)
414420
wjm;
415421
int32jm;
416422

423+
if (!check[i])
424+
continue;
425+
417426
if (!addInfoIsNull[i])
418427
{
419428
dimt=count_pos(VARDATA_ANY(addInfo[i]),VARSIZE_ANY_EXHDR(addInfo[i]));
@@ -431,7 +440,10 @@ calc_rank_pos_or(float *w, Datum *addInfo, bool *addInfoIsNull, int size)
431440
post=0;
432441
for (j=0;j<dimt;j++)
433442
{
434-
ptrt=decompress_pos(ptrt,&post);
443+
if (ptrt== (char*)POSNULL.pos)
444+
post=POSNULL.pos[0];
445+
else
446+
ptrt=decompress_pos(ptrt,&post);
435447
resj=resj+wpos(post) / ((j+1)* (j+1));
436448
if (wpos(post)>wjm)
437449
{
@@ -455,19 +467,21 @@ calc_rank_pos_or(float *w, Datum *addInfo, bool *addInfoIsNull, int size)
455467
}
456468

457469
staticfloat
458-
calc_rank_pos(float*w,TSQueryq,Datum*addInfo,bool*addInfoIsNull,intsize)
470+
calc_rank_pos(float*w,bool*check,TSQueryq,Datum*addInfo,bool*addInfoIsNull,intsize)
459471
{
460472
QueryItem*item=GETQUERY(q);
461473
floatres=0.0;
462474

463475
if (!size|| !q->size)
464476
return0.0;
465477

478+
WEP_SETPOS(POSNULL.pos[0],MAXENTRYPOS-1);
479+
466480
/* XXX: What about NOT? */
467481
res= (item->type==QI_OPR&& (item->qoperator.oper==OP_AND||
468482
item->qoperator.oper==OP_PHRASE)) ?
469-
calc_rank_pos_and(w,addInfo,addInfoIsNull,size) :
470-
calc_rank_pos_or(w,addInfo,addInfoIsNull,size);
483+
calc_rank_pos_and(w,check,addInfo,addInfoIsNull,size) :
484+
calc_rank_pos_or(w,check,addInfo,addInfoIsNull,size);
471485

472486
if (res<0)
473487
res=1e-20f;
@@ -691,18 +705,16 @@ rum_extract_tsquery(PG_FUNCTION_ARGS)
691705
Datum
692706
rum_tsquery_distance(PG_FUNCTION_ARGS)
693707
{
694-
/* bool *check = (bool *) PG_GETARG_POINTER(0); */
695-
708+
bool*check= (bool*)PG_GETARG_POINTER(0);
696709
/* StrategyNumber strategy = PG_GETARG_UINT16(1); */
697710
TSQueryquery=PG_GETARG_TSQUERY(2);
698-
699711
int32nkeys=PG_GETARG_INT32(3);
700-
/*Pointer*extra_data = (Pointer *) PG_GETARG_POINTER(4); */
712+
Pointer*extra_data= (Pointer*)PG_GETARG_POINTER(4);
701713
Datum*addInfo= (Datum*)PG_GETARG_POINTER(8);
702714
bool*addInfoIsNull= (bool*)PG_GETARG_POINTER(9);
703715
float8res;
704716

705-
res=1.0 / (float8)calc_rank_pos(weights,query,
717+
res=1.0 / (float8)calc_rank_pos(weights,check,query,
706718
addInfo,addInfoIsNull,nkeys);
707719

708720
PG_RETURN_FLOAT8(res);
@@ -711,10 +723,15 @@ rum_tsquery_distance(PG_FUNCTION_ARGS)
711723
Datum
712724
rum_ts_distance(PG_FUNCTION_ARGS)
713725
{
714-
returnDirectFunctionCall2Coll(ts_rank_tt,
715-
PG_GET_COLLATION(),
716-
PG_GETARG_DATUM(0),
717-
PG_GETARG_DATUM(1));
726+
float4r=DatumGetFloat4(DirectFunctionCall2Coll(ts_rank_tt,
727+
PG_GET_COLLATION(),
728+
PG_GETARG_DATUM(0),
729+
PG_GETARG_DATUM(1)));
730+
731+
if (r==0)
732+
PG_RETURN_FLOAT4(get_float4_infinity());
733+
else
734+
PG_RETURN_FLOAT4(1.0 /r);
718735
}
719736

720737
Datum

‎rumget.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,6 +2517,12 @@ insertScanItem(RumScanOpaque so, bool recheck)
25172517
continue;
25182518

25192519
item->data[j]=keyGetOrdering(&so->rumstate,so->tempCtx,&so->keys[i],&so->iptr);
2520+
/*
2521+
elog(NOTICE, "%f %u:%u",
2522+
item->data[j],
2523+
ItemPointerGetBlockNumber(&item->iptr),
2524+
ItemPointerGetOffsetNumber(&item->iptr));
2525+
*/
25202526
j++;
25212527
}
25222528
rum_tuplesort_putrum(so->sortstate,item);

‎sql/rum.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ SELECT rum_ts_distance(a, to_tsquery('pg_catalog.english', 'way & (go | half)'))
3939
FROM test_rum
4040
WHERE a @@ to_tsquery('pg_catalog.english','way & (go | half)')
4141
ORDER BY a<-> to_tsquery('pg_catalog.english','way & (go | half)');
42+
SELECT rum_ts_distance(a, to_tsquery('pg_catalog.english','way & (go | half)')),*
43+
FROM test_rum
44+
ORDER BY a<-> to_tsquery('pg_catalog.english','way & (go | half)')limit5;
4245

4346
INSERT INTO test_rum (t)VALUES ('foo bar foo the over foo qq bar');
4447
INSERT INTO test_rum (t)VALUES ('345 qwerty copyright');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp