Skip to content

Commit 52ee800

Browse files
committed
Patch resolve ERROR problem for non-goog query_txt.
Teodor Sigaev
1 parent 2e0e430 commit 52ee800

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

contrib/tsearch/README.tsearch

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ All work was done by Teodor Sigaev (teodor@stack.net) and Oleg Bartunov
66

77
CHANGES:
88

9+
August 22, 2002
10+
Fix works with 'bad' queries
911
August 13, 2002
1012
Use parser of OpenFTS v0.33.
1113

contrib/tsearch/gistidx.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ gtxtidx_consistent(PG_FUNCTION_ARGS) {
231231
((GISTENTRY *)PG_GETARG_POINTER(0))->key
232232
);
233233

234+
if ( !query->size )
235+
PG_RETURN_BOOL(false);
236+
234237
if ( ISSIGNKEY(key) ) {
235238
if ( ISALLTRUE(key) )
236239
PG_RETURN_BOOL(true);

contrib/tsearch/query.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ execqtxt(PG_FUNCTION_ARGS)
419419
CHKVAL chkval;
420420
bool result;
421421

422-
if (!val->size)
422+
if (!val->size || !query->size)
423423
{
424424
PG_FREE_IF_COPY(val, 0);
425425
PG_FREE_IF_COPY(query, 1);
@@ -593,8 +593,9 @@ mqtxt_in(PG_FUNCTION_ARGS)
593593
res = clean_fakeval(GETQUERY(query), &len);
594594
if (!res)
595595
{
596-
pfree(query);
597-
PG_RETURN_NULL();
596+
query->len=HDRSIZEQT;
597+
query->size=0;
598+
PG_RETURN_POINTER(query);
598599
}
599600
memcpy((void *) GETQUERY(query), (void *) res, len * sizeof(ITEM));
600601
#ifdef BS_DEBUG
@@ -738,8 +739,11 @@ qtxt_out(PG_FUNCTION_ARGS)
738739
QUERYTYPE *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0)));
739740
INFIX nrm;
740741

741-
if (query->size == 0)
742-
elog(ERROR, "Empty");
742+
if (query->size == 0) {
743+
char *b=palloc(1);
744+
*b='\0';
745+
PG_RETURN_POINTER(b);
746+
}
743747
nrm.curpol = GETQUERY(query);
744748
nrm.buflen = 32;
745749
nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
@@ -765,8 +769,11 @@ querytree(PG_FUNCTION_ARGS)
765769
int4 len;
766770

767771

768-
if (query->size == 0)
769-
elog(ERROR, "Empty");
772+
if (query->size == 0) {
773+
res = (text *) palloc(VARHDRSZ);
774+
VARATT_SIZEP(res) = VARHDRSZ;
775+
PG_RETURN_POINTER(res);
776+
}
770777

771778
q = clean_NOT(GETQUERY(query), &len);
772779

contrib/tsearch/rewrite.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ clean_fakeval(ITEM * ptr, int4 *len)
283283
resroot = clean_fakeval_intree(root, &result);
284284
if (result != V_UNKNOWN)
285285
{
286-
elog(ERROR, "Your query contained only stopword(s), ignored");
286+
elog(NOTICE, "Query contains only stopword(s) or doesn't contain lexem(s), ignored");
287287
*len = 0;
288288
return NULL;
289289
}

0 commit comments

Comments
 (0)