[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.81, Wed Dec 20 20:03:25 2006 UTC revision 1.86, Mon Feb 12 19:23:32 2007 UTC
# Line 228  Line 228 
228    
229  =head3 Indexes  =head3 Indexes
230    
231  An entity can have multiple alternate indexes associated with it. The fields must  An entity can have multiple alternate indexes associated with it. The fields in an
232  all be from the same relation. The alternate indexes assist in ordering results  index must all be from the same relation. The alternate indexes assist in searching
233  from a query. A relationship can have up to two indexes-- a I<to-index> and a  on fields other than the entity ID. A relationship has at least two indexes-- a I<to-index> and a
234  I<from-index>. These order the results when crossing the relationship. For  I<from-index> that order the results when crossing the relationship. For
235  example, in the relationship C<HasContig> from C<Genome> to C<Contig>, the  example, in the relationship C<HasContig> from C<Genome> to C<Contig>, the
236  from-index would order the contigs of a ganome, and the to-index would order  from-index would order the contigs of a ganome, and the to-index would order
237  the genomes of a contig. A relationship's index must specify only fields in  the genomes of a contig. In addition, it can have zero or more alternate
238    indexes. A relationship's index must specify only fields in
239  the relationship.  the relationship.
240    
241  The indexes for an entity must be listed inside the B<Indexes> tag. The from-index  The alternate indexes for an entity or relationship must be listed inside the B<Indexes> tag.
242  of a relationship is specified using the B<FromIndex> tag; the to-index is specified  The from-index of a relationship is specified using the B<FromIndex> tag; the to-index is
243  using the B<ToIndex> tag.  specified using the B<ToIndex> tag.
244    
245  Each index can contain a B<Notes> tag. In addition, it will have an B<IndexFields>  Each index can contain a B<Notes> tag. In addition, it will have an B<IndexFields>
246  tag containing the B<IndexField> tags. These specify, in order, the fields used in  tag containing the B<IndexField> tags. These specify, in order, the fields used in
# Line 303  Line 304 
304    
305  A relationship is described by the C<Relationship> tag. Within a relationship,  A relationship is described by the C<Relationship> tag. Within a relationship,
306  there can be a C<Notes> tag, a C<Fields> tag containing the intersection data  there can be a C<Notes> tag, a C<Fields> tag containing the intersection data
307  fields, a C<FromIndex> tag containing the from-index, and a C<ToIndex> tag containing  fields, a C<FromIndex> tag containing the from-index, a C<ToIndex> tag containing
308  the to-index.  the to-index, and an C<Indexes> tag containing the alternate indexes.
309    
310  The C<Relationship> tag has the following attributes.  The C<Relationship> tag has the following attributes.
311    
# Line 548  Line 549 
549          if (my $notes = $entityData->{Notes}) {          if (my $notes = $entityData->{Notes}) {
550              $retVal .= "<p>" . HTMLNote($notes->{content}) . "</p>\n";              $retVal .= "<p>" . HTMLNote($notes->{content}) . "</p>\n";
551          }          }
552          # 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.
553            my $relCount = keys %{$relationshipList};
554            if ($relCount > 0) {
555                # First, we set up the relationship subsection.
556          $retVal .= "<h4>Relationships for <b>$key</b></h4>\n<ul>\n";          $retVal .= "<h4>Relationships for <b>$key</b></h4>\n<ul>\n";
557          # Loop through the relationships.          # Loop through the relationships.
558          for my $relationship (sort keys %{$relationshipList}) {          for my $relationship (sort keys %{$relationshipList}) {
# Line 564  Line 568 
568          }          }
569          # Close off the relationship list.          # Close off the relationship list.
570          $retVal .= "</ul>\n";          $retVal .= "</ul>\n";
571            }
572          # Get the entity's relations.          # Get the entity's relations.
573          my $relationList = $entityData->{Relations};          my $relationList = $entityData->{Relations};
574          # Create a header for the relation subsection.          # Create a header for the relation subsection.
# Line 1841  Line 1846 
1846          for my $dir ('from', 'to') {          for my $dir ('from', 'to') {
1847              if ($structure->{$dir} eq $originEntityName) {              if ($structure->{$dir} eq $originEntityName) {
1848                  # Delete all relationship instances on this side of the entity instance.                  # Delete all relationship instances on this side of the entity instance.
1849                    Trace("Disconnecting in $dir direction with ID \"$originEntityID\".");
1850                  $dbh->SQL("DELETE FROM $relationshipName WHERE ${dir}_link = ?", 0, $originEntityID);                  $dbh->SQL("DELETE FROM $relationshipName WHERE ${dir}_link = ?", 0, $originEntityID);
1851                  $found = 1;                  $found = 1;
1852              }              }
# Line 2428  Line 2434 
2434                  if (!$retVal) {                  if (!$retVal) {
2435                      my $errorString = $sth->errstr();                      my $errorString = $sth->errstr();
2436                      Confess("Error inserting into $relationName: $errorString");                      Confess("Error inserting into $relationName: $errorString");
2437                    } else {
2438                        Trace("Insert successful using $parameterList[0].") if T(3);
2439                  }                  }
2440              }              }
2441          }          }
# Line 2587  Line 2595 
2595              # primary relations are allowed that privilege.              # primary relations are allowed that privilege.
2596              Trace("Checking for full-text index on $relationName.") if T(2);              Trace("Checking for full-text index on $relationName.") if T(2);
2597              if ($self->_IsPrimary($relationName)) {              if ($self->_IsPrimary($relationName)) {
2598                  # Get the relation's entity/relationship structure.                  $self->CreateSearchIndex($relationName);
                 my $structure = $self->_GetStructure($relationName);  
                 Trace("Checking for search fields in $relationName.") if T(3);  
                 # 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(", ", _FixNames(@{$structure->{searchFields}}));  
                     # Create the index.  
                     $dbh->create_index(tbl => $relationName, idx => "search_idx",  
                                        flds => $fields, kind => 'fulltext');  
                     Trace("Index created for $fields in $relationName.") if T(2);  
                 }  
2599              }              }
2600          }          }
2601      }      }
# Line 2611  Line 2607 
2607      return $retVal;      return $retVal;
2608  }  }
2609    
2610    =head3 CreateSearchIndex
2611    
2612    C<< $erdb->CreateSearchIndex($objectName); >>
2613    
2614    Check for a full-text search index on the specified entity or relationship object, and
2615    if one is required, rebuild it.
2616    
2617    =over 4
2618    
2619    =item objectName
2620    
2621    Name of the entity or relationship to be indexed.
2622    
2623    =back
2624    
2625    =cut
2626    
2627    sub CreateSearchIndex {
2628        # Get the parameters.
2629        my ($self, $objectName) = @_;
2630        # Get the relation's entity/relationship structure.
2631        my $structure = $self->_GetStructure($objectName);
2632        # Get the database handle.
2633        my $dbh = $self->{_dbh};
2634        Trace("Checking for search fields in $objectName.") if T(3);
2635        # Check for a searchable fields list.
2636        if (exists $structure->{searchFields}) {
2637            # Here we know that we need to create a full-text search index.
2638            # Get an SQL-formatted field name list.
2639            my $fields = join(", ", _FixNames(@{$structure->{searchFields}}));
2640            # Create the index. If it already exists, it will be dropped.
2641            $dbh->create_index(tbl => $objectName, idx => "search_idx",
2642                               flds => $fields, kind => 'fulltext');
2643            Trace("Index created for $fields in $objectName.") if T(2);
2644        }
2645    }
2646    
2647  =head3 DropRelation  =head3 DropRelation
2648    
2649  C<< $erdb->DropRelation($relationName); >>  C<< $erdb->DropRelation($relationName); >>
# Line 3297  Line 3330 
3330      # Substitute the bulletin board codes.      # Substitute the bulletin board codes.
3331      $retVal =~ s!\[(/?[bi])\]!<$1>!g;      $retVal =~ s!\[(/?[bi])\]!<$1>!g;
3332      $retVal =~ s!\[p\]!</p><p>!g;      $retVal =~ s!\[p\]!</p><p>!g;
3333        $retVal =~ s!\[link\s+([^\]]+)\]!<a href="$1">!g;
3334        $retVal =~ s!\[/link\]!</a>!g;
3335      # Return the result.      # Return the result.
3336      return $retVal;      return $retVal;
3337  }  }
# Line 4068  Line 4103 
4103    
4104  =head3 _LoadMetaData  =head3 _LoadMetaData
4105    
4106    C<< my $metadata = ERDB::_LoadMetaData($filename); >>
4107    
4108  This method loads the data describing this database from an XML file into a metadata structure.  This method loads the data describing this database from an XML file into a metadata structure.
4109  The resulting structure is a set of nested hash tables containing all the information needed to  The resulting structure is a set of nested hash tables containing all the information needed to
4110  load or use the database. The schema for the XML file is F<ERDatabase.xml>.  load or use the database. The schema for the XML file is F<ERDatabase.xml>.
# Line 4241  Line 4278 
4278          _FixupFields($relationshipStructure, $relationshipName, 2, 3);          _FixupFields($relationshipStructure, $relationshipName, 2, 3);
4279          # Format a description for the FROM field.          # Format a description for the FROM field.
4280          my $fromEntity = $relationshipStructure->{from};          my $fromEntity = $relationshipStructure->{from};
4281          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].";
4282          # Get the FROM entity's key type.          # Get the FROM entity's key type.
4283          my $fromType = $entityList->{$fromEntity}->{keyType};          my $fromType = $entityList->{$fromEntity}->{keyType};
4284          # Add the FROM field.          # Add the FROM field.
# Line 4251  Line 4288 
4288                                                      PrettySort => 1});                                                      PrettySort => 1});
4289          # Format a description for the TO field.          # Format a description for the TO field.
4290          my $toEntity = $relationshipStructure->{to};          my $toEntity = $relationshipStructure->{to};
4291          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].";
4292          # Get the TO entity's key type.          # Get the TO entity's key type.
4293          my $toType = $entityList->{$toEntity}->{keyType};          my $toType = $entityList->{$toEntity}->{keyType};
4294          # Add the TO field.          # Add the TO field.
# Line 4954  Line 4991 
4991      # Compute the number of columns.      # Compute the number of columns.
4992      my $colCount = @colNames;      my $colCount = @colNames;
4993      # Generate the title row.      # Generate the title row.
4994      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";
4995      # Loop through the columns, adding the column header rows.      # Loop through the columns, adding the column header rows.
4996      $htmlString .= "<tr>";      $htmlString .= "<tr>";
4997      for my $colName (@colNames) {      for my $colName (@colNames) {
# Line 4973  Line 5010 
5010  =cut  =cut
5011    
5012  sub _CloseTable {  sub _CloseTable {
5013      return "</table></p>\n";      return "</table>\n";
5014  }  }
5015    
5016  =head3 _ShowField  =head3 _ShowField

Legend:
Removed from v.1.81  
changed lines
  Added in v.1.86

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3