[Bio] / Sprout / ERDB.pm Repository:
ViewVC logotype

Diff of /Sprout/ERDB.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.79, Wed Nov 29 20:29:53 2006 UTC revision 1.82, Tue Jan 9 01:49:57 2007 UTC
# Line 1493  Line 1493 
1493          my $actualKeywords = $self->CleanKeywords($searchExpression);          my $actualKeywords = $self->CleanKeywords($searchExpression);
1494          # Prefix a "+" to each uncontrolled word. This converts the default          # Prefix a "+" to each uncontrolled word. This converts the default
1495          # search mode from OR to AND.          # search mode from OR to AND.
1496          $actualKeywords =~ s/(^|\s)(\w)/$1\+$2/g;          $actualKeywords =~ s/(^|\s)(\w|")/$1\+$2/g;
1497          Trace("Actual keywords for search are\n$actualKeywords") if T(3);          Trace("Actual keywords for search are\n$actualKeywords") if T(3);
1498          # We need two match expressions, one for the filter clause and one in the          # We need two match expressions, one for the filter clause and one in the
1499          # query itself. Both will use a parameter mark, so we need to push the          # query itself. Both will use a parameter mark, so we need to push the
# Line 2585  Line 2585 
2585              # The full-text index (if any) is always built last, even for MySQL.              # The full-text index (if any) is always built last, even for MySQL.
2586              # First we need to see if this table has a full-text index. Only              # First we need to see if this table has a full-text index. Only
2587              # primary relations are allowed that privilege.              # primary relations are allowed that privilege.
2588                Trace("Checking for full-text index on $relationName.") if T(2);
2589              if ($self->_IsPrimary($relationName)) {              if ($self->_IsPrimary($relationName)) {
2590                  # Get the relation's entity/relationship structure.                  $self->CreateSearchIndex($relationName);
                 my $structure = $self->_GetStructure($relationName);  
                 # Check for a searchable fields list.  
                 if (exists $structure->{searchFields}) {  
                     # Here we know that we need to create a full-text search index.  
                     # Get an SQL-formatted field name list.  
                     my $fields = join(", ", $self->_FixNames(@{$structure->{searchFields}}));  
                     # Create the index.  
                     $dbh->create_index(tbl => $relationName, idx => "search_idx",  
                                        flds => $fields, kind => 'fulltext');  
                 }  
2591              }              }
2592          }          }
2593      }      }
# Line 2608  Line 2599 
2599      return $retVal;      return $retVal;
2600  }  }
2601    
2602    =head3 CreateSearchIndex
2603    
2604    C<< $erdb->CreateSearchIndex($objectName); >>
2605    
2606    Check for a full-text search index on the specified entity or relationship object, and
2607    if one is required, rebuild it.
2608    
2609    =over 4
2610    
2611    =item objectName
2612    
2613    Name of the entity or relationship to be indexed.
2614    
2615    =back
2616    
2617    =cut
2618    
2619    sub CreateSearchIndex {
2620        # Get the parameters.
2621        my ($self, $objectName) = @_;
2622        # Get the relation's entity/relationship structure.
2623        my $structure = $self->_GetStructure($objectName);
2624        # Get the database handle.
2625        my $dbh = $self->{_dbh};
2626        Trace("Checking for search fields in $objectName.") if T(3);
2627        # Check for a searchable fields list.
2628        if (exists $structure->{searchFields}) {
2629            # Here we know that we need to create a full-text search index.
2630            # Get an SQL-formatted field name list.
2631            my $fields = join(", ", _FixNames(@{$structure->{searchFields}}));
2632            # Create the index. If it already exists, it will be dropped.
2633            $dbh->create_index(tbl => $objectName, idx => "search_idx",
2634                               flds => $fields, kind => 'fulltext');
2635            Trace("Index created for $fields in $objectName.") if T(2);
2636        }
2637    }
2638    
2639  =head3 DropRelation  =head3 DropRelation
2640    
2641  C<< $erdb->DropRelation($relationName); >>  C<< $erdb->DropRelation($relationName); >>

Legend:
Removed from v.1.79  
changed lines
  Added in v.1.82

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3