Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved all Document::Set packages to their own files
- Loading branch information
Showing
18 changed files
with
1,552 additions
and
1,551 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package MetaCPAN::Document::Author::Set; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Moose; | ||
extends 'ElasticSearchX::Model::Document::Set'; | ||
|
||
use Ref::Util qw( is_arrayref ); | ||
|
||
use MetaCPAN::Util qw( single_valued_arrayref_to_scalar ); | ||
|
||
sub by_ids { | ||
my ( $self, $ids ) = @_; | ||
|
||
map {uc} @{$ids}; | ||
|
||
my $body = { | ||
query => { | ||
constant_score => { | ||
filter => { ids => { values => $ids } } | ||
} | ||
}, | ||
size => scalar @{$ids}, | ||
}; | ||
|
||
my $authors = $self->es->search( | ||
index => $self->index->name, | ||
type => 'author', | ||
body => $body, | ||
); | ||
return {} unless $authors->{hits}{total}; | ||
|
||
my @authors = map { | ||
single_valued_arrayref_to_scalar( $_->{_source} ); | ||
$_->{_source} | ||
} @{ $authors->{hits}{hits} }; | ||
|
||
return { authors => \@authors }; | ||
} | ||
|
||
sub by_user { | ||
my ( $self, $users ) = @_; | ||
$users = [$users] unless is_arrayref($users); | ||
|
||
my $authors = $self->es->search( | ||
index => $self->index->name, | ||
type => 'author', | ||
body => { | ||
query => { terms => { user => $users } }, | ||
size => 100, | ||
} | ||
); | ||
return {} unless $authors->{hits}{total}; | ||
|
||
my @authors = map { | ||
single_valued_arrayref_to_scalar( $_->{_source} ); | ||
$_->{_source} | ||
} @{ $authors->{hits}{hits} }; | ||
|
||
return { authors => \@authors }; | ||
} | ||
|
||
sub search { | ||
my ( $self, $query, $from ) = @_; | ||
|
||
my $body = { | ||
query => { | ||
bool => { | ||
should => [ | ||
{ | ||
match => { | ||
'name.analyzed' => | ||
{ query => $query, operator => 'and' } | ||
} | ||
}, | ||
{ | ||
match => { | ||
'asciiname.analyzed' => | ||
{ query => $query, operator => 'and' } | ||
} | ||
}, | ||
{ match => { 'pauseid' => uc($query) } }, | ||
{ match => { 'profile.id' => lc($query) } }, | ||
] | ||
} | ||
}, | ||
size => 10, | ||
from => $from || 0, | ||
}; | ||
|
||
my $ret = $self->es->search( | ||
index => $self->index->name, | ||
type => 'author', | ||
body => $body, | ||
); | ||
return {} unless $ret->{hits}{total}; | ||
|
||
my @authors = map { | ||
single_valued_arrayref_to_scalar( $_->{_source} ); | ||
+{ %{ $_->{_source} }, id => $_->{_id} } | ||
} @{ $ret->{hits}{hits} }; | ||
|
||
return +{ | ||
authors => \@authors, | ||
took => $ret->{took}, | ||
total => $ret->{hits}{total}, | ||
}; | ||
} | ||
|
||
__PACKAGE__->meta->make_immutable; | ||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package MetaCPAN::Document::Contributor::Set; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Moose; | ||
|
||
extends 'ElasticSearchX::Model::Document::Set'; | ||
|
||
sub find_release_contributors { | ||
my ( $self, $author, $name ) = @_; | ||
|
||
my $query = +{ | ||
bool => { | ||
must => [ | ||
{ term => { release_author => $author } }, | ||
{ term => { release_name => $name } }, | ||
] | ||
} | ||
}; | ||
|
||
my $res = $self->es->search( | ||
index => 'contributor', | ||
type => 'contributor', | ||
body => { | ||
query => $query, | ||
size => 999, | ||
} | ||
); | ||
$res->{hits}{total} or return {}; | ||
|
||
return +{ | ||
contributors => [ map { $_->{_source} } @{ $res->{hits}{hits} } ] | ||
}; | ||
} | ||
|
||
sub find_author_contributions { | ||
my ( $self, $pauseid ) = @_; | ||
|
||
my $query = +{ term => { pauseid => $pauseid } }; | ||
|
||
my $res = $self->es->search( | ||
index => 'contributor', | ||
type => 'contributor', | ||
body => { | ||
query => $query, | ||
size => 999, | ||
} | ||
); | ||
$res->{hits}{total} or return {}; | ||
|
||
return +{ | ||
contributors => [ map { $_->{_source} } @{ $res->{hits}{hits} } ] | ||
}; | ||
} | ||
|
||
__PACKAGE__->meta->make_immutable; | ||
1; |
Oops, something went wrong.