File tree 4 files changed +59
-3
lines changed
4 files changed +59
-3
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ typedef struct
21
21
{
22
22
int maxlen ;
23
23
bool rejectlong ;
24
+ bool absval ;
24
25
} DictInt ;
25
26
26
27
@@ -37,6 +38,7 @@ dintdict_init(PG_FUNCTION_ARGS)
37
38
d = (DictInt * ) palloc0 (sizeof (DictInt ));
38
39
d -> maxlen = 6 ;
39
40
d -> rejectlong = false;
41
+ d -> absval = false;
40
42
41
43
foreach (l , dictoptions )
42
44
{
@@ -55,6 +57,10 @@ dintdict_init(PG_FUNCTION_ARGS)
55
57
{
56
58
d -> rejectlong = defGetBoolean (defel );
57
59
}
60
+ else if (strcmp (defel -> defname , "absval" ) == 0 )
61
+ {
62
+ d -> absval = defGetBoolean (defel );
63
+ }
58
64
else
59
65
{
60
66
ereport (ERROR ,
@@ -72,11 +78,21 @@ dintdict_lexize(PG_FUNCTION_ARGS)
72
78
{
73
79
DictInt * d = (DictInt * ) PG_GETARG_POINTER (0 );
74
80
char * in = (char * ) PG_GETARG_POINTER (1 );
75
- char * txt = pnstrdup (in , PG_GETARG_INT32 (2 ));
81
+ int len = PG_GETARG_INT32 (2 );
82
+ char * txt ;
76
83
TSLexeme * res = palloc0 (sizeof (TSLexeme ) * 2 );
77
84
78
85
res [1 ].lexeme = NULL ;
79
- if (PG_GETARG_INT32 (2 ) > d -> maxlen )
86
+
87
+ if (d -> absval && (in [0 ] == '+' || in [0 ] == '-' ))
88
+ {
89
+ len -- ;
90
+ txt = pnstrdup (in + 1 , len );
91
+ }
92
+ else
93
+ txt = pnstrdup (in , len );
94
+
95
+ if (len > d -> maxlen )
80
96
{
81
97
if (d -> rejectlong )
82
98
{
Original file line number Diff line number Diff line change @@ -302,3 +302,28 @@ select ts_lexize('intdict', '314532610153');
302
302
303
303
ALTER TEXT SEARCH DICTIONARY intdict (MAXLEN = -214783648);
304
304
ERROR: maxlen value has to be >= 1
305
+ select ts_lexize('intdict', '-40865854');
306
+ ts_lexize
307
+ -----------
308
+ {-40865}
309
+ (1 row)
310
+
311
+ select ts_lexize('intdict', '+40865854');
312
+ ts_lexize
313
+ -----------
314
+ {+40865}
315
+ (1 row)
316
+
317
+ ALTER TEXT SEARCH DICTIONARY intdict (ABSVAL = true);
318
+ select ts_lexize('intdict', '-40865854');
319
+ ts_lexize
320
+ -----------
321
+ {408658}
322
+ (1 row)
323
+
324
+ select ts_lexize('intdict', '+40865854');
325
+ ts_lexize
326
+ -----------
327
+ {408658}
328
+ (1 row)
329
+
Original file line number Diff line number Diff line change @@ -53,3 +53,9 @@ select ts_lexize('intdict', '641439323669');
53
53
select ts_lexize(' intdict' , ' 314532610153' );
54
54
55
55
ALTER TEXT SEARCH DICTIONARY intdict (MAXLEN = - 214783648 );
56
+
57
+ select ts_lexize(' intdict' , ' -40865854' );
58
+ select ts_lexize(' intdict' , ' +40865854' );
59
+ ALTER TEXT SEARCH DICTIONARY intdict (ABSVAL = true);
60
+ select ts_lexize(' intdict' , ' -40865854' );
61
+ select ts_lexize(' intdict' , ' +40865854' );
Original file line number Diff line number Diff line change 25
25
<title>Configuration</title>
26
26
27
27
<para>
28
- The dictionary accepts two options:
28
+ The dictionary accepts three options:
29
29
</para>
30
30
31
31
<itemizedlist>
46
46
such an integer cannot be searched for.
47
47
</para>
48
48
</listitem>
49
+ <listitem>
50
+ <para>
51
+ The <literal>absval</literal> parameter specifies whether leading
52
+ <quote><literal>+</literal></quote> or <quote><literal>-</literal></quote>
53
+ signs should be removed from integer words. The default
54
+ is <literal>false</literal>. When <literal>true</literal>, the sign is
55
+ removed before <literal>maxlen</literal> is applied.
56
+ </para>
57
+ </listitem>
49
58
</itemizedlist>
50
59
</sect2>
51
60
You can’t perform that action at this time.
0 commit comments