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

Commit1aed4c4

Browse files
committed
Add comments and a missing CHECK_FOR_INTERRUPTS in ts_headline.
I just spent an annoying amount of time reverse-engineering the100%-undocumented API between ts_headline and the text searchparser's prsheadline function. Add some commentary about thatwhile it's fresh in mind. Also remove some unused macros inwparser_def.c.While at it, I noticed that when commit78e73e8 added aCHECK_FOR_INTERRUPTS call in TS_execute_recurse, it misseddoing so in the parallel function TS_phrase_execute, whichsurely needs one just as much.Back-patch because of the missing CHECK_FOR_INTERRUPTS.Might as well back-patch the rest of this too.
1 parent4cbcb7e commit1aed4c4

File tree

4 files changed

+60
-21
lines changed

4 files changed

+60
-21
lines changed

‎src/backend/tsearch/ts_parse.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,8 @@ parsetext(Oid cfgId, ParsedText *prs, char *buf, int buflen)
437437
/*
438438
* Headline framework
439439
*/
440+
441+
/* Add a word to prs->words[] */
440442
staticvoid
441443
hladdword(HeadlineParsedText*prs,char*buf,intbuflen,inttype)
442444
{
@@ -453,6 +455,14 @@ hladdword(HeadlineParsedText *prs, char *buf, int buflen, int type)
453455
prs->curwords++;
454456
}
455457

458+
/*
459+
* Add pos and matching-query-item data to the just-added word.
460+
* Here, buf/buflen represent a processed lexeme, not raw token text.
461+
*
462+
* If the query contains more than one matching item, we replicate
463+
* the last-added word so that each item can be pointed to. The
464+
* duplicate entries are marked with repeated = 1.
465+
*/
456466
staticvoid
457467
hlfinditem(HeadlineParsedText*prs,TSQueryquery,int32pos,char*buf,intbuflen)
458468
{
@@ -594,6 +604,9 @@ hlparsetext(Oid cfgId, HeadlineParsedText *prs, TSQuery query, char *buf, int bu
594604
FunctionCall1(&(prsobj->prsend),PointerGetDatum(prsdata));
595605
}
596606

607+
/*
608+
* Generate the headline, as a text object, from HeadlineParsedText.
609+
*/
597610
text*
598611
generateHeadline(HeadlineParsedText*prs)
599612
{

‎src/backend/tsearch/wparser_def.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,10 +1921,6 @@ prsd_end(PG_FUNCTION_ARGS)
19211921
*/
19221922

19231923
/* token type classification macros */
1924-
#defineLEAVETOKEN(x)( (x)==SPACE )
1925-
#defineCOMPLEXTOKEN(x) ( (x)==URL_T || (x)==NUMHWORD || (x)==ASCIIHWORD || (x)==HWORD )
1926-
#defineENDPUNCTOKEN(x) ( (x)==SPACE )
1927-
19281924
#defineTS_IDIGNORE(x)( (x)==TAG_T || (x)==PROTOCOL || (x)==SPACE || (x)==XMLENTITY )
19291925
#defineHLIDREPLACE(x)( (x)==TAG_T )
19301926
#defineHLIDSKIP(x)( (x)==URL_T || (x)==NUMHWORD || (x)==ASCIIHWORD || (x)==HWORD )

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,9 @@ TS_phrase_execute(QueryItem *curitem, void *arg, uint32 flags,
16071607
/* since this function recurses, it could be driven to stack overflow */
16081608
check_stack_depth();
16091609

1610+
/* ... and let's check for query cancel while we're at it */
1611+
CHECK_FOR_INTERRUPTS();
1612+
16101613
if (curitem->type==QI_VAL)
16111614
{
16121615
if (!chkcond(arg, (QueryOperand*)curitem,data))

‎src/include/tsearch/ts_public.h

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,60 @@ typedef struct
3030
}LexDescr;
3131

3232
/*
33-
* Interface to headline generator
33+
* Interface to headline generator (tsparser's prsheadline function)
34+
*
35+
* HeadlineParsedText describes the text that is to be highlighted.
36+
* Some fields are passed from the core code to the prsheadline function,
37+
* while others are output from the prsheadline function.
38+
*
39+
* The principal data is words[], an array of HeadlineWordEntry,
40+
* one entry per token, of length curwords.
41+
* The fields of HeadlineWordEntry are:
42+
*
43+
* in, selected, replace, skip: these flags are initially zero
44+
* and may be set by the prsheadline function. A consecutive group
45+
* of tokens marked "in" form a "fragment" to be output.
46+
* Such tokens may additionally be marked selected, replace, or skip
47+
* to modify how they are shown. (If you set more than one of those
48+
* bits, you get an unspecified one of those behaviors.)
49+
*
50+
* type, len, pos, word: filled by core code to describe the token.
51+
*
52+
* item: if the token matches any operand of the tsquery of interest,
53+
* a pointer to such an operand. (If there are multiple matching
54+
* operands, we generate extra copies of the HeadlineWordEntry to hold
55+
* all the pointers. The extras are marked with repeated = 1 and should
56+
* be ignored except for checking the item pointer.)
3457
*/
3558
typedefstruct
3659
{
37-
uint32selected:1,
38-
in:1,
39-
replace:1,
40-
repeated:1,
41-
skip:1,
42-
unused:3,
43-
type:8,
44-
len:16;
45-
WordEntryPospos;
46-
char*word;
47-
QueryOperand*item;
60+
uint32selected:1,/* token is to be highlighted */
61+
in:1,/* token is part of headline */
62+
replace:1,/* token is to be replaced with a space */
63+
repeated:1,/* duplicate entry to hold item pointer */
64+
skip:1,/* token is to be skipped (not output) */
65+
unused:3,/* available bits */
66+
type:8,/* parser's token category */
67+
len:16;/* length of token */
68+
WordEntryPospos;/* position of token */
69+
char*word;/* text of token (not null-terminated) */
70+
QueryOperand*item;/* a matching query operand, or NULL if none */
4871
}HeadlineWordEntry;
4972

5073
typedefstruct
5174
{
75+
/* Fields filled by core code before calling prsheadline function: */
5276
HeadlineWordEntry*words;
53-
int32lenwords;
54-
int32curwords;
55-
int32vectorpos;/* positions a-la tsvector */
56-
char*startsel;
77+
int32lenwords;/* allocated length of words[] */
78+
int32curwords;/* current number of valid entries */
79+
int32vectorpos;/* used by ts_parse.c in filling pos fields */
80+
81+
/* The prsheadline function must fill these fields: */
82+
/* Strings for marking selected tokens and separating fragments: */
83+
char*startsel;/* palloc'd strings */
5784
char*stopsel;
5885
char*fragdelim;
59-
int16startsellen;
86+
int16startsellen;/* lengths of strings */
6087
int16stopsellen;
6188
int16fragdelimlen;
6289
}HeadlineParsedText;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp