📄 quicksearch.pm
字号:
addChart('short_desc', 'substring', $baseWord, $negate); addChart('status_whiteboard', 'substring', $baseWord, $negate); } elsif ($firstChar eq '!') { addChart('keywords', 'anywords', $baseWord, $negate); } else { # No special first char # Split by '|' to get all operands for a boolean OR. foreach my $or_operand (split(/\|/, $qsword)) { if ($or_operand =~ /^votes:([0-9]+)$/) { # votes:xx ("at least xx votes") addChart('votes', 'greaterthan', $1 - 1, $negate); } elsif ($or_operand =~ /^([^:]+):([^:]+)$/) { # generic field1,field2,field3:value1,value2 notation my @fields = split(/,/, $1); my @values = split(/,/, $2); foreach my $field (@fields) { # Skip and record any unknown fields if (!defined(MAPPINGS->{$field})) { push(@unknownFields, $field); next; } $field = MAPPINGS->{$field}; foreach (@values) { addChart($field, 'substring', $_, $negate); } } } else { # Having ruled out the special cases, we may now split # by comma, which is another legal boolean OR indicator. foreach my $word (split(/,/, $or_operand)) { # Platform if (grep({lc($word) eq $_} PLATFORMS)) { addChart('rep_platform', 'substring', $word, $negate); } # Priority elsif ($word =~ m/^[pP]([1-5](-[1-5])?)$/) { addChart('priority', 'regexp', "[$1]", $negate); } # Severity elsif (grep({lc($word) eq substr($_, 0, 3)} @{get_legal_field_values('bug_severity')})) { addChart('bug_severity', 'substring', $word, $negate); } # Votes (votes>xx) elsif ($word =~ m/^votes>([0-9]+)$/) { addChart('votes', 'greaterthan', $1, $negate); } # Votes (votes>=xx, votes=>xx) elsif ($word =~ m/^votes(>=|=>)([0-9]+)$/) { addChart('votes', 'greaterthan', $2-1, $negate); } else { # Default QuickSearch word if (!grep({lc($word) eq $_} PRODUCT_EXCEPTIONS) && length($word)>2 ) { addChart('product', 'substring', $word, $negate); } if (!grep({lc($word) eq $_} COMPONENT_EXCEPTIONS) && length($word)>2 ) { addChart('component', 'substring', $word, $negate); } if (grep({lc($word) eq $_} map($_->name, Bugzilla::Keyword->get_all))) { addChart('keywords', 'substring', $word, $negate); if (length($word)>2) { addChart('short_desc', 'substring', $word, $negate); addChart('status_whiteboard', 'substring', $word, $negate); } } else { addChart('short_desc', 'substring', $word, $negate); addChart('status_whiteboard', 'substring', $word, $negate); } if ($searchComments) { addChart('longdesc', 'substring', $word, $negate); } } # URL field (for IP addrs, host.names, # scheme://urls) if ($word =~ m/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ || $word =~ /^[A-Za-z]+(\.[A-Za-z]+)+/ || $word =~ /:[\\\/][\\\/]/ || $word =~ /localhost/ || $word =~ /mailto[:]?/ # || $word =~ /[A-Za-z]+[:][0-9]+/ #host:port ) { addChart('bug_file_loc', 'substring', $word, $negate); } } # foreach my $word (split(/,/, $qsword)) } # votes and generic field detection } # foreach (split(/\|/, $_)) } # "switch" $firstChar $chart++; $and = 0; $or = 0; } # foreach (@words) # Inform user about any unknown fields if (scalar(@unknownFields)) { ThrowUserError("quicksearch_unknown_field", { fields => \@unknownFields }); } # Make sure we have some query terms left scalar($cgi->param())>0 || ThrowUserError("buglist_parameters_required"); } # List of quicksearch-specific CGI parameters to get rid of. my @params_to_strip = ('quicksearch', 'load', 'run'); my $modified_query_string = $cgi->canonicalise_query(@params_to_strip); if ($cgi->param('load')) { # Param 'load' asks us to display the query in the advanced search form. print $cgi->redirect(-uri => "${urlbase}query.cgi?format=advanced&" . $modified_query_string); } # Otherwise, pass the modified query string to the caller. # We modified $cgi->params, so the caller can choose to look at that, too, # and disregard the return value. $cgi->delete(@params_to_strip); return $modified_query_string;}############################################################################ Helpers############################################################################ Split string on whitespace, retaining quoted strings as onesub splitString { my $string = shift; my @quoteparts; my @parts; my $i = 0; # Now split on quote sign; be tolerant about unclosed quotes @quoteparts = split(/"/, $string); foreach my $part (@quoteparts) { # After every odd quote, quote special chars $part = url_quote($part) if $i++ % 2; } # Join again $string = join('"', @quoteparts); # Now split on unescaped whitespace @parts = split(/\s+/, $string); foreach (@parts) { # Remove quotes s/"//g; } return @parts;}# Expand found prefixes to states or resolutionssub matchPrefixes { my $hr_states = shift; my $hr_resolutions = shift; my $ar_prefixes = shift; my $ar_check_states = shift; my $ar_check_resolutions = shift; my $foundMatch = 0; foreach my $prefix (@$ar_prefixes) { foreach (@$ar_check_states) { if (/^$prefix/) { $$hr_states{$_} = 1; $foundMatch = 1; } } foreach (@$ar_check_resolutions) { if (/^$prefix/) { $$hr_resolutions{$_} = 1; $foundMatch = 1; } } } return $foundMatch;}# Negate comparison typesub negateComparisonType { my $comparisonType = shift; if ($comparisonType eq 'substring') { return 'notsubstring'; } elsif ($comparisonType eq 'anywords') { return 'nowords'; } elsif ($comparisonType eq 'regexp') { return 'notregexp'; } else { # Don't know how to negate that ThrowCodeError('unknown_comparison_type'); }}# Add a boolean chartsub addChart { my ($field, $comparisonType, $value, $negate) = @_; $negate && ($comparisonType = negateComparisonType($comparisonType)); makeChart("$chart-$and-$or", $field, $comparisonType, $value); if ($negate) { $and++; $or = 0; } else { $or++; }}# Create the CGI parameters for a boolean chartsub makeChart { my ($expr, $field, $type, $value) = @_; my $cgi = Bugzilla->cgi; $cgi->param("field$expr", $field); $cgi->param("type$expr", $type); $cgi->param("value$expr", url_decode($value));}1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -