Skip to content

Commit

Permalink
move MetaCPAN::Model::Search to MetaCPAN::Query::Search
Browse files Browse the repository at this point in the history
The module more resembles a query module.
  • Loading branch information
haarg committed Oct 21, 2024
1 parent 2c61741 commit 870c44b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 23 deletions.
4 changes: 2 additions & 2 deletions lib/MetaCPAN/API/Plugin/Model.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use Mojo::Base 'Mojolicious::Plugin';
use Carp ();

# Models from the catalyst app
use MetaCPAN::Model::Search ();
use MetaCPAN::Query::Search ();

# New models
use MetaCPAN::API::Model::Cover ();
Expand All @@ -21,7 +21,7 @@ has download => sub {

has search => sub {
my $self = shift;
return MetaCPAN::Model::Search->new(
return MetaCPAN::Query::Search->new(
es => $self->app->es,
index => 'cpan',
);
Expand Down
17 changes: 3 additions & 14 deletions lib/MetaCPAN/Model/Search.pm → lib/MetaCPAN/Query/Search.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package MetaCPAN::Model::Search;
package MetaCPAN::Query::Search;

use MetaCPAN::Moose;

Expand All @@ -10,18 +10,7 @@ use MetaCPAN::Types::TypeTiny qw( Object Str );
use MetaCPAN::Util qw( single_valued_arrayref_to_scalar true false );
use MooseX::StrictConstructor;

has es => (
is => 'ro',
isa => Object,
handles => { _run_query => 'search', },
required => 1,
);

has index => (
is => 'ro',
isa => Str,
required => 1,
);
with 'MetaCPAN::Query::Role::Common';

const my $RESULTS_PER_RUN => 200;
const my @ROGUE_DISTRIBUTIONS => qw(
Expand Down Expand Up @@ -368,7 +357,7 @@ sub build_query {

sub run_query {
my ( $self, $type, $es_query ) = @_;
return $self->_run_query(
return $self->es->search(
index => $self->index,
type => $type,
body => $es_query,
Expand Down
6 changes: 3 additions & 3 deletions lib/MetaCPAN/Server/Model/Search.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ use strict;
use warnings;

use Moose;
use MetaCPAN::Model::Search ();
use MetaCPAN::Query::Search ();

extends 'MetaCPAN::Server::Model::CPAN';

has search => (
is => 'ro',
isa => 'MetaCPAN::Model::Search',
isa => 'MetaCPAN::Query::Search',
lazy => 1,
handles => [qw( search_for_first_result search_web )],
default => sub {
my $self = shift;
return MetaCPAN::Model::Search->new(
return MetaCPAN::Query::Search->new(
es => $self->es,
index => $self->index,
);
Expand Down
4 changes: 2 additions & 2 deletions t/model/search.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ use strict;
use warnings;
use lib 't/lib';

use MetaCPAN::Model::Search ();
use MetaCPAN::Query::Search ();
use MetaCPAN::TestServer ();
use MetaCPAN::Util qw(true false);
use Test::Deep qw( cmp_deeply ignore );
use Test::More;

# Just use this to get an es object.
my $server = MetaCPAN::TestServer->new;
my $search = MetaCPAN::Model::Search->new(
my $search = MetaCPAN::Query::Search->new(
es => $server->es_client,
index => 'cpan',
);
Expand Down
4 changes: 2 additions & 2 deletions xt/search_web.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use lib 't/lib';
# USE `bin/prove_live` to run this
# READ the README.txt in this dir

use MetaCPAN::Model::Search ();
use MetaCPAN::Query::Search ();
use MetaCPAN::TestServer ();
use Test::More;

# Just use this to get an es object.
my $server = MetaCPAN::TestServer->new;
my $search = MetaCPAN::Model::Search->new(
my $search = MetaCPAN::Query::Search->new(
es => $server->es_client,
index => 'cpan',
);
Expand Down

0 comments on commit 870c44b

Please sign in to comment.