[open-ils-commits] r9147 - branches/rel_1_2/Open-ILS/src/sql/Pg

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Mar 27 01:12:31 EDT 2008


Author: miker
Date: 2008-03-27 00:37:08 -0400 (Thu, 27 Mar 2008)
New Revision: 9147

Modified:
   branches/rel_1_2/Open-ILS/src/sql/Pg/300.schema.staged_search.sql
Log:
protect regexp-special characters in phrase search

Modified: branches/rel_1_2/Open-ILS/src/sql/Pg/300.schema.staged_search.sql
===================================================================
--- branches/rel_1_2/Open-ILS/src/sql/Pg/300.schema.staged_search.sql	2008-03-27 04:36:16 UTC (rev 9146)
+++ branches/rel_1_2/Open-ILS/src/sql/Pg/300.schema.staged_search.sql	2008-03-27 04:37:08 UTC (rev 9147)
@@ -211,8 +211,17 @@
               WHERE term_type = 'phrase'
                     AND table_alias = query_part.table_alias LOOP
 
-            inner_where_clause := inner_where_clause || ' AND ' || 'value  ~* ' || quote_literal( E'(^|\\W+)' || regexp_replace(phrase_query_part.term, E'\\s+',E'\\\\s+','g') || E'(\\W+|\$)' );
+            tmp_text := replace( phrase_query_part.term, '*', E'\\*' );
+            tmp_text := replace( tmp_text, '?', E'\\?' );
+            tmp_text := replace( tmp_text, '+', E'\\+' );
+            tmp_text := replace( tmp_text, '|', E'\\|' );
+            tmp_text := replace( tmp_text, '(', E'\\(' );
+            tmp_text := replace( tmp_text, ')', E'\\)' );
+            tmp_text := replace( tmp_text, '[', E'\\[' );
+            tmp_text := replace( tmp_text, ']', E'\\]' );
 
+            inner_where_clause := inner_where_clause || ' AND ' || 'value  ~* ' || quote_literal( E'(^|\\W+)' || regexp_replace(tmp_text, E'\\s+',E'\\\\s+','g') || E'(\\W+|\$)' );
+
         END LOOP;
 
         query_table := search.pick_table(query_part.field_class);



More information about the open-ils-commits mailing list