Add an "absval" parameter to allow contrib/dict_int to ignore signs.
Jeff Janes Discussion: https://postgr.es/m/CAMkU=1xRcs_BUPzR0+V3WndaCAv0E_m3h6aUEJ8NF-sY1nnHsw@mail.gmail.com
This commit is contained in:
parent
38ce06c37e
commit
806eb92c01
|
@ -21,6 +21,7 @@ typedef struct
|
||||||
{
|
{
|
||||||
int maxlen;
|
int maxlen;
|
||||||
bool rejectlong;
|
bool rejectlong;
|
||||||
|
bool absval;
|
||||||
} DictInt;
|
} DictInt;
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,6 +38,7 @@ dintdict_init(PG_FUNCTION_ARGS)
|
||||||
d = (DictInt *) palloc0(sizeof(DictInt));
|
d = (DictInt *) palloc0(sizeof(DictInt));
|
||||||
d->maxlen = 6;
|
d->maxlen = 6;
|
||||||
d->rejectlong = false;
|
d->rejectlong = false;
|
||||||
|
d->absval = false;
|
||||||
|
|
||||||
foreach(l, dictoptions)
|
foreach(l, dictoptions)
|
||||||
{
|
{
|
||||||
|
@ -55,6 +57,10 @@ dintdict_init(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
d->rejectlong = defGetBoolean(defel);
|
d->rejectlong = defGetBoolean(defel);
|
||||||
}
|
}
|
||||||
|
else if (strcmp(defel->defname, "absval") == 0)
|
||||||
|
{
|
||||||
|
d->absval = defGetBoolean(defel);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
|
@ -72,11 +78,21 @@ dintdict_lexize(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
DictInt *d = (DictInt *) PG_GETARG_POINTER(0);
|
DictInt *d = (DictInt *) PG_GETARG_POINTER(0);
|
||||||
char *in = (char *) PG_GETARG_POINTER(1);
|
char *in = (char *) PG_GETARG_POINTER(1);
|
||||||
char *txt = pnstrdup(in, PG_GETARG_INT32(2));
|
int len = PG_GETARG_INT32(2);
|
||||||
|
char *txt;
|
||||||
TSLexeme *res = palloc0(sizeof(TSLexeme) * 2);
|
TSLexeme *res = palloc0(sizeof(TSLexeme) * 2);
|
||||||
|
|
||||||
res[1].lexeme = NULL;
|
res[1].lexeme = NULL;
|
||||||
if (PG_GETARG_INT32(2) > d->maxlen)
|
|
||||||
|
if (d->absval && (in[0] == '+' || in[0] == '-'))
|
||||||
|
{
|
||||||
|
len--;
|
||||||
|
txt = pnstrdup(in + 1, len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
txt = pnstrdup(in, len);
|
||||||
|
|
||||||
|
if (len > d->maxlen)
|
||||||
{
|
{
|
||||||
if (d->rejectlong)
|
if (d->rejectlong)
|
||||||
{
|
{
|
||||||
|
|
|
@ -302,3 +302,28 @@ select ts_lexize('intdict', '314532610153');
|
||||||
|
|
||||||
ALTER TEXT SEARCH DICTIONARY intdict (MAXLEN = -214783648);
|
ALTER TEXT SEARCH DICTIONARY intdict (MAXLEN = -214783648);
|
||||||
ERROR: maxlen value has to be >= 1
|
ERROR: maxlen value has to be >= 1
|
||||||
|
select ts_lexize('intdict', '-40865854');
|
||||||
|
ts_lexize
|
||||||
|
-----------
|
||||||
|
{-40865}
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
select ts_lexize('intdict', '+40865854');
|
||||||
|
ts_lexize
|
||||||
|
-----------
|
||||||
|
{+40865}
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
ALTER TEXT SEARCH DICTIONARY intdict (ABSVAL = true);
|
||||||
|
select ts_lexize('intdict', '-40865854');
|
||||||
|
ts_lexize
|
||||||
|
-----------
|
||||||
|
{408658}
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
select ts_lexize('intdict', '+40865854');
|
||||||
|
ts_lexize
|
||||||
|
-----------
|
||||||
|
{408658}
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
|
|
@ -53,3 +53,9 @@ select ts_lexize('intdict', '641439323669');
|
||||||
select ts_lexize('intdict', '314532610153');
|
select ts_lexize('intdict', '314532610153');
|
||||||
|
|
||||||
ALTER TEXT SEARCH DICTIONARY intdict (MAXLEN = -214783648);
|
ALTER TEXT SEARCH DICTIONARY intdict (MAXLEN = -214783648);
|
||||||
|
|
||||||
|
select ts_lexize('intdict', '-40865854');
|
||||||
|
select ts_lexize('intdict', '+40865854');
|
||||||
|
ALTER TEXT SEARCH DICTIONARY intdict (ABSVAL = true);
|
||||||
|
select ts_lexize('intdict', '-40865854');
|
||||||
|
select ts_lexize('intdict', '+40865854');
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
<title>Configuration</title>
|
<title>Configuration</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The dictionary accepts two options:
|
The dictionary accepts three options:
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<itemizedlist>
|
<itemizedlist>
|
||||||
|
@ -46,6 +46,15 @@
|
||||||
such an integer cannot be searched for.
|
such an integer cannot be searched for.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
The <literal>absval</literal> parameter specifies whether leading
|
||||||
|
<quote><literal>+</literal></quote> or <quote><literal>-</literal></quote>
|
||||||
|
signs should be removed from integer words. The default
|
||||||
|
is <literal>false</literal>. When <literal>true</literal>, the sign is
|
||||||
|
removed before <literal>maxlen</literal> is applied.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
</sect2>
|
</sect2>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue