Patch resolve ERROR problem for non-goog query_txt.
authorBruce Momjian
Fri, 23 Aug 2002 02:56:36 +0000 (02:56 +0000)
committerBruce Momjian
Fri, 23 Aug 2002 02:56:36 +0000 (02:56 +0000)
Teodor Sigaev

contrib/tsearch/README.tsearch
contrib/tsearch/gistidx.c
contrib/tsearch/query.c
contrib/tsearch/rewrite.c

index a57df55eea79f39d9f4a7bcb9a39185680266152..e3bb9d91ec3b3d1e7a073ca37e5bc29748cd81b0 100644 (file)
@@ -6,6 +6,8 @@ All work was done by Teodor Sigaev ([email protected]) and Oleg Bartunov
 
 CHANGES:
 
+August 22, 2002
+   Fix works with 'bad' queries
 August 13, 2002
    Use parser of OpenFTS v0.33.
 
index 5e527036840c49c1bb0b86617952727383fd3036..61ab1bd8f05a7ecb1c80867217f2750c109243c1 100644 (file)
@@ -231,6 +231,9 @@ gtxtidx_consistent(PG_FUNCTION_ARGS) {
        ((GISTENTRY *)PG_GETARG_POINTER(0))->key
    );
 
+   if ( !query->size )
+       PG_RETURN_BOOL(false);
+
    if ( ISSIGNKEY(key) ) {
        if ( ISALLTRUE(key) )
            PG_RETURN_BOOL(true);
index 6666720c9bc6122247143fec3c83288055c93fcb..c3917f204fb6005de5dadb4bf0c4aa9f7695ed55 100644 (file)
@@ -419,7 +419,7 @@ execqtxt(PG_FUNCTION_ARGS)
    CHKVAL      chkval;
    bool        result;
 
-   if (!val->size)
+   if (!val->size || !query->size)
    {
        PG_FREE_IF_COPY(val, 0);
        PG_FREE_IF_COPY(query, 1);
@@ -593,8 +593,9 @@ mqtxt_in(PG_FUNCTION_ARGS)
    res = clean_fakeval(GETQUERY(query), &len);
    if (!res)
    {
-       pfree(query);
-       PG_RETURN_NULL();
+       query->len=HDRSIZEQT;
+       query->size=0;
+       PG_RETURN_POINTER(query);
    }
    memcpy((void *) GETQUERY(query), (void *) res, len * sizeof(ITEM));
 #ifdef BS_DEBUG
@@ -738,8 +739,11 @@ qtxt_out(PG_FUNCTION_ARGS)
    QUERYTYPE  *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0)));
    INFIX       nrm;
 
-   if (query->size == 0)
-       elog(ERROR, "Empty");
+   if (query->size == 0) {
+       char *b=palloc(1);
+       *b='\0';
+       PG_RETURN_POINTER(b);
+   }   
    nrm.curpol = GETQUERY(query);
    nrm.buflen = 32;
    nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
@@ -765,8 +769,11 @@ querytree(PG_FUNCTION_ARGS)
    int4        len;
 
 
-   if (query->size == 0)
-       elog(ERROR, "Empty");
+   if (query->size == 0) {
+       res = (text *) palloc(VARHDRSZ);
+       VARATT_SIZEP(res) = VARHDRSZ;
+       PG_RETURN_POINTER(res);
+   }   
 
    q = clean_NOT(GETQUERY(query), &len);
 
index 5036c420ff2faa84429b449a0010535dcacc4947..33e948faf8914bf036507298bf4c3122569245d4 100644 (file)
@@ -283,7 +283,7 @@ clean_fakeval(ITEM * ptr, int4 *len)
    resroot = clean_fakeval_intree(root, &result);
    if (result != V_UNKNOWN)
    {
-       elog(ERROR, "Your query contained only stopword(s), ignored");
+       elog(NOTICE, "Query contains only stopword(s) or doesn't contain lexem(s), ignored");
        *len = 0;
        return NULL;
    }