--- SearchBuilder.pm.orig	Fri Jul 29 16:49:52 2005
+++ SearchBuilder.pm	Mon Aug 22 13:40:38 2005
@@ -688,9 +688,15 @@
 
     if ( $args{'FIELD'} ) {
 
-        #If it's a like, we supply the %s around the search term
+        #If it's a like, we supply the %s around the search term only if its not Oracle
+        #because for Oracle we'll use where contains(content,'text')>1
         if ( $args{'OPERATOR'} =~ /LIKE/i ) {
-            $args{'VALUE'} = "%" . $args{'VALUE'} . "%";
+            if ( $RT::DatabaseType == 'Oracle') {
+                 $args{'VALUE'} = $args{'VALUE'} 
+            }
+            else {
+                $args{'VALUE'} = "%" . $args{'VALUE'} . "%";
+            }
         }
         elsif ( $args{'OPERATOR'} =~ /STARTSWITH/i ) {
             $args{'VALUE'}    = $args{'VALUE'} . "%";
@@ -864,6 +870,20 @@
     }
 
     my $clause = "($QualifiedField $args{'OPERATOR'} $args{'VALUE'})";
+
+# Keep the original clause and modify if dbtype is Oracle
+# This patch makes searching for ticket content real fast when you have the appropriate
+# index on attachments.content
+# CREATE INDEX CNT ON ATTACHMENTS (CONTENT) INDEXTYPE IS CTXSYS.CONTEXT PARAMETERS('memory 4M');
+# parameters is tunable, see Oracle docs ;-)
+    if ( $RT::DatabaseType == 'Oracle' ) {
+        if ($QualifiedField eq 'lower(Attachments_2.Content)' and $args{'OPERATOR'} eq 'LIKE') {
+            $clause = '(contains(Attachments_2.Content,' . $args{'VALUE'} . ') >0)';
+        }
+        elsif ($QualifiedField eq 'lower(Attachments_2.Content)' and $args{'OPERATOR'} eq 'NOT LIKE') {
+            $clause = '(not contains(Attachments_2.Content,' . $args{'VALUE'} . ') >0)';
+        }
+    }
 
     # Juju because this should come _AFTER_ the EA
     my $prefix = "";
