# Description: If a tsearch/stem dictionary is not found in /usr/share/postgresql/VERSION/tsearch_data/, fall back to /var/cache/postgresql/dicts/, where postgresql-common creates them from system directories.
# Ubuntu: https://launchpad.net/bugs/301770
--- ./src/backend/tsearch/ts_utils.c.orig	2008-12-01 06:47:28.000000000 -0800
+++ ./src/backend/tsearch/ts_utils.c	2008-12-01 07:05:14.000000000 -0800
@@ -15,6 +15,7 @@
 #include "postgres.h"
 
 #include <ctype.h>
+#include <unistd.h>
 
 #include "miscadmin.h"
 #include "tsearch/ts_locale.h"
@@ -36,7 +37,7 @@
 							const char *extension)
 {
 	char		sharepath[MAXPGPATH];
-	char	   *result;
+	char	   *result, *system_result;
 
 	/*
 	 * We limit the basename to contain a-z, 0-9, and underscores.	This may
@@ -58,6 +59,21 @@
 	snprintf(result, MAXPGPATH, "%s/tsearch_data/%s.%s",
 			 sharepath, basename, extension);
 
+	/* fall back to /var/cache/postgresql/dicts/ */
+	if (access(result, R_OK) != 0)
+	{
+		system_result = palloc(MAXPGPATH);
+		snprintf(system_result, MAXPGPATH, "/var/cache/postgresql/dicts/%s.%s",
+			 basename, extension);
+		if (access(system_result, R_OK) == 0)
+		{
+			pfree(result);
+			result = system_result;
+		} 
+		else
+			pfree(system_result);
+	}
+
 	return result;
 }
 
