LCOV - code coverage report
Current view: top level - src/backend/tsearch - dict.c (source / functions) Hit Total Coverage
Test: PostgreSQL Lines: 30 31 96.8 %
Date: 2017-09-29 15:12:54 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  * dict.c
       4             :  *      Standard interface to dictionary
       5             :  *
       6             :  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
       7             :  *
       8             :  *
       9             :  * IDENTIFICATION
      10             :  *    src/backend/tsearch/dict.c
      11             :  *
      12             :  *-------------------------------------------------------------------------
      13             :  */
      14             : #include "postgres.h"
      15             : 
      16             : #include "catalog/pg_type.h"
      17             : #include "tsearch/ts_cache.h"
      18             : #include "tsearch/ts_utils.h"
      19             : #include "utils/builtins.h"
      20             : 
      21             : 
      22             : /*
      23             :  * Lexize one word by dictionary, mostly debug function
      24             :  */
      25             : Datum
      26         114 : ts_lexize(PG_FUNCTION_ARGS)
      27             : {
      28         114 :     Oid         dictId = PG_GETARG_OID(0);
      29         114 :     text       *in = PG_GETARG_TEXT_PP(1);
      30             :     ArrayType  *a;
      31             :     TSDictionaryCacheEntry *dict;
      32             :     TSLexeme   *res,
      33             :                *ptr;
      34             :     Datum      *da;
      35         114 :     DictSubState dstate = {false, false, NULL};
      36             : 
      37         114 :     dict = lookup_ts_dictionary_cache(dictId);
      38             : 
      39         114 :     res = (TSLexeme *) DatumGetPointer(FunctionCall4(&dict->lexize,
      40             :                                                      PointerGetDatum(dict->dictData),
      41             :                                                      PointerGetDatum(VARDATA_ANY(in)),
      42             :                                                      Int32GetDatum(VARSIZE_ANY_EXHDR(in)),
      43             :                                                      PointerGetDatum(&dstate)));
      44             : 
      45         114 :     if (dstate.getnext)
      46             :     {
      47           1 :         dstate.isend = true;
      48           1 :         ptr = (TSLexeme *) DatumGetPointer(FunctionCall4(&dict->lexize,
      49             :                                                          PointerGetDatum(dict->dictData),
      50             :                                                          PointerGetDatum(VARDATA_ANY(in)),
      51             :                                                          Int32GetDatum(VARSIZE_ANY_EXHDR(in)),
      52             :                                                          PointerGetDatum(&dstate)));
      53           1 :         if (ptr != NULL)
      54           0 :             res = ptr;
      55             :     }
      56             : 
      57         114 :     if (!res)
      58           4 :         PG_RETURN_NULL();
      59             : 
      60         110 :     ptr = res;
      61         382 :     while (ptr->lexeme)
      62         162 :         ptr++;
      63         110 :     da = (Datum *) palloc(sizeof(Datum) * (ptr - res));
      64         110 :     ptr = res;
      65         382 :     while (ptr->lexeme)
      66             :     {
      67         162 :         da[ptr - res] = CStringGetTextDatum(ptr->lexeme);
      68         162 :         ptr++;
      69             :     }
      70             : 
      71         110 :     a = construct_array(da,
      72         110 :                         ptr - res,
      73             :                         TEXTOID,
      74             :                         -1,
      75             :                         false,
      76             :                         'i');
      77             : 
      78         110 :     ptr = res;
      79         382 :     while (ptr->lexeme)
      80             :     {
      81         162 :         pfree(DatumGetPointer(da[ptr - res]));
      82         162 :         pfree(ptr->lexeme);
      83         162 :         ptr++;
      84             :     }
      85         110 :     pfree(res);
      86         110 :     pfree(da);
      87             : 
      88         110 :     PG_RETURN_POINTER(a);
      89             : }

Generated by: LCOV version 1.11