Changeset 456
- Timestamp:
- 07/26/04 16:49:50 (4 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 1 modified
-
lib/OpenGuides/SuperSearch.pm (modified) (8 diffs)
-
t/35_supersearch_two_searches.t (added)
-
t/36_supersearch_order.t (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/OpenGuides/SuperSearch.pm
r417 r456 141 141 my $numres = scalar @results; 142 142 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 143 149 # For 0 or many we display results, for 1 we redirect to that page. 144 150 if ( $numres == 1 && !$self->{return_tt_vars}) { … … 169 175 @results = sort { $a->{distance} <=> $b->{distance} } @results; 170 176 } else { 171 @results = sort { $ a->{score} <=> $b->{score} } @results;177 @results = sort { $b->{score} <=> $a->{score} } @results; 172 178 } 173 179 … … 225 231 my $key = $wiki->formatter->node_name_to_node_param( $node ); 226 232 my $text = $node . " " . $wiki->retrieve_node( $node ); 227 $self->{wikitext}{$key} ||= $self->_mungepage( $text );233 $self->{wikitext}{$key}{text} ||= $self->_mungepage( $text ); 228 234 } 229 235 } … … 242 248 my $key = $wiki->formatter->node_name_to_node_param( $node ); 243 249 my $text = $node. " " . $wiki->retrieve_node( $node ); 244 $self->{wikitext}{$key} ||= $self->_mungepage( $text );250 $self->{wikitext}{$key}{text} ||= $self->_mungepage( $text ); 245 251 # 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; 247 254 } 248 255 … … 256 263 my $key = $wiki->formatter->node_name_to_node_param( $node ); 257 264 my $text = $node. " " . $wiki->retrieve_node( $node ); 258 $self->{wikitext}{$key} ||= $self->_mungepage( $text );265 $self->{wikitext}{$key}{text} ||= $self->_mungepage( $text ); 259 266 # 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; 261 269 } 262 270 } # $op eq 'word' … … 579 587 } 580 588 589 =back 590 591 =head1 OUTPUT 592 593 Results will be put into some form of relevance ordering. These are 594 the rules we have tests for so far (and hence the only rules that can 595 be relied on): 596 597 =over 598 599 =item * 600 601 A match on page title will score higher than a match on page category 602 or locale. 603 604 =item * 605 606 A match on page category or locale will score higher than a match on 607 page content. 608 609 =back 610 611 =cut 612 581 613 sub intersperse { 582 614 my $self = shift; … … 612 644 while (my ($k,$v) = each %wikitext) { 613 645 my @out; 614 for ($v =~ /$wexp/g) {646 for ($v->{text} =~ /$wexp/g) { 615 647 my $match .= "...$_..."; 616 648 $match =~ s/<[^>]+>//gs; … … 622 654 623 655 # 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 626 664 $results{$k} = { 627 665 score => $score,
