Header And Logo

| The world's most advanced open source database.

Data Structures | Defines | Functions

ts_public.h File Reference

#include "tsearch/ts_type.h"
Include dependency graph for ts_public.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  LexDescr
struct  HeadlineWordEntry
struct  HeadlineParsedText
struct  StopList
struct  TSLexeme
struct  DictSubState


#define TSL_ADDPOS   0x01
#define TSL_PREFIX   0x02
#define TSL_FILTER   0x04


char * get_tsearch_config_filename (const char *basename, const char *extension)
void readstoplist (const char *fname, StopList *s, char *(*wordop)(const char *))
bool searchstoplist (StopList *s, char *key)

Define Documentation

#define TSL_ADDPOS   0x01

Definition at line 113 of file ts_public.h.

Referenced by parsetext().

#define TSL_FILTER   0x04

Definition at line 115 of file ts_public.h.

Referenced by LexizeExec().

#define TSL_PREFIX   0x02

Definition at line 114 of file ts_public.h.

Referenced by pushval_morph().

Function Documentation

char* get_tsearch_config_filename ( const char *  basename,
const char *  extension 

Definition at line 33 of file ts_utils.c.

References ereport, errcode(), errmsg(), ERROR, get_share_path(), MAXPGPATH, my_exec_path, palloc(), and snprintf().

Referenced by dispell_init(), dsynonym_init(), initSuffixTree(), read_dictionary(), readstoplist(), and thesaurusRead().

    char        sharepath[MAXPGPATH];
    char       *result;

     * We limit the basename to contain a-z, 0-9, and underscores.  This may
     * be overly restrictive, but we don't want to allow access to anything
     * outside the tsearch_data directory, so for instance '/' *must* be
     * rejected, and on some platforms '\' and ':' are risky as well. Allowing
     * uppercase might result in incompatible behavior between case-sensitive
     * and case-insensitive filesystems, and non-ASCII characters create other
     * interesting risks, so on the whole a tight policy seems best.
    if (strspn(basename, "abcdefghijklmnopqrstuvwxyz0123456789_") != strlen(basename))
                 errmsg("invalid text search configuration file name \"%s\"",

    get_share_path(my_exec_path, sharepath);
    result = palloc(MAXPGPATH);
    snprintf(result, MAXPGPATH, "%s/tsearch_data/%s.%s",
             sharepath, basename, extension);

    return result;

void readstoplist ( const char *  fname,
StopList s,
char *(*)(const char *)  wordop 

Definition at line 68 of file ts_utils.c.

References ereport, errcode(), errmsg(), ERROR, filename, get_tsearch_config_filename(), StopList::len, NULL, palloc(), pfree(), pg_mblen(), pg_qsort_strcmp(), qsort, repalloc(), StopList::stop, t_isspace, tsearch_readline(), tsearch_readline_begin(), and tsearch_readline_end().

Referenced by dispell_init(), dsimple_init(), and dsnowball_init().

    char      **stop = NULL;

    s->len = 0;
    if (fname && *fname)
        char       *filename = get_tsearch_config_filename(fname, "stop");
        tsearch_readline_state trst;
        char       *line;
        int         reallen = 0;

        if (!tsearch_readline_begin(&trst, filename))
                     errmsg("could not open stop-word file \"%s\": %m",

        while ((line = tsearch_readline(&trst)) != NULL)
            char       *pbuf = line;

            /* Trim trailing space */
            while (*pbuf && !t_isspace(pbuf))
                pbuf += pg_mblen(pbuf);
            *pbuf = '\0';

            /* Skip empty lines */
            if (*line == '\0')

            if (s->len >= reallen)
                if (reallen == 0)
                    reallen = 64;
                    stop = (char **) palloc(sizeof(char *) * reallen);
                    reallen *= 2;
                    stop = (char **) repalloc((void *) stop,
                                              sizeof(char *) * reallen);

            if (wordop)
                stop[s->len] = wordop(line);
                if (stop[s->len] != line)
                stop[s->len] = line;



    s->stop = stop;

    /* Sort to allow binary searching */
    if (s->stop && s->len > 0)
        qsort(s->stop, s->len, sizeof(char *), pg_qsort_strcmp);

bool searchstoplist ( StopList s,
char *  key 

Definition at line 141 of file ts_utils.c.

References StopList::len, pg_qsort_strcmp(), and StopList::stop.

Referenced by dispell_lexize(), dsimple_lexize(), and dsnowball_lexize().

    return (s->stop && s->len > 0 &&
            bsearch(&key, s->stop, s->len,
                    sizeof(char *), pg_qsort_strcmp)) ? true : false;