Changeset 9149


Ignore:
Timestamp:
09/16/10 07:29:07 (21 months ago)
Author:
CrawfordCurrie
Message:

Item8841: comment cleanup and correction. No code changes.

Location:
branches/Release01x01/core/lib/Foswiki
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/Release01x01/core/lib/Foswiki/Query/HoistREs.pm

    r7644 r9149  
    99representation to pre-filter topic lists for more efficient query matching. 
    1010 
    11 See =Store/RcsFile.pm= for an example of usage. 
     11See =Store/QueryAlgorithms/BruteForce.pm= for an example of usage. 
    1212 
    1313=cut 
  • branches/Release01x01/core/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm

    r8604 r9149  
    1515that it's around 6 topics, though this may vary depending on disk 
    1616speed and memory size. It also depends on the complexity of the query. 
     17 
     18TODO: There is an additional opprotunity for optimisation; if we assume 
     19the grep is solid, we can cut those parts of the query out for the full 
     20evaluation path. Not done yet, because CDot strongly suspects it won't make 
     21much difference. 
    1722 
    1823=cut 
     
    2934use Foswiki::Search::ResultSet (); 
    3035use Foswiki::MetaCache         (); 
     36use Foswiki::Query::Node       (); 
     37use Foswiki::Query::HoistREs   (); 
    3138 
    3239# See Foswiki::Query::QueryAlgorithms.pm for details 
     
    3441    my ( $query, $inputTopicSet, $session, $options ) = @_; 
    3542 
    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 
    4344    my $context = Foswiki::Meta->new( $session, $session->{webName} ); 
    4445    $query->simplify( tom => $context, data => $context ); 
     
    5960 
    6061        my $webObject = Foswiki::Meta->new( $session, $web ); 
    61         my $thisWebNoSearchAll = Foswiki::isTrue( $webObject->getPreference('NOSEARCHALL') ); 
     62        my $thisWebNoSearchAll = Foswiki::isTrue( 
     63            $webObject->getPreference('NOSEARCHALL') ); 
    6264 
    6365        # make sure we can report this web on an 'all' search 
     
    8385} 
    8486 
    85 #ok, for initial validation, naively call the code with a web. 
     87# Query over a single web 
    8688sub _webQuery { 
    8789    my ( $query, $web, $inputTopicSet, $session, $options ) = @_; 
     
    9092      new Foswiki::Search::InfoCache( $Foswiki::Plugins::SESSION, $web ); 
    9193 
    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' 
    9699    $query->simplify(); 
    97100    if ( $query->evaluatesToConstant() ) { 
    98101 
    99         #SMELL: use any old topic 
    100         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' ); 
    102105        my $meta = $cache->{tom}; 
    103106        $queryIsAConstantFastpath = 
    104107          $query->evaluate( tom => $meta, data => $meta ); 
    105  
    106108    } 
    107109 
     
    115117    else { 
    116118 
    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 
    118121        $queryIsAConstantFastpath = 0; 
    119122    } 
    120123 
    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 
    122127    my $hoistedREs = Foswiki::Query::HoistREs::collatedHoist($query); 
     128 
     129    # Reduce the input topic set by matching simple topic names hoisted 
     130    # from the query. 
    123131 
    124132    if ( 
     
    127135        and ( 
    128136            scalar( @{ $hoistedREs->{name} } ) == 1 
    129         ) #only do this if the 'name' query is simple (ie, has only one element) 
     137        ) 
    130138      ) 
    131139    { 
     140        # only do this if the 'name' query is simple 
     141        # (ie, has only one element) 
    132142        my @filter = @{ $hoistedREs->{name_source} }; 
    133143 
     
    136146    } 
    137147 
     148    # Reduce the input topic set by matching the hoisted REs against 
     149    # the topics in it. 
     150 
    138151    my $topicSet = $inputTopicSet; 
    139152    if ( !defined($topicSet) ) { 
    140153 
    141         #then we start with the whole web? 
    142         #TODO: i'm sure that is a flawed assumption 
     154        # then we start with the whole web? 
     155        # TODO: i'm sure that is a flawed assumption 
    143156        my $webObject = Foswiki::Meta->new( $session, $web ); 
    144157        $topicSet = 
     
    147160    } 
    148161 
    149     #TODO: howto ask iterator for list length? 
    150     #TODO: once the inputTopicSet isa ResultSet we might have an idea 
    151     #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.. 
    152165    #    if (() and ( scalar(@$topics) > 6 )) { 
    153166    if ( defined( $hoistedREs->{text} ) ) { 
     
    169182    else { 
    170183 
    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 
    172187 
    173188        #print STDERR "WARNING: couldn't hoistREs on ".$query->toString(); 
     
    183198            if ( defined( $options->{date} ) ) { 
    184199 
    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 
    186202                $Foswiki::Plugins::SESSION->search->metacache->get( $Iweb, 
    187203                    $topic ); 
    188204            } 
    189205 
    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.. 
    191208            $resultTopicSet->addTopics( $Iweb, $topic ); 
    192209        } 
     
    201218            $meta = $meta->load() unless ( $meta->latestIsLoaded() ); 
    202219            print STDERR "Processing $topic\n" 
    203               if Foswiki::Query::Node::MONITOR_EVAL(); 
     220              if Foswiki::Query::Node::MONITOR_EVAL; 
    204221            my $match = $query->evaluate( tom => $meta, data => $meta ); 
    205222            if ($match) { 
     
    3543711; 
    355372__END__ 
    356 Author: Crawford Currie http://c-dot.co.uk 
     373Authors: Crawford Currie http://c-dot.co.uk, Sven Dowideit http://fosiki.com 
    357374 
    358375Foswiki - The Free and Open Source Wiki, http://foswiki.org/ 
Note: See TracChangeset for help on using the changeset viewer.