Skip to content

Commit cb4e49e

Browse files
committed
rename user $query -> $search_term
1 parent 192d8f2 commit cb4e49e

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

lib/MetaCPAN/Model/Search.pm

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ sub _not_rogue {
3636
}
3737

3838
sub search_simple {
39-
my ( $self, $query ) = @_;
40-
my $es_query = $self->build_query($query);
39+
my ( $self, $search_term ) = @_;
40+
my $es_query = $self->build_query($search_term);
4141
my $results = $self->run_query( file => $es_query );
4242
return $results;
4343
}
4444

4545
sub search_for_first_result {
46-
my ( $self, $query ) = @_;
47-
my $es_query = $self->build_query($query);
46+
my ( $self, $search_term ) = @_;
47+
my $es_query = $self->build_query($search_term);
4848
my $results = $self->run_query( file => $es_query );
4949
return unless $results->{hits}{total};
5050
my $data = $results->{hits}{hits}[0];
@@ -53,31 +53,33 @@ sub search_for_first_result {
5353
}
5454

5555
sub search_web {
56-
my ( $self, $query, $from, $page_size, $collapsed ) = @_;
56+
my ( $self, $search_term, $from, $page_size, $collapsed ) = @_;
5757
$page_size //= 20;
5858
$from //= 0;
5959

6060
# munge the query
6161
# these would be nicer if we had variable-length lookbehinds...
62-
$query =~ s{(^|\s)author:([a-zA-Z]+)(?=\s|$)}{$1author:\U$2\E}g;
63-
$query =~ s/(^|\s)dist(ribution)?:([\w-]+)(?=\s|$)/$1distribution:$3/g;
64-
$query =~ s/(^|\s)module:(\w[\w:]*)(?=\s|$)/$1module.name.analyzed:$2/g;
62+
$search_term =~ s{(^|\s)author:([a-zA-Z]+)(?=\s|$)}{$1author:\U$2\E}g;
63+
$search_term
64+
=~ s/(^|\s)dist(ribution)?:([\w-]+)(?=\s|$)/$1distribution:$3/g;
65+
$search_term
66+
=~ s/(^|\s)module:(\w[\w:]*)(?=\s|$)/$1module.name.analyzed:$2/g;
6567

6668
my $results
67-
= $collapsed // $query !~ /(distribution|module\.name\S*):/
68-
? $self->_search_collapsed( $query, $from, $page_size )
69-
: $self->_search_expanded( $query, $from, $page_size );
69+
= $collapsed // $search_term !~ /(distribution|module\.name\S*):/
70+
? $self->_search_collapsed( $search_term, $from, $page_size )
71+
: $self->_search_expanded( $search_term, $from, $page_size );
7072

7173
return $results;
7274
}
7375

7476
sub _search_expanded {
75-
my ( $self, $query, $from, $page_size ) = @_;
77+
my ( $self, $search_term, $from, $page_size ) = @_;
7678

7779
# When used for a distribution or module search, the limit is included in
7880
# thl query and ES does the right thing.
7981
my $es_query = $self->build_query(
80-
$query,
82+
$search_term,
8183
{
8284
size => $page_size,
8385
from => $from
@@ -112,7 +114,7 @@ sub _search_expanded {
112114
}
113115

114116
sub _search_collapsed {
115-
my ( $self, $query, $from, $page_size ) = @_;
117+
my ( $self, $search_term, $from, $page_size ) = @_;
116118

117119
my $took = 0;
118120
my $total;
@@ -138,7 +140,7 @@ sub _search_collapsed {
138140
count => { terms => { size => 999, field => 'distribution' } }
139141
}
140142
if $run == 1;
141-
my $es_query = $self->build_query( $query, $es_query_opts );
143+
my $es_query = $self->build_query( $search_term, $es_query_opts );
142144

143145
$data = $self->run_query( file => $es_query );
144146
$took += $data->{took} || 0;
@@ -170,7 +172,7 @@ sub _search_collapsed {
170172
# results page, fetch the details about those distributions
171173
my $favorites = $self->search_favorites(@distributions);
172174
my $es_query = $self->build_query(
173-
$query,
175+
$search_term,
174176
{
175177
# we will probably never hit that limit, since we are searching in $page_size=20 distributions max
176178
size => 5000,
@@ -228,9 +230,9 @@ sub _collapse_results {
228230
}
229231

230232
sub build_query {
231-
my ( $self, $query, $params ) = @_;
233+
my ( $self, $search_term, $params ) = @_;
232234
$params //= {};
233-
( my $clean = $query ) =~ s/::/ /g;
235+
( my $clean = $search_term ) =~ s/::/ /g;
234236

235237
my $negative
236238
= { term => { 'mime' => { value => 'text/x-script.perl' } } };
@@ -243,15 +245,15 @@ sub build_query {
243245
{
244246
term => {
245247
'documentation' => {
246-
value => $query,
248+
value => $search_term,
247249
boost => 20,
248250
}
249251
}
250252
},
251253
{
252254
term => {
253255
'module.name' => {
254-
value => $query,
256+
value => $search_term,
255257
boost => 20,
256258
}
257259
}
@@ -376,11 +378,11 @@ sub build_query {
376378
}
377379

378380
sub run_query {
379-
my ( $self, $type, $query ) = @_;
381+
my ( $self, $type, $es_query ) = @_;
380382
return $self->_run_query(
381383
index => $self->index,
382384
type => $type,
383-
body => $query,
385+
body => $es_query,
384386
);
385387
}
386388

0 commit comments

Comments
 (0)