Changeset 4047
- Timestamp:
- 06/06/09 15:44:38 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/QueryAcceleratorPlugin/lib/Foswiki/Store/QueryAlgorithms/DBCache.pm
r4042 r4047 11 11 12 12 package Foswiki::Store::QueryAlgorithms::DBCache; 13 14 13 use strict; 14 #@ISA = ( 'Foswiki::Query::QueryAlgorithms' ); # interface 15 15 16 use Assert; 16 17 use Error ( ':try' ); … … 19 20 20 21 # 1 for debug 21 sub MONITOR_EVAL { 0 } 22 22 sub MONITOR_EVAL { Foswiki::Query::Node::MONITOR_EVAL() } 23 24 # See Foswiki::Query::QueryAlgorithms in Foswiki 1.1 or later for details 23 25 sub query { 24 my ( $query, $web, $topics, $store ) = @_;26 my ( $query, $web, $topics, $store, $options ) = @_; 25 27 26 28 my $db = Foswiki::Plugins::QueryAcceleratorPlugin::getDB( $web ); 27 29 ASSERT($db) if DEBUG; 28 30 29 # Monkey-patch 30 my @saved = ( \&Foswiki::Query::Node::evaluate, 31 \&Foswiki::Query::OP_ref::evaluate ); 32 no warnings 'redefine'; 33 *Foswiki::Query::Node::evaluate = \&_nodeEvaluate; 34 *Foswiki::Query::OP_ref::evaluate = \&_op_refEvaluate; 35 use warnings 'redefine'; 31 my $is10 = (ref($topics) eq 'ARRAY'); # 1.0.x 32 my @monkeys; 33 34 if ($is10) { 35 # Monkey-patch 36 @monkeys = ( \&Foswiki::Query::Node::evaluate, 37 \&Foswiki::Query::OP_ref::evaluate ); 38 no warnings 'redefine'; 39 *Foswiki::Query::Node::evaluate = \&_nodeEvaluate; 40 *Foswiki::Query::OP_ref::evaluate = \&_op_refEvaluate; 41 use warnings 'redefine'; 42 } 36 43 37 44 my %matches; 38 local $/; 39 foreach my $topic (@$topics) { 40 my $meta = $db->fastget( $topic ); 41 next unless $meta; 42 print STDERR "TEST $topic\n" if MONITOR_EVAL; 43 my $match = $query->evaluate( tom => $meta, data => $meta ); 44 if ($match) { 45 $matches{$topic} = $match; 46 } 47 } 48 49 # Remove the monkey patches 50 no warnings 'redefine'; 51 *Foswiki::Query::Node::evaluate = $saved[0]; 52 *Foswiki::Query::OP_ref::evaluate = $saved[1]; 53 use warnings 'redefine'; 54 55 return \%matches; 56 } 57 58 sub _getField { 59 my ( $node, $data, $field ) = @_; 45 if ($is10) { 46 foreach my $topic (@$topics) { 47 my $meta = $db->fastget( $topic ); 48 next unless $meta; 49 print STDERR "Processing $topic\n" if MONITOR_EVAL; 50 my $match = $query->evaluate( tom => $meta, data => $meta ); 51 if ($match) { 52 $matches{$topic} = $match; 53 } 54 } 55 } else { 56 # 1.1 and later 57 while ($topics->hasNext()) { 58 my $topic = $topics->next(); 59 my $meta = $db->fastget( $topic ); 60 next unless $meta; 61 print STDERR "Processing $topic\n" if MONITOR_EVAL; 62 my $match = $query->evaluate( tom => $meta, data => $meta ); 63 if ($match) { 64 $matches{$topic} = $match; 65 } 66 } 67 } 68 69 if ($is10) { 70 # Remove the monkey patches 71 no warnings 'redefine'; 72 *Foswiki::Query::Node::evaluate = $monkeys[0]; 73 *Foswiki::Query::OP_ref::evaluate = $monkeys[1]; 74 use warnings 'redefine'; 75 76 # 1.0.x and earlier 77 return \%matches; 78 } else { 79 require Foswiki::Search::InfoCache; 80 81 my @topics = keys(%matches); 82 my $resultTopicSet = 83 new Foswiki::Search::InfoCache( $Foswiki::Plugins::SESSION, $web, 84 \@topics ); 85 return $resultTopicSet; 86 } 87 } 88 89 # See Foswiki::Query::QueryAlgorithms in Foswiki 1.1 or later for details 90 sub getField { 91 my ( $class, $node, $data, $field ) = @_; 60 92 61 93 my $result = undef; 62 94 95 # The query evaluation process can return either DBCacheContrib maps 96 # and arrays (when data in the store is matched) and also standard 97 # perl arrays and hashes (when data is filtered, for example). To simplify 98 # the following code, we map them all to perl objects, using the fact that 99 # DBCacheContrib objects are designed to be tied to. 63 100 if ( UNIVERSAL::isa( 64 101 $data, 'Foswiki::Contrib::DBCacheContrib::Map' )) { … … 88 125 for( my $i = 0; $i < scalar(@$data); $i++) { 89 126 my $f = $data->[$i]; 90 my $val = _getField($node, $f, $field );127 my $val = getField( undef, $node, $f, $field ); 91 128 push( @res, $val ) if defined($val); 92 129 } … … 160 197 } 161 198 199 # See Foswiki::Query::QueryAlgorithms in Foswiki 1.1 or later for details 200 sub getRefTopic { 201 my ($class, $relativeTo, $w, $t) = @_; 202 return Foswiki::Plugins::QueryAcceleratorPlugin::getDB( 203 $w)->fastget( $t ); 204 } 205 206 ########################################################################### 207 # The following monkey-patching functions are only required for Foswiki 1.0 208 # Later versions do not need them as the core functions have been generalised 209 # to the versions given here 210 ########################################################################### 211 162 212 my $ind = 0; 163 213 164 # Override of Foswiki::Query::Node 214 # This should be identical to Foswiki::Query::Node::evaluate in 215 # Foswiki 1.1. It is provided here for use in monkey-patching Foswiki 1.0. 165 216 sub _nodeEvaluate { 166 217 my $node = shift; … … 175 226 && defined $domain{data} ) 176 227 { 177 # a name; look it up in clientData 178 $result = _getField( $node, $domain{data}, $node->{params}[0] ); 228 # a name; look it up in $domain{data} 229 $result = $Foswiki::cfg{RCS}{QueryAlgorithm}->getField( 230 $node, $domain{data}, $node->{params}[0] ); 179 231 } 180 232 else { … … 194 246 } 195 247 196 # Override of Foswiki::Query::OP_ref 248 # This should be identical to Foswiki::Query::OP_ref::evaluate in 249 # Foswiki 1.1. It is provided here for use in monkey-patching Foswiki 1.0. 197 250 sub _op_refEvaluate { 198 251 my $this = shift; … … 218 271 my $result = undef; 219 272 try { 220 my $submeta = Foswiki::Plugins::QueryAcceleratorPlugin::getDB(221 $ w)->fastget($t );273 my $submeta = $Foswiki::cfg{RCS}{QueryAlgorithm}->getRefTopic( 274 $domain{tom}, $w, $t ); 222 275 my $b = $pnode->{params}[1]; 223 276 my $res = $b->evaluate( tom => $submeta, data => $submeta );
Note: See TracChangeset
for help on using the changeset viewer.
