From 1c03d215b0cb81a8deb67f58c345abd2b6f5f739 Mon Sep 17 00:00:00 2001 From: "myk%mozilla.org" <> Date: Tue, 6 Apr 2004 07:11:17 +0000 Subject: Fix for bug 237176: allows power users to display relevance values as a column in the search results for a fulltext search r=justdave a=justdave --- Bugzilla/Search.pm | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'Bugzilla/Search.pm') diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm index 3db341c7f..6d3c7c916 100644 --- a/Bugzilla/Search.pm +++ b/Bugzilla/Search.pm @@ -429,12 +429,9 @@ sub init { # The term to use in the WHERE clause. $term = $term1; - # In order to sort by relevance, we SELECT the relevance value - # and give it an alias so we can add it to the SORT BY clause - # when we build that clause in buglist.cgi. We also flag the - # query in Bugzilla with the "sorted_by_relevance" flag - # so buglist.cgi knows to sort by relevance instead of anything - # else the user selected. + # In order to sort by relevance (in case the user requests it), + # we SELECT the relevance value and give it an alias so we can + # add it to the SORT BY clause when we build it in buglist.cgi. # # Note: MySQL calculates relevance for each comment separately, # so we need to do some additional calculations to get an overall @@ -446,8 +443,19 @@ sub init { # Note: We should be calculating the average relevance of all # comments for a bug, not just matching comments, but that's hard # (see http://bugzilla.mozilla.org/show_bug.cgi?id=145588#c35). - push(@fields, "(SUM($term1)/COUNT($term1) + $term2) AS relevance"); - $self->{'sorted_by_relevance'} = 1; + my $select_term = + "(SUM($term1)/COUNT($term1) + $term2) AS relevance"; + + # Users can specify to display the relevance field, in which case + # it'll show up in the list of fields being selected, and we need + # to replace that occurrence with our select term. Otherwise + # we can just add the term to the list of fields being selected. + if (grep($_ eq "relevance", @fields)) { + @fields = map($_ eq "relevance" ? $select_term : $_ , @fields); + } + else { + push(@fields, $select_term); + } }, "^long_?desc," => sub { my $table = "longdescs_$chartid"; -- cgit v1.2.3-24-g4f1b