From 638bd34f899fbcbb6571458be8e8e09d82c70020 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 19 Oct 2007 22:01:45 +0000 Subject: [PATCH] Found another small glitch in tsearch API: the two versions of ts_lexize() are really redundant, since we invented a regdictionary alias type. We can have just one function, declared as taking regdictionary, and it will handle both behaviors. Noted while working on documentation. --- src/backend/tsearch/dict.c | 60 +++++--------------------------- src/include/catalog/catversion.h | 4 +-- src/include/catalog/pg_proc.h | 6 ++-- src/include/tsearch/ts_utils.h | 5 ++- 4 files changed, 15 insertions(+), 60 deletions(-) diff --git a/src/backend/tsearch/dict.c b/src/backend/tsearch/dict.c index 15deb71af6..0459a5c1b0 100644 --- a/src/backend/tsearch/dict.c +++ b/src/backend/tsearch/dict.c @@ -7,41 +7,31 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/tsearch/dict.c,v 1.1 2007/08/21 01:11:18 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/tsearch/dict.c,v 1.2 2007/10/19 22:01:45 tgl Exp $ * *------------------------------------------------------------------------- */ #include "postgres.h" -#include "funcapi.h" -#include "access/genam.h" -#include "access/heapam.h" -#include "access/skey.h" -#include "catalog/indexing.h" -#include "catalog/namespace.h" -#include "catalog/pg_ts_dict.h" #include "catalog/pg_type.h" #include "tsearch/ts_cache.h" -#include "tsearch/ts_public.h" #include "tsearch/ts_utils.h" -#include "utils/array.h" #include "utils/builtins.h" -#include "utils/fmgroids.h" -#include "utils/rel.h" -#include "utils/syscache.h" /* * Lexize one word by dictionary, mostly debug function */ -static ArrayType * -ts_lexize_workhorse(Oid dictId, text *in) +Datum +ts_lexize(PG_FUNCTION_ARGS) { + Oid dictId = PG_GETARG_OID(0); + text *in = PG_GETARG_TEXT_P(1); + ArrayType *a; TSDictionaryCacheEntry *dict; TSLexeme *res, *ptr; Datum *da; - ArrayType *a; DictSubState dstate = {false, false, NULL}; dict = lookup_ts_dictionary_cache(dictId); @@ -65,12 +55,12 @@ ts_lexize_workhorse(Oid dictId, text *in) } if (!res) - return NULL; + PG_RETURN_NULL(); ptr = res; while (ptr->lexeme) ptr++; - da = (Datum *) palloc(sizeof(Datum) * (ptr - res + 1)); + da = (Datum *) palloc(sizeof(Datum) * (ptr - res)); ptr = res; while (ptr->lexeme) { @@ -95,37 +85,5 @@ ts_lexize_workhorse(Oid dictId, text *in) pfree(res); pfree(da); - return a; -} - -Datum -ts_lexize_byid(PG_FUNCTION_ARGS) -{ - Oid dictId = PG_GETARG_OID(0); - text *in = PG_GETARG_TEXT_P(1); - ArrayType *a; - - a = ts_lexize_workhorse(dictId, in); - - if (a) - PG_RETURN_POINTER(a); - else - PG_RETURN_NULL(); -} - -Datum -ts_lexize_byname(PG_FUNCTION_ARGS) -{ - text *dictname = PG_GETARG_TEXT_P(0); - text *in = PG_GETARG_TEXT_P(1); - Oid dictId; - ArrayType *a; - - dictId = TSDictionaryGetDictid(textToQualifiedNameList(dictname), false); - a = ts_lexize_workhorse(dictId, in); - - if (a) - PG_RETURN_POINTER(a); - else - PG_RETURN_NULL(); + PG_RETURN_POINTER(a); } diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 8342727f0f..467277d8ad 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -37,7 +37,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.433 2007/10/19 19:48:34 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.434 2007/10/19 22:01:45 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 200710191 +#define CATALOG_VERSION_NO 200710192 #endif diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index 045c6e52f5..bd3eb5abc3 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.475 2007/10/19 19:48:34 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.476 2007/10/19 22:01:45 tgl Exp $ * * NOTES * The script catalog/genbki.sh reads this file and generates .bki @@ -4326,9 +4326,7 @@ DESCR(""); DATA(insert OID = 3721 ( prsd_lextype PGNSP PGUID 12 1 0 f f t f i 1 2281 "2281" _null_ _null_ _null_ prsd_lextype - _null_ _null_ )); DESCR(""); -DATA(insert OID = 3723 ( ts_lexize PGNSP PGUID 12 1 0 f f t f i 2 1009 "26 25" _null_ _null_ _null_ ts_lexize_byid - _null_ _null_ )); -DESCR("normalize one word by dictionary"); -DATA(insert OID = 3724 ( ts_lexize PGNSP PGUID 12 1 0 f f t f s 2 1009 "25 25" _null_ _null_ _null_ ts_lexize_byname - _null_ _null_ )); +DATA(insert OID = 3723 ( ts_lexize PGNSP PGUID 12 1 0 f f t f i 2 1009 "3769 25" _null_ _null_ _null_ ts_lexize - _null_ _null_ )); DESCR("normalize one word by dictionary"); DATA(insert OID = 3725 ( dsimple_init PGNSP PGUID 12 1 0 f f t f i 1 2281 "2281" _null_ _null_ _null_ dsimple_init - _null_ _null_ )); diff --git a/src/include/tsearch/ts_utils.h b/src/include/tsearch/ts_utils.h index 93da9cb4a9..60f176054a 100644 --- a/src/include/tsearch/ts_utils.h +++ b/src/include/tsearch/ts_utils.h @@ -5,7 +5,7 @@ * * Copyright (c) 1998-2007, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/include/tsearch/ts_utils.h,v 1.4 2007/09/10 12:36:41 teodor Exp $ + * $PostgreSQL: pgsql/src/include/tsearch/ts_utils.h,v 1.5 2007/10/19 22:01:45 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -222,8 +222,7 @@ extern Datum prsd_lextype(PG_FUNCTION_ARGS); /* * Dictionary interface to SQL */ -extern Datum ts_lexize_byid(PG_FUNCTION_ARGS); -extern Datum ts_lexize_byname(PG_FUNCTION_ARGS); +extern Datum ts_lexize(PG_FUNCTION_ARGS); /* * Simple built-in dictionary