Changeset 9149
- Timestamp:
- 09/16/10 07:29:07 (21 months ago)
- Location:
- branches/Release01x01/core/lib/Foswiki
- Files:
-
- 2 edited
-
Query/HoistREs.pm (modified) (1 diff)
-
Store/QueryAlgorithms/BruteForce.pm (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/Release01x01/core/lib/Foswiki/Query/HoistREs.pm
r7644 r9149 9 9 representation to pre-filter topic lists for more efficient query matching. 10 10 11 See =Store/ RcsFile.pm= for an example of usage.11 See =Store/QueryAlgorithms/BruteForce.pm= for an example of usage. 12 12 13 13 =cut -
branches/Release01x01/core/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm
r8604 r9149 15 15 that it's around 6 topics, though this may vary depending on disk 16 16 speed and memory size. It also depends on the complexity of the query. 17 18 TODO: There is an additional opprotunity for optimisation; if we assume 19 the grep is solid, we can cut those parts of the query out for the full 20 evaluation path. Not done yet, because CDot strongly suspects it won't make 21 much difference. 17 22 18 23 =cut … … 29 34 use Foswiki::Search::ResultSet (); 30 35 use Foswiki::MetaCache (); 36 use Foswiki::Query::Node (); 37 use Foswiki::Query::HoistREs (); 31 38 32 39 # See Foswiki::Query::QueryAlgorithms.pm for details … … 34 41 my ( $query, $inputTopicSet, $session, $options ) = @_; 35 42 36 #TODO: th 1==2 and other false optimisations.. 37 #if ( !defined($query->{tokens}) or 38 # (@{ $query->{tokens} } ) == 0) { 39 # return new Foswiki::Search::InfoCache($session, ''); 40 #} 41 42 # Eliminate static expressions 43 # Fold constants 43 44 my $context = Foswiki::Meta->new( $session, $session->{webName} ); 44 45 $query->simplify( tom => $context, data => $context ); … … 59 60 60 61 my $webObject = Foswiki::Meta->new( $session, $web ); 61 my $thisWebNoSearchAll = Foswiki::isTrue( $webObject->getPreference('NOSEARCHALL') ); 62 my $thisWebNoSearchAll = Foswiki::isTrue( 63 $webObject->getPreference('NOSEARCHALL') ); 62 64 63 65 # make sure we can report this web on an 'all' search … … 83 85 } 84 86 85 # ok, for initial validation, naively call the code with a web.87 # Query over a single web 86 88 sub _webQuery { 87 89 my ( $query, $web, $inputTopicSet, $session, $options ) = @_; … … 90 92 new Foswiki::Search::InfoCache( $Foswiki::Plugins::SESSION, $web ); 91 93 92 #see if this query can be fasttracked. 93 #TODO: is this simplification call appropriate here, or should it go in Search.pm 94 #TODO: what about simplify to constant in _this_ web? 95 my $queryIsAConstantFastpath; #undefined if this is a 'real' query' 94 # see if this query can be fasttracked. 95 # TODO: is this simplification call appropriate here, or should it 96 # go in Search.pm 97 # TODO: what about simplify to constant in _this_ web? 98 my $queryIsAConstantFastpath; # undefined if this is a 'real' query' 96 99 $query->simplify(); 97 100 if ( $query->evaluatesToConstant() ) { 98 101 99 # SMELL: use any old topic100 my $cache = $Foswiki::Plugins::SESSION->search->metacache->get( $web,101 'WebPreferences' );102 # SMELL: use any old topic 103 my $cache = $Foswiki::Plugins::SESSION->search->metacache->get( 104 $web, 'WebPreferences' ); 102 105 my $meta = $cache->{tom}; 103 106 $queryIsAConstantFastpath = 104 107 $query->evaluate( tom => $meta, data => $meta ); 105 106 108 } 107 109 … … 115 117 else { 116 118 117 #from here on, FALSE means its not a constant, TRUE means is is a constant and evals to TRUE 119 # from here on, FALSE means its not a constant, TRUE 120 # means is is a constant and evals to TRUE 118 121 $queryIsAConstantFastpath = 0; 119 122 } 120 123 121 require Foswiki::Query::HoistREs; 124 # Try and hoist regular expressions out of the query that we 125 # can use to refine the topic set 126 122 127 my $hoistedREs = Foswiki::Query::HoistREs::collatedHoist($query); 128 129 # Reduce the input topic set by matching simple topic names hoisted 130 # from the query. 123 131 124 132 if ( … … 127 135 and ( 128 136 scalar( @{ $hoistedREs->{name} } ) == 1 129 ) #only do this if the 'name' query is simple (ie, has only one element)137 ) 130 138 ) 131 139 { 140 # only do this if the 'name' query is simple 141 # (ie, has only one element) 132 142 my @filter = @{ $hoistedREs->{name_source} }; 133 143 … … 136 146 } 137 147 148 # Reduce the input topic set by matching the hoisted REs against 149 # the topics in it. 150 138 151 my $topicSet = $inputTopicSet; 139 152 if ( !defined($topicSet) ) { 140 153 141 # then we start with the whole web?142 # TODO: i'm sure that is a flawed assumption154 # then we start with the whole web? 155 # TODO: i'm sure that is a flawed assumption 143 156 my $webObject = Foswiki::Meta->new( $session, $web ); 144 157 $topicSet = … … 147 160 } 148 161 149 # TODO: howto ask iterator for list length?150 # TODO: once the inputTopicSet isa ResultSet we might have an idea151 # TODO: I presume $hoisetedRE's is undefined for constant queries..162 # TODO: how to ask iterator for list length? 163 # TODO: once the inputTopicSet isa ResultSet we might have an idea 164 # TODO: I presume $hoisetedRE's is undefined for constant queries.. 152 165 # if (() and ( scalar(@$topics) > 6 )) { 153 166 if ( defined( $hoistedREs->{text} ) ) { … … 169 182 else { 170 183 171 #TODO: clearly _this_ can be re-written as a FilterIterator, and if we are able to use the sorting hints (ie DB Store) can propogate all the way to FORMAT 184 # TODO: clearly _this_ can be re-written as a FilterIterator, 185 # and if we are able to use the sorting hints (ie DB Store) 186 # can propogate all the way to FORMAT 172 187 173 188 #print STDERR "WARNING: couldn't hoistREs on ".$query->toString(); … … 183 198 if ( defined( $options->{date} ) ) { 184 199 185 #TODO: preload the meta cache if we're doing date based filtering - else the wrong filedate will be used 200 # TODO: preload the meta cache if we're doing date 201 # based filtering - else the wrong filedate will be used 186 202 $Foswiki::Plugins::SESSION->search->metacache->get( $Iweb, 187 203 $topic ); 188 204 } 189 205 190 #TODO: frustratingly, there is no way to evaluate a filterIterator without actually iterating over it.. 206 # TODO: frustratingly, there is no way to evaluate a 207 # filterIterator without actually iterating over it.. 191 208 $resultTopicSet->addTopics( $Iweb, $topic ); 192 209 } … … 201 218 $meta = $meta->load() unless ( $meta->latestIsLoaded() ); 202 219 print STDERR "Processing $topic\n" 203 if Foswiki::Query::Node::MONITOR_EVAL ();220 if Foswiki::Query::Node::MONITOR_EVAL; 204 221 my $match = $query->evaluate( tom => $meta, data => $meta ); 205 222 if ($match) { … … 354 371 1; 355 372 __END__ 356 Author : Crawford Currie http://c-dot.co.uk373 Authors: Crawford Currie http://c-dot.co.uk, Sven Dowideit http://fosiki.com 357 374 358 375 Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Note: See TracChangeset
for help on using the changeset viewer.
