On Mon, 2007-09-10 at 10:21 -0400, Tom Lane wrote:
> Oleg Bartunov <[EMAIL PROTECTED]> writes:
> > On Mon, 10 Sep 2007, Simon Riggs wrote:
> >> Can we include that functionality now?
> 
> > This could be realized very easyly using dict_strict, which returns
> > only known words, and mapping contains only this dictionary. So, 
> > feel free to write it and submit.
> 
> ... for 8.4.

I've coded a small patch to allow CaseSensitive synonyms.

  CREATE TEXT SEARCH DICTIONARY my_diction (
     TEMPLATE = biglist,
     DictFile = words,
     CaseSensitive = true
  );

-- 
  Simon Riggs
  2ndQuadrant  http://www.2ndQuadrant.com
Index: src/backend/tsearch/dict_synonym.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/tsearch/dict_synonym.c,v
retrieving revision 1.4
diff -c -r1.4 dict_synonym.c
*** src/backend/tsearch/dict_synonym.c	25 Aug 2007 02:29:45 -0000	1.4
--- src/backend/tsearch/dict_synonym.c	10 Sep 2007 15:14:21 -0000
***************
*** 29,34 ****
--- 29,35 ----
  typedef struct
  {
  	int			len;	/* length of syn array */
+ 	bool		case_sensitive;
  	Syn		   *syn;
  } DictSyn;
  
***************
*** 83,88 ****
--- 84,90 ----
  			   *end = NULL;
  	int			cur = 0;
  	char	   *line = NULL;
+ 	bool		case_sensitive = false;
  
  	foreach(l, dictoptions)
  	{
***************
*** 95,100 ****
--- 97,107 ----
  					(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
  					 errmsg("unrecognized synonym parameter: \"%s\"",
  							defel->defname)));
+ 
+ 		if (pg_strcasecmp("CaseSensitive", defel->defname) == 0 &&
+ 			pg_strcasecmp("True", defGetString(defel)) == 0)
+ 			case_sensitive = true;
+ 
  	}
  
  	if (!filename)
***************
*** 168,173 ****
--- 175,182 ----
  	d->len = cur;
  	qsort(d->syn, d->len, sizeof(Syn), compareSyn);
  
+ 	d->case_sensitive = case_sensitive;
+ 
  	PG_RETURN_POINTER(d);
  }
  
***************
*** 180,195 ****
  	Syn			key,
  			   *found;
  	TSLexeme   *res;
  
  	/* note: d->len test protects against Solaris bsearch-of-no-items bug */
  	if (len <= 0 || d->len <= 0)
  		PG_RETURN_POINTER(NULL);
  
! 	key.in = lowerstr_with_len(in, len);
  	key.out = NULL;
  
  	found = (Syn *) bsearch(&key, d->syn, d->len, sizeof(Syn), compareSyn);
! 	pfree(key.in);
  
  	if (!found)
  		PG_RETURN_POINTER(NULL);
--- 189,214 ----
  	Syn			key,
  			   *found;
  	TSLexeme   *res;
+ 	bool		need_pfree = false;
  
  	/* note: d->len test protects against Solaris bsearch-of-no-items bug */
  	if (len <= 0 || d->len <= 0)
  		PG_RETURN_POINTER(NULL);
  
! 	if (d->case_sensitive)
! 		key.in = in;
! 	else
! 	{
! 		key.in = lowerstr_with_len(in, len);
! 		need_pfree = true;
! 	}
! 
  	key.out = NULL;
  
  	found = (Syn *) bsearch(&key, d->syn, d->len, sizeof(Syn), compareSyn);
! 
! 	if (need_pfree)
! 		pfree(key.in);
  
  	if (!found)
  		PG_RETURN_POINTER(NULL);
---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Reply via email to