*** ./contrib/tsearch2.orig/./expected/tsearch2.out	Wed Aug 23 14:58:46 2006
--- ./contrib/tsearch2/./expected/tsearch2.out	Wed Aug 23 15:57:33 2006
***************
*** 59,83 ****
  SELECT E'''1 \\''2'''::tsvector;
   tsvector 
  ----------
!  '1 \'2' 
  (1 row)
  
  SELECT E'''1 \\''2''3'::tsvector;
    tsvector   
  -------------
!  '3' '1 \'2'
  (1 row)
  
  SELECT E'''1 \\''2'' 3'::tsvector;
    tsvector   
  -------------
!  '3' '1 \'2'
  (1 row)
  
  SELECT E'''1 \\''2'' '' 3'' 4 '::tsvector;
       tsvector     
  ------------------
!  '4' ' 3' '1 \'2'
  (1 row)
  
  select '''w'':4A,3B,2C,1D,5 a:8';
--- 59,83 ----
  SELECT E'''1 \\''2'''::tsvector;
   tsvector 
  ----------
!  '1 ''2'
  (1 row)
  
  SELECT E'''1 \\''2''3'::tsvector;
    tsvector   
  -------------
!  '3' '1 ''2'
  (1 row)
  
  SELECT E'''1 \\''2'' 3'::tsvector;
    tsvector   
  -------------
!  '3' '1 ''2'
  (1 row)
  
  SELECT E'''1 \\''2'' '' 3'' 4 '::tsvector;
       tsvector     
  ------------------
!  '4' ' 3' '1 ''2'
  (1 row)
  
  select '''w'':4A,3B,2C,1D,5 a:8';
***************
*** 138,144 ****
  SELECT E'''1 \\''2'''::tsquery;
   tsquery 
  ---------
!  '1 \'2'
  (1 row)
  
  SELECT '!1'::tsquery;
--- 138,144 ----
  SELECT E'''1 \\''2'''::tsquery;
   tsquery 
  ---------
!  '1 ''2'
  (1 row)
  
  SELECT '!1'::tsquery;
***************
*** 336,342 ****
  SELECT E'1&(''2''&('' 4''&(\\|5 | ''6 \\'' !|&'')))'::tsquery;
                   tsquery                  
  ------------------------------------------
!  '1' & '2' & ' 4' & ( '|5' | '6 \' !|&' )
  (1 row)
  
  SELECT '''the wether'':dc & '' sKies '':BC & a:d b:a';
--- 336,342 ----
  SELECT E'1&(''2''&('' 4''&(\\|5 | ''6 \\'' !|&'')))'::tsquery;
                   tsquery                  
  ------------------------------------------
!  '1' & '2' & ' 4' & ( '|5' | '6 '' !|&' )
  (1 row)
  
  SELECT '''the wether'':dc & '' sKies '':BC & a:d b:a';
*** ./contrib/tsearch2.orig/./tsvector.c	Wed Aug 23 14:58:46 2006
--- ./contrib/tsearch2/./tsvector.c	Wed Aug 23 15:57:33 2006
***************
*** 164,176 ****
  	return res + 1 - a;
  }
  
! #define WAITWORD	1
! #define WAITENDWORD 2
  #define WAITNEXTCHAR	3
  #define WAITENDCMPLX	4
! #define WAITPOSINFO 5
! #define INPOSINFO	6
  #define WAITPOSDELIM	7
  
  #define RESIZEPRSBUF \
  do { \
--- 164,177 ----
  	return res + 1 - a;
  }
  
! #define WAITWORD		1
! #define WAITENDWORD 	2
  #define WAITNEXTCHAR	3
  #define WAITENDCMPLX	4
! #define WAITPOSINFO 	5
! #define INPOSINFO		6
  #define WAITPOSDELIM	7
+ #define	WAITCHARCMPLX	8
  
  #define RESIZEPRSBUF \
  do { \
***************
*** 270,290 ****
  		}
  		else if (state->state == WAITENDCMPLX)
  		{
! 			if ( t_iseq(state->prsbuf, '\'') )
! 			{
! 				RESIZEPRSBUF;
! 				*(state->curpos) = '\0';
! 				if (state->curpos == state->word)
! 					ereport(ERROR,
! 							(errcode(ERRCODE_SYNTAX_ERROR),
! 							 errmsg("syntax error")));
! 				if (state->oprisdelim)
! 				{
! 					state->prsbuf+=pg_mblen(state->prsbuf);
! 					return 1;
! 				}
! 				else
! 					state->state = WAITPOSINFO;
  			}
  			else if ( t_iseq(state->prsbuf, '\\') )
  			{
--- 271,278 ----
  		}
  		else if (state->state == WAITENDCMPLX)
  		{
! 			if ( t_iseq(state->prsbuf, '\'') ) {
! 				state->state = WAITCHARCMPLX; 
  			}
  			else if ( t_iseq(state->prsbuf, '\\') )
  			{
***************
*** 302,307 ****
--- 290,320 ----
  				state->curpos+=pg_mblen(state->prsbuf);
  			}
  		}
+ 		else if (state->state == WAITCHARCMPLX)
+ 		{
+ 			if ( t_iseq(state->prsbuf, '\'') ) 
+ 			{
+ 				RESIZEPRSBUF;
+ 				COPYCHAR(state->curpos, state->prsbuf);
+ 				state->curpos+=pg_mblen(state->prsbuf);
+ 				state->state = WAITENDCMPLX;
+ 			} else {
+ 				RESIZEPRSBUF;
+ 				*(state->curpos) = '\0';
+ 				if (state->curpos == state->word)
+ 					ereport(ERROR,
+ 							(errcode(ERRCODE_SYNTAX_ERROR),
+ 							 errmsg("syntax error")));
+ 				if (state->oprisdelim)
+ 				{
+ 					/* state->prsbuf+=pg_mblen(state->prsbuf); */
+ 					return 1;
+ 				}
+ 				else
+ 					state->state = WAITPOSINFO;
+ 				continue; /* recheck current character */
+ 			}
+ 		}
  		else if (state->state == WAITPOSINFO)
  		{
  			if ( t_iseq(state->prsbuf, ':') )
***************
*** 385,390 ****
--- 398,405 ----
  		else
  			/* internal error */
  			elog(ERROR, "internal error");
+ 
+ 		/* get next char */
  		state->prsbuf+=pg_mblen(state->prsbuf);
  	}
  
***************
*** 529,535 ****
  
  				outbuf = (char *) repalloc((void *) outbuf, ++lenbuf);
  				curout = outbuf + pos;
! 				*curout++ = '\\';
  			}
  			while(len--)
  				*curout++ = *curin++;
--- 544,550 ----
  
  				outbuf = (char *) repalloc((void *) outbuf, ++lenbuf);
  				curout = outbuf + pos;
! 				*curout++ = '\'';
  			}
  			while(len--)
  				*curout++ = *curin++;
*** ./contrib/tsearch2.orig/./query.c	Wed Aug 23 14:58:46 2006
--- ./contrib/tsearch2/./query.c	Wed Aug 23 15:57:33 2006
***************
*** 604,610 ****
   * input
   */
  static QUERYTYPE *
! 			queryin(char *buf, void (*pushval) (QPRS_STATE *, int, char *, int, int2), int cfg_id, bool isplain)
  {
  	QPRS_STATE	state;
  	int4		i;
--- 604,610 ----
   * input
   */
  static QUERYTYPE *
! queryin(char *buf, void (*pushval) (QPRS_STATE *, int, char *, int, int2), int cfg_id, bool isplain)
  {
  	QPRS_STATE	state;
  	int4		i;
***************
*** 748,754 ****
  		{
  			if ( t_iseq(op, '\'') )
  			{
! 				*(in->cur) = '\\';
  				in->cur++;
  			}
  			COPYCHAR(in->cur,op);
--- 748,754 ----
  		{
  			if ( t_iseq(op, '\'') )
  			{
! 				*(in->cur) = '\'';
  				in->cur++;
  			}
  			COPYCHAR(in->cur,op);
