From d1419f874824dd5a0a4d4499d13a0941ee434044 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Fri, 15 May 2015 12:12:10 +0800 Subject: Bug 908387: product/component searching should sort hits on product/component name before hits on descriptions --- extensions/ProdCompSearch/lib/WebService.pm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'extensions') diff --git a/extensions/ProdCompSearch/lib/WebService.pm b/extensions/ProdCompSearch/lib/WebService.pm index 3bf0e1377..a28b5d059 100644 --- a/extensions/ProdCompSearch/lib/WebService.pm +++ b/extensions/ProdCompSearch/lib/WebService.pm @@ -92,12 +92,14 @@ sub prod_comp_search { push @terms, _build_terms($component, 0, 1); push @order, "products.name != " . $dbh->quote($product) if $product ne ''; push @order, "components.name != " . $dbh->quote($component) if $component ne ''; + push @order, _build_like_order($product . ' ' . $component); push @order, "products.name"; push @order, "components.name"; } else { push @terms, _build_terms($search, 1, 1); push @order, "products.name != " . $dbh->quote($search); push @order, "components.name != " . $dbh->quote($search); + push @order, _build_like_order($search); push @order, "products.name"; push @order, "components.name"; } @@ -147,4 +149,17 @@ sub _build_terms { return @terms; } +sub _build_like_order { + my ($query) = @_; + my $dbh = Bugzilla->dbh; + + my @terms; + foreach my $word (split(/[\s,]+/, $query)) { + push @terms, "CONCAT(products.name, components.name) LIKE " . $dbh->quote('%' . $word . '%') + if $word ne ''; + } + + return 'NOT(' . join(' AND ', @terms) . ')'; +} + 1; -- cgit v1.2.3-24-g4f1b