Changeset 456

Show
Ignore:
Timestamp:
07/26/04 16:49:50 (4 years ago)
Author:
kake
Message:

Search improvements, bugfix, better rankings.

Location:
trunk
Files:
2 added
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/OpenGuides/SuperSearch.pm

    r417 r456  
    141141        my $numres = scalar @results; 
    142142 
     143        # Clear out wikitext; we're done with this search.  (Avoids 
     144        # subsequent searches with this object erroneously matching things 
     145        # that matched this time.)  Do it here (ie at the last minute) to 
     146        # avoid screwing up "AND" searches. 
     147        delete $self->{wikitext}; 
     148 
    143149        # For 0 or many we display results, for 1 we redirect to that page. 
    144150        if ( $numres == 1 && !$self->{return_tt_vars}) { 
     
    169175                @results = sort { $a->{distance} <=> $b->{distance} } @results; 
    170176            } else { 
    171                 @results = sort { $a->{score} <=> $b->{score} } @results; 
     177                @results = sort { $b->{score} <=> $a->{score} } @results; 
    172178            } 
    173179 
     
    225231                my $key = $wiki->formatter->node_name_to_node_param( $node ); 
    226232                my $text = $node . " " . $wiki->retrieve_node( $node ); 
    227                 $self->{wikitext}{$key} ||= $self->_mungepage( $text ); 
     233                $self->{wikitext}{$key}{text} ||= $self->_mungepage( $text ); 
    228234            } 
    229235        } 
     
    242248                my $key = $wiki->formatter->node_name_to_node_param( $node ); 
    243249                my $text = $node. " " . $wiki->retrieve_node( $node ); 
    244                 $self->{wikitext}{$key} ||= $self->_mungepage( $text ); 
     250                $self->{wikitext}{$key}{text} ||= $self->_mungepage( $text ); 
    245251                # Append this category so the regex finds it later. 
    246                 $self->{wikitext}{$key} .= " [$matchstr]"; 
     252                $self->{wikitext}{$key}{text} .= " [$matchstr]"; 
     253                $self->{wikitext}{$key}{category_match} = 1; 
    247254        } 
    248255 
     
    256263                my $key = $wiki->formatter->node_name_to_node_param( $node ); 
    257264                my $text = $node. " " . $wiki->retrieve_node( $node ); 
    258                 $self->{wikitext}{$key} ||= $self->_mungepage( $text ); 
     265                $self->{wikitext}{$key}{text} ||= $self->_mungepage( $text ); 
    259266                # Append this locale so the regex finds it later. 
    260                 $self->{wikitext}{$key} .= " [$matchstr]"; 
     267                $self->{wikitext}{$key}{text} .= " [$matchstr]"; 
     268                $self->{wikitext}{$key}{locale_match} = 1; 
    261269        } 
    262270    } # $op eq 'word' 
     
    579587} 
    580588 
     589=back 
     590 
     591=head1 OUTPUT 
     592 
     593Results will be put into some form of relevance ordering.  These are 
     594the rules we have tests for so far (and hence the only rules that can 
     595be relied on): 
     596 
     597=over 
     598 
     599=item * 
     600 
     601A match on page title will score higher than a match on page category 
     602or locale. 
     603 
     604=item * 
     605 
     606A match on page category or locale will score higher than a match on 
     607page content. 
     608 
     609=back 
     610 
     611=cut 
     612 
    581613sub intersperse { 
    582614    my $self = shift; 
     
    612644    while (my ($k,$v) = each %wikitext) { 
    613645        my @out; 
    614         for ($v =~ /$wexp/g) { 
     646        for ($v->{text} =~ /$wexp/g) { 
    615647            my $match .= "...$_..."; 
    616648            $match =~ s/<[^>]+>//gs; 
     
    622654 
    623655        # Compute score and create summary. 
    624         my $score = scalar @out; 
    625         $score +=10 if $temp =~ /$wexp/; 
     656        my $score = scalar @out; # 1 point for each match in body/title/cats 
     657        $score += 10 if $temp =~ /$wexp/; # 10 points if title matches 
     658        # 5 points for cat/locale match.  Check $score too since this might 
     659        # be a branch of an AND search and the cat/locale match may have 
     660        # been for the other branch, 
     661        $score += 5  if $v->{category_match} and $score; 
     662        $score += 5  if $v->{locale_match} and $score; 
     663 
    626664        $results{$k} = { 
    627665                         score   => $score,