[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.83, Mon Jan 22 20:23:58 2007 UTC
# Line 548  Line 548 
548          if (my $notes = $entityData->{Notes}) {          if (my $notes = $entityData->{Notes}) {
549              $retVal .= "<p>" . HTMLNote($notes->{content}) . "</p>\n";              $retVal .= "<p>" . HTMLNote($notes->{content}) . "</p>\n";
550          }          }
551          # Now we want a list of the entity's relationships. First, we set up the relationship subsection.          # See if we need a list of the entity's relationships.
552            my $relCount = keys %{$relationshipList};
553            if ($relCount > 0) {
554                # First, we set up the relationship subsection.
555          $retVal .= "<h4>Relationships for <b>$key</b></h4>\n<ul>\n";          $retVal .= "<h4>Relationships for <b>$key</b></h4>\n<ul>\n";
556          # Loop through the relationships.          # Loop through the relationships.
557          for my $relationship (sort keys %{$relationshipList}) {          for my $relationship (sort keys %{$relationshipList}) {
# Line 564  Line 567 
567          }          }
568          # Close off the relationship list.          # Close off the relationship list.
569          $retVal .= "</ul>\n";          $retVal .= "</ul>\n";
570            }
571          # Get the entity's relations.          # Get the entity's relations.
572          my $relationList = $entityData->{Relations};          my $relationList = $entityData->{Relations};
573          # Create a header for the relation subsection.          # Create a header for the relation subsection.
# Line 1493  Line 1497 
1497          my $actualKeywords = $self->CleanKeywords($searchExpression);          my $actualKeywords = $self->CleanKeywords($searchExpression);
1498          # Prefix a "+" to each uncontrolled word. This converts the default          # Prefix a "+" to each uncontrolled word. This converts the default
1499          # search mode from OR to AND.          # search mode from OR to AND.
1500          $actualKeywords =~ s/(^|\s)(\w)/$1\+$2/g;          $actualKeywords =~ s/(^|\s)(\w|")/$1\+$2/g;
1501          Trace("Actual keywords for search are\n$actualKeywords") if T(3);          Trace("Actual keywords for search are\n$actualKeywords") if T(3);
1502          # 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
1503          # 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 2589 
2589              # 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.
2590              # 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
2591              # primary relations are allowed that privilege.              # primary relations are allowed that privilege.
2592                Trace("Checking for full-text index on $relationName.") if T(2);
2593              if ($self->_IsPrimary($relationName)) {              if ($self->_IsPrimary($relationName)) {
2594                  # 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');  
                 }  
2595              }              }
2596          }          }
2597      }      }
# Line 2608  Line 2603 
2603      return $retVal;      return $retVal;
2604  }  }
2605    
2606    =head3 CreateSearchIndex
2607    
2608    C<< $erdb->CreateSearchIndex($objectName); >>
2609    
2610    Check for a full-text search index on the specified entity or relationship object, and
2611    if one is required, rebuild it.
2612    
2613    =over 4
2614    
2615    =item objectName
2616    
2617    Name of the entity or relationship to be indexed.
2618    
2619    =back
2620    
2621    =cut
2622    
2623    sub CreateSearchIndex {
2624        # Get the parameters.
2625        my ($self, $objectName) = @_;
2626        # Get the relation's entity/relationship structure.
2627        my $structure = $self->_GetStructure($objectName);
2628        # Get the database handle.
2629        my $dbh = $self->{_dbh};
2630        Trace("Checking for search fields in $objectName.") if T(3);
2631        # Check for a searchable fields list.
2632        if (exists $structure->{searchFields}) {
2633            # Here we know that we need to create a full-text search index.
2634            # Get an SQL-formatted field name list.
2635            my $fields = join(", ", _FixNames(@{$structure->{searchFields}}));
2636            # Create the index. If it already exists, it will be dropped.
2637            $dbh->create_index(tbl => $objectName, idx => "search_idx",
2638                               flds => $fields, kind => 'fulltext');
2639            Trace("Index created for $fields in $objectName.") if T(2);
2640        }
2641    }
2642    
2643  =head3 DropRelation  =head3 DropRelation
2644    
2645  C<< $erdb->DropRelation($relationName); >>  C<< $erdb->DropRelation($relationName); >>
# Line 3294  Line 3326 
3326      # Substitute the bulletin board codes.      # Substitute the bulletin board codes.
3327      $retVal =~ s!\[(/?[bi])\]!<$1>!g;      $retVal =~ s!\[(/?[bi])\]!<$1>!g;
3328      $retVal =~ s!\[p\]!</p><p>!g;      $retVal =~ s!\[p\]!</p><p>!g;
3329        $retVal =~ s!\[link\s+([^\]]+)\]!<a href="$1">!g;
3330        $retVal =~ s!\[/link\]!</a>!g;
3331      # Return the result.      # Return the result.
3332      return $retVal;      return $retVal;
3333  }  }
# Line 4238  Line 4272 
4272          _FixupFields($relationshipStructure, $relationshipName, 2, 3);          _FixupFields($relationshipStructure, $relationshipName, 2, 3);
4273          # Format a description for the FROM field.          # Format a description for the FROM field.
4274          my $fromEntity = $relationshipStructure->{from};          my $fromEntity = $relationshipStructure->{from};
4275          my $fromComment = "<b>id</b> of the source <b><a href=\"#$fromEntity\">$fromEntity</a></b>.";          my $fromComment = "[b]id[/b] of the source [b][link #$fromEntity]$fromEntity\[/link][/b].";
4276          # Get the FROM entity's key type.          # Get the FROM entity's key type.
4277          my $fromType = $entityList->{$fromEntity}->{keyType};          my $fromType = $entityList->{$fromEntity}->{keyType};
4278          # Add the FROM field.          # Add the FROM field.
# Line 4248  Line 4282 
4282                                                      PrettySort => 1});                                                      PrettySort => 1});
4283          # Format a description for the TO field.          # Format a description for the TO field.
4284          my $toEntity = $relationshipStructure->{to};          my $toEntity = $relationshipStructure->{to};
4285          my $toComment = "<b>id</b> of the target <b><a href=\"#$toEntity\">$toEntity</a></b>.";          my $toComment = "[b]id[/b] of the target [b][link #$toEntity]$toEntity\[/link][/b].";
4286          # Get the TO entity's key type.          # Get the TO entity's key type.
4287          my $toType = $entityList->{$toEntity}->{keyType};          my $toType = $entityList->{$toEntity}->{keyType};
4288          # Add the TO field.          # Add the TO field.
# Line 4951  Line 4985 
4985      # Compute the number of columns.      # Compute the number of columns.
4986      my $colCount = @colNames;      my $colCount = @colNames;
4987      # Generate the title row.      # Generate the title row.
4988      my $htmlString = "<p><table border=\"2\"><tr><td colspan=\"$colCount\" align=\"center\">$tablename</td></tr>\n";      my $htmlString = "<table border=\"2\"><tr><td colspan=\"$colCount\" align=\"center\">$tablename</td></tr>\n";
4989      # Loop through the columns, adding the column header rows.      # Loop through the columns, adding the column header rows.
4990      $htmlString .= "<tr>";      $htmlString .= "<tr>";
4991      for my $colName (@colNames) {      for my $colName (@colNames) {
# Line 4970  Line 5004 
5004  =cut  =cut
5005    
5006  sub _CloseTable {  sub _CloseTable {
5007      return "</table></p>\n";      return "</table>\n";
5008  }  }
5009    
5010  =head3 _ShowField  =head3 _ShowField

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3