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

Commite5be899

Browse files
committed
Refactoring by Heikki Linnakangas <heikki@enterprisedb.com> with
small editorization by me- Brake the QueryItem struct into QueryOperator and QueryOperand. Type was really the only common field between them. QueryItem still exists, and is used in the TSQuery struct as before, but it's now a union of the two. Many other changes fell from that, like separation of pushval_asis function into pushValue, pushOperator and pushStop.- Moved some structs that were for internal use only from header files to the right .c-files.- Moved tsvector parser to a new tsvector_parser.c file. Parser code was about half of the size of tsvector.c, it's also used from tsquery.c, and it has some data structures of its own, so it seems better to separate it. Cleaned up the API so that TSVectorParserState is not accessed from outside tsvector_parser.c.- Separated enumerations (#defines, really) used for QueryItem.type field and as return codes from gettoken_query. It was just accidental code sharing.- Removed ParseQueryNode struct used internally by makepol and friends. push*-functions now construct QueryItems directly.- Changed int4 variables to just ints for variables like "i" or "array size", where the storage-size was not significant.
1 parentda12484 commite5be899

18 files changed

+1278
-822
lines changed

‎src/backend/tsearch/to_tsany.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/tsearch/to_tsany.c,v 1.1 2007/08/21 01:11:18 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/tsearch/to_tsany.c,v 1.2 2007/09/07 15:09:55 teodor Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -225,10 +225,17 @@ to_tsvector(PG_FUNCTION_ARGS)
225225

226226

227227
/*
228-
* This function is used for morph parsing
228+
* This function is used for morph parsing.
229+
*
230+
* The value is passed to parsetext which will call the right dictionary to
231+
* lexize the word. If it turns out to be a stopword, we push a QI_VALSTOP
232+
* to the stack.
233+
*
234+
* All words belonging to the same variant are pushed as an ANDed list,
235+
* and different variants are ORred together.
229236
*/
230237
staticvoid
231-
pushval_morph(TSQueryParserState*state,inttypeval,char*strval,intlenval,int2weight)
238+
pushval_morph(void*opaque,TSQueryParserStatestate,char*strval,intlenval,int2weight)
232239
{
233240
int4count=0;
234241
ParsedTextprs;
@@ -237,13 +244,14 @@ pushval_morph(TSQueryParserState * state, int typeval, char *strval, int lenval,
237244
cntvar=0,
238245
cntpos=0,
239246
cnt=0;
247+
Oidcfg_id= (Oid)opaque;/* the input is actually an Oid, not a pointer */
240248

241249
prs.lenwords=4;
242250
prs.curwords=0;
243251
prs.pos=0;
244252
prs.words= (ParsedWord*)palloc(sizeof(ParsedWord)*prs.lenwords);
245253

246-
parsetext(state->cfg_id,&prs,strval,lenval);
254+
parsetext(cfg_id,&prs,strval,lenval);
247255

248256
if (prs.curwords>0)
249257
{
@@ -260,21 +268,21 @@ pushval_morph(TSQueryParserState * state, int typeval, char *strval, int lenval,
260268
while (count<prs.curwords&&pos==prs.words[count].pos.pos&&variant==prs.words[count].nvariant)
261269
{
262270

263-
pushval_asis(state,VAL,prs.words[count].word,prs.words[count].len,weight);
271+
pushValue(state,prs.words[count].word,prs.words[count].len,weight);
264272
pfree(prs.words[count].word);
265273
if (cnt)
266-
pushquery(state,OPR, (int4)'&',0,0,0);
274+
pushOperator(state,OP_AND);
267275
cnt++;
268276
count++;
269277
}
270278

271279
if (cntvar)
272-
pushquery(state,OPR, (int4)'|',0,0,0);
280+
pushOperator(state,OP_OR);
273281
cntvar++;
274282
}
275283

276284
if (cntpos)
277-
pushquery(state,OPR, (int4)'&',0,0,0);
285+
pushOperator(state,OP_AND);
278286

279287
cntpos++;
280288
}
@@ -283,7 +291,7 @@ pushval_morph(TSQueryParserState * state, int typeval, char *strval, int lenval,
283291

284292
}
285293
else
286-
pushval_asis(state,VALSTOP,NULL,0,0);
294+
pushStop(state);
287295
}
288296

289297
Datum
@@ -295,7 +303,7 @@ to_tsquery_byid(PG_FUNCTION_ARGS)
295303
QueryItem*res;
296304
int4len;
297305

298-
query=parse_tsquery(TextPGetCString(in),pushval_morph,cfgid, false);
306+
query=parse_tsquery(TextPGetCString(in),pushval_morph,(void*)cfgid, false);
299307

300308
if (query->size==0)
301309
PG_RETURN_TSQUERY(query);
@@ -333,7 +341,7 @@ plainto_tsquery_byid(PG_FUNCTION_ARGS)
333341
QueryItem*res;
334342
int4len;
335343

336-
query=parse_tsquery(TextPGetCString(in),pushval_morph,cfgid, true);
344+
query=parse_tsquery(TextPGetCString(in),pushval_morph,(void*)cfgid, true);
337345

338346
if (query->size==0)
339347
PG_RETURN_TSQUERY(query);

‎src/backend/tsearch/ts_parse.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/tsearch/ts_parse.c,v 1.2 2007/08/25 00:03:59 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/tsearch/ts_parse.c,v 1.3 2007/09/07 15:09:55 teodor Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -344,10 +344,12 @@ LexizeExec(LexizeData * ld, ParsedLex ** correspondLexem)
344344
}
345345

346346
/*
347-
* Parse string and lexize words
347+
* Parse string and lexize words.
348+
*
349+
* prs will be filled in.
348350
*/
349351
void
350-
parsetext(OidcfgId,ParsedText*prs,char*buf,int4buflen)
352+
parsetext(OidcfgId,ParsedText*prs,char*buf,intbuflen)
351353
{
352354
inttype,
353355
lenlemm;
@@ -427,7 +429,7 @@ parsetext(Oid cfgId, ParsedText * prs, char *buf, int4 buflen)
427429
* Headline framework
428430
*/
429431
staticvoid
430-
hladdword(HeadlineParsedText*prs,char*buf,int4buflen,inttype)
432+
hladdword(HeadlineParsedText*prs,char*buf,intbuflen,inttype)
431433
{
432434
while (prs->curwords >=prs->lenwords)
433435
{
@@ -458,17 +460,19 @@ hlfinditem(HeadlineParsedText * prs, TSQuery query, char *buf, int buflen)
458460
word=&(prs->words[prs->curwords-1]);
459461
for (i=0;i<query->size;i++)
460462
{
461-
if (item->type==VAL&&item->length==buflen&&strncmp(GETOPERAND(query)+item->distance,buf,buflen)==0)
463+
if (item->type==QI_VAL&&
464+
item->operand.length==buflen&&
465+
strncmp(GETOPERAND(query)+item->operand.distance,buf,buflen)==0)
462466
{
463467
if (word->item)
464468
{
465469
memcpy(&(prs->words[prs->curwords]),word,sizeof(HeadlineWordEntry));
466-
prs->words[prs->curwords].item=item;
470+
prs->words[prs->curwords].item=&item->operand;
467471
prs->words[prs->curwords].repeated=1;
468472
prs->curwords++;
469473
}
470474
else
471-
word->item=item;
475+
word->item=&item->operand;
472476
}
473477
item++;
474478
}
@@ -511,7 +515,7 @@ addHLParsedLex(HeadlineParsedText * prs, TSQuery query, ParsedLex * lexs, TSLexe
511515
}
512516

513517
void
514-
hlparsetext(OidcfgId,HeadlineParsedText*prs,TSQueryquery,char*buf,int4buflen)
518+
hlparsetext(OidcfgId,HeadlineParsedText*prs,TSQueryquery,char*buf,intbuflen)
515519
{
516520
inttype,
517521
lenlemm;

‎src/backend/tsearch/wparser_def.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/tsearch/wparser_def.c,v 1.2 2007/08/22 01:39:45 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/tsearch/wparser_def.c,v 1.3 2007/09/07 15:09:55 teodor Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1575,7 +1575,7 @@ typedef struct
15751575
}hlCheck;
15761576

15771577
staticbool
1578-
checkcondition_HL(void*checkval,QueryItem*val)
1578+
checkcondition_HL(void*checkval,QueryOperand*val)
15791579
{
15801580
inti;
15811581

@@ -1601,14 +1601,14 @@ hlCover(HeadlineParsedText * prs, TSQuery query, int *p, int *q)
16011601

16021602
for (j=0;j<query->size;j++)
16031603
{
1604-
if (item->type!=VAL)
1604+
if (item->type!=QI_VAL)
16051605
{
16061606
item++;
16071607
continue;
16081608
}
16091609
for (i=pos;i<prs->curwords;i++)
16101610
{
1611-
if (prs->words[i].item==item)
1611+
if (prs->words[i].item==&item->operand)
16121612
{
16131613
if (i>*q)
16141614
*q=i;
@@ -1624,14 +1624,14 @@ hlCover(HeadlineParsedText * prs, TSQuery query, int *p, int *q)
16241624
item=GETQUERY(query);
16251625
for (j=0;j<query->size;j++)
16261626
{
1627-
if (item->type!=VAL)
1627+
if (item->type!=QI_VAL)
16281628
{
16291629
item++;
16301630
continue;
16311631
}
16321632
for (i=*q;i >=pos;i--)
16331633
{
1634-
if (prs->words[i].item==item)
1634+
if (prs->words[i].item==&item->operand)
16351635
{
16361636
if (i<*p)
16371637
*p=i;

‎src/backend/utils/adt/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Makefile for utils/adt
33
#
4-
# $PostgreSQL: pgsql/src/backend/utils/adt/Makefile,v 1.66 2007/08/27 01:39:24 tgl Exp $
4+
# $PostgreSQL: pgsql/src/backend/utils/adt/Makefile,v 1.67 2007/09/07 15:09:56 teodor Exp $
55
#
66

77
subdir = src/backend/utils/adt
@@ -28,7 +28,7 @@ OBJS = acl.o arrayfuncs.o array_userfuncs.o arrayutils.o bool.o \
2828
ascii.o quote.o pgstatfuncs.o encode.o dbsize.o genfile.o\
2929
tsginidx.o tsgistidx.o tsquery.o tsquery_cleanup.o tsquery_gist.o\
3030
tsquery_op.o tsquery_rewrite.o tsquery_util.o tsrank.o\
31-
tsvector.o tsvector_op.o\
31+
tsvector.o tsvector_op.otsvector_parser.o\
3232
uuid.o xml.o
3333

3434
like.o: like.c like_match.c

‎src/backend/utils/adt/tsginidx.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsginidx.c,v 1.1 2007/08/21 01:11:19 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsginidx.c,v 1.2 2007/09/07 15:09:56 teodor Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -77,24 +77,25 @@ gin_extract_query(PG_FUNCTION_ARGS)
7777
item=GETQUERY(query);
7878

7979
for (i=0;i<query->size;i++)
80-
if (item[i].type==VAL)
80+
if (item[i].type==QI_VAL)
8181
(*nentries)++;
8282

8383
entries= (Datum*)palloc(sizeof(Datum)* (*nentries));
8484

8585
for (i=0;i<query->size;i++)
86-
if (item[i].type==VAL)
86+
if (item[i].type==QI_VAL)
8787
{
8888
text*txt;
89+
QueryOperand*val=&item[i].operand;
8990

90-
txt= (text*)palloc(VARHDRSZ+item[i].length);
91+
txt= (text*)palloc(VARHDRSZ+val->length);
9192

92-
SET_VARSIZE(txt,VARHDRSZ+item[i].length);
93-
memcpy(VARDATA(txt),GETOPERAND(query)+item[i].distance,item[i].length);
93+
SET_VARSIZE(txt,VARHDRSZ+val->length);
94+
memcpy(VARDATA(txt),GETOPERAND(query)+val->distance,val->length);
9495

9596
entries[j++]=PointerGetDatum(txt);
9697

97-
if (strategy!=TSearchWithClassStrategyNumber&&item[i].weight!=0)
98+
if (strategy!=TSearchWithClassStrategyNumber&&val->weight!=0)
9899
ereport(ERROR,
99100
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
100101
errmsg("@@ operator does not support lexeme class restrictions"),
@@ -116,11 +117,11 @@ typedef struct
116117
}GinChkVal;
117118

118119
staticbool
119-
checkcondition_gin(void*checkval,QueryItem*val)
120+
checkcondition_gin(void*checkval,QueryOperand*val)
120121
{
121122
GinChkVal*gcv= (GinChkVal*)checkval;
122123

123-
returngcv->mapped_check[val-gcv->frst];
124+
returngcv->mapped_check[((QueryItem*)val)-gcv->frst];
124125
}
125126

126127
Datum
@@ -142,7 +143,7 @@ gin_ts_consistent(PG_FUNCTION_ARGS)
142143
gcv.mapped_check= (bool*)palloc(sizeof(bool)*query->size);
143144

144145
for (i=0;i<query->size;i++)
145-
if (item[i].type==VAL)
146+
if (item[i].type==QI_VAL)
146147
gcv.mapped_check[i]=check[j++];
147148

148149
res=TS_execute(

‎src/backend/utils/adt/tsgistidx.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsgistidx.c,v 1.2 2007/08/21 06:34:42 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsgistidx.c,v 1.3 2007/09/07 15:09:56 teodor Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -293,7 +293,7 @@ typedef struct
293293
* is there value 'val' in array or not ?
294294
*/
295295
staticbool
296-
checkcondition_arr(void*checkval,QueryItem*val)
296+
checkcondition_arr(void*checkval,QueryOperand*val)
297297
{
298298
int4*StopLow= ((CHKVAL*)checkval)->arrb;
299299
int4*StopHigh= ((CHKVAL*)checkval)->arre;
@@ -304,9 +304,9 @@ checkcondition_arr(void *checkval, QueryItem * val)
304304
while (StopLow<StopHigh)
305305
{
306306
StopMiddle=StopLow+ (StopHigh-StopLow) /2;
307-
if (*StopMiddle==val->val)
307+
if (*StopMiddle==val->valcrc)
308308
return (true);
309-
elseif (*StopMiddle<val->val)
309+
elseif (*StopMiddle<val->valcrc)
310310
StopLow=StopMiddle+1;
311311
else
312312
StopHigh=StopMiddle;
@@ -316,9 +316,9 @@ checkcondition_arr(void *checkval, QueryItem * val)
316316
}
317317

318318
staticbool
319-
checkcondition_bit(void*checkval,QueryItem*val)
319+
checkcondition_bit(void*checkval,QueryOperand*val)
320320
{
321-
returnGETBIT(checkval,HASHVAL(val->val));
321+
returnGETBIT(checkval,HASHVAL(val->valcrc));
322322
}
323323

324324
Datum

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp