LCOV - differential code coverage report
Current view: top level - src/backend/tsearch - dict_simple.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage HEAD vs 15 Lines: 51.4 % 35 18 17 18
Current Date: 2023-04-08 15:15:32 Functions: 100.0 % 2 2 2
Baseline: 15
Baseline Date: 2023-04-08 15:09:40
Legend: Lines: hit not hit

           TLA  Line data    Source code
       1                 : /*-------------------------------------------------------------------------
       2                 :  *
       3                 :  * dict_simple.c
       4                 :  *      Simple dictionary: just lowercase and check for stopword
       5                 :  *
       6                 :  * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
       7                 :  *
       8                 :  *
       9                 :  * IDENTIFICATION
      10                 :  *    src/backend/tsearch/dict_simple.c
      11                 :  *
      12                 :  *-------------------------------------------------------------------------
      13                 :  */
      14                 : #include "postgres.h"
      15                 : 
      16                 : #include "commands/defrem.h"
      17                 : #include "tsearch/ts_locale.h"
      18                 : #include "tsearch/ts_utils.h"
      19                 : #include "utils/builtins.h"
      20                 : 
      21                 : 
      22                 : typedef struct
      23                 : {
      24                 :     StopList    stoplist;
      25                 :     bool        accept;
      26                 : } DictSimple;
      27                 : 
      28                 : 
      29                 : Datum
      30 CBC          35 : dsimple_init(PG_FUNCTION_ARGS)
      31                 : {
      32              35 :     List       *dictoptions = (List *) PG_GETARG_POINTER(0);
      33              35 :     DictSimple *d = (DictSimple *) palloc0(sizeof(DictSimple));
      34              35 :     bool        stoploaded = false,
      35              35 :                 acceptloaded = false;
      36                 :     ListCell   *l;
      37                 : 
      38              35 :     d->accept = true;            /* default */
      39                 : 
      40              35 :     foreach(l, dictoptions)
      41                 :     {
      42 UBC           0 :         DefElem    *defel = (DefElem *) lfirst(l);
      43                 : 
      44               0 :         if (strcmp(defel->defname, "stopwords") == 0)
      45                 :         {
      46               0 :             if (stoploaded)
      47               0 :                 ereport(ERROR,
      48                 :                         (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
      49                 :                          errmsg("multiple StopWords parameters")));
      50               0 :             readstoplist(defGetString(defel), &d->stoplist, lowerstr);
      51               0 :             stoploaded = true;
      52                 :         }
      53               0 :         else if (strcmp(defel->defname, "accept") == 0)
      54                 :         {
      55               0 :             if (acceptloaded)
      56               0 :                 ereport(ERROR,
      57                 :                         (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
      58                 :                          errmsg("multiple Accept parameters")));
      59               0 :             d->accept = defGetBoolean(defel);
      60               0 :             acceptloaded = true;
      61                 :         }
      62                 :         else
      63                 :         {
      64               0 :             ereport(ERROR,
      65                 :                     (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
      66                 :                      errmsg("unrecognized simple dictionary parameter: \"%s\"",
      67                 :                             defel->defname)));
      68                 :         }
      69                 :     }
      70                 : 
      71 CBC          35 :     PG_RETURN_POINTER(d);
      72                 : }
      73                 : 
      74                 : Datum
      75            1837 : dsimple_lexize(PG_FUNCTION_ARGS)
      76                 : {
      77            1837 :     DictSimple *d = (DictSimple *) PG_GETARG_POINTER(0);
      78            1837 :     char       *in = (char *) PG_GETARG_POINTER(1);
      79            1837 :     int32       len = PG_GETARG_INT32(2);
      80                 :     char       *txt;
      81                 :     TSLexeme   *res;
      82                 : 
      83            1837 :     txt = lowerstr_with_len(in, len);
      84                 : 
      85            1837 :     if (*txt == '\0' || searchstoplist(&(d->stoplist), txt))
      86                 :     {
      87                 :         /* reject as stopword */
      88 UBC           0 :         pfree(txt);
      89               0 :         res = palloc0(sizeof(TSLexeme) * 2);
      90               0 :         PG_RETURN_POINTER(res);
      91                 :     }
      92 CBC        1837 :     else if (d->accept)
      93                 :     {
      94                 :         /* accept */
      95            1837 :         res = palloc0(sizeof(TSLexeme) * 2);
      96            1837 :         res[0].lexeme = txt;
      97            1837 :         PG_RETURN_POINTER(res);
      98                 :     }
      99                 :     else
     100                 :     {
     101                 :         /* report as unrecognized */
     102 UBC           0 :         pfree(txt);
     103               0 :         PG_RETURN_POINTER(NULL);
     104                 :     }
     105                 : }
        

Generated by: LCOV version v1.16-55-g56c0a2a