1 |
commit: a77d38585dc75d783976b84656939c357d4d6308 |
2 |
Author: Kent Fredric <kentfredric <AT> gmail <DOT> com> |
3 |
AuthorDate: Sat Feb 25 22:09:03 2012 +0000 |
4 |
Commit: Kent Fredric <kentfredric <AT> gmail <DOT> com> |
5 |
CommitDate: Sat Feb 25 22:09:03 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/perl-overlay.git;a=commit;h=a77d3858 |
7 |
|
8 |
[scripts] enhanced metacpan requests: |
9 |
|
10 |
find_dist_all now supports filtering to report only the "latest" release |
11 |
of a dist. ( --latest ) |
12 |
|
13 |
Also supports sorting by status=latest first ( --sort-latest ) |
14 |
module_log.pl can now resort to the simple non-nested query which |
15 |
doesn't do server-side "authorised" based reduction via ( |
16 |
--method=simple ) |
17 |
|
18 |
|
19 |
|
20 |
--- |
21 |
scripts/lib/metacpan.pm | 115 +++++++++++++++++++++++++++-------------------- |
22 |
scripts/module_log.pl | 9 +++- |
23 |
2 files changed, 73 insertions(+), 51 deletions(-) |
24 |
|
25 |
diff --git a/scripts/lib/metacpan.pm b/scripts/lib/metacpan.pm |
26 |
index e732cae..ccc267a 100644 |
27 |
--- a/scripts/lib/metacpan.pm |
28 |
+++ b/scripts/lib/metacpan.pm |
29 |
@@ -35,7 +35,19 @@ sub mcpan { |
30 |
); |
31 |
} |
32 |
if ( defined $ENV{WWW_MECH_DEBUG} ) { |
33 |
- $mech->add_handler( "request_send", sub { warn shift->dump; return } ); |
34 |
+ require Data::Dump; |
35 |
+ $mech->add_handler( |
36 |
+ "request_send", |
37 |
+ sub { |
38 |
+ if ( $ENV{WWW_MECH_DEBUG} > 1 ) { |
39 |
+ warn shift->as_string; |
40 |
+ } |
41 |
+ else { |
42 |
+ warn shift->dump; |
43 |
+ } |
44 |
+ return; |
45 |
+ } |
46 |
+ ); |
47 |
$mech->add_handler( |
48 |
"response_done", |
49 |
sub { |
50 |
@@ -67,6 +79,15 @@ sub mcpan { |
51 |
# # You can optionally do this to modify the query before it is performed. |
52 |
# }; |
53 |
# |
54 |
+# $opts{latest} = 1 # return only latest versions of dists |
55 |
+# |
56 |
+# $opts{method} = 'simple' # non-nested query ( introduces bad results ) |
57 |
+# $opts{method} = 'nested' # works like notrim but serverside |
58 |
+# |
59 |
+# $opts{version} = 1 # return version information |
60 |
+# |
61 |
+# $opts{'sort-latest'} = 1 # sort by status == latest first. |
62 |
+# |
63 |
# Array items are each a subset of a 'file' entry which contains information |
64 |
# about the distribution that file was in. |
65 |
# |
66 |
@@ -79,7 +100,6 @@ sub mcpan { |
67 |
sub find_dist_all { |
68 |
my ( $class, $module, $opts ) = @_; |
69 |
|
70 |
- # my @unwanted_terms = ( { terms => { 'file.distribution' => [qw( libwww-perl HTTP-Message )] } } ); |
71 |
my $fields = [ |
72 |
'status', 'date', 'author', 'maturity', 'indexed', 'documentation', |
73 |
'id', '_source.module', 'authorized', 'release_id', 'version', 'name', |
74 |
@@ -87,62 +107,59 @@ sub find_dist_all { |
75 |
'sloc', 'abstract', 'slop', 'mime', 'directory', |
76 |
]; |
77 |
|
78 |
- my $simple_filter = { |
79 |
- bool => { |
80 |
- must => [ |
81 |
- { term => { 'file.module.authorized' => 1 } }, |
82 |
- { term => { 'file.module.indexed' => 1 } }, |
83 |
- { term => { 'file.module.name' => $module } }, |
84 |
- { term => { 'directory' => 0 } }, |
85 |
- ] |
86 |
- } |
87 |
- }; |
88 |
- |
89 |
my $q = { |
90 |
- sort => { 'file.date' => 'desc' }, |
91 |
+ |
92 |
+ script_fields => { 'latest' => { script => q{ doc[ 'status' ].value == 'latest' } } }, |
93 |
+ sort => [ |
94 |
+ ( |
95 |
+ $opts->{'sort-latest'} |
96 |
+ ? ( |
97 |
+ { |
98 |
+ '_script' => { |
99 |
+ script => q{ doc['status'].value == 'latest' ? 1 : 0 }, |
100 |
+ type => 'number', |
101 |
+ order => 'desc', |
102 |
+ } |
103 |
+ } |
104 |
+ ) |
105 |
+ : () |
106 |
+ ), |
107 |
+ { 'file.date' => 'desc' }, |
108 |
+ ], |
109 |
size => 9999, |
110 |
}; |
111 |
|
112 |
- if ( not defined $opts->{method} or $opts->{method} eq 'nested' ) { |
113 |
+ if ( not defined $opts->{method} |
114 |
+ or $opts->{method} eq 'nested' ) |
115 |
+ { |
116 |
+ my $module_rules = [ |
117 |
+ { term => { 'module.authorized' => 1 } }, |
118 |
+ { term => { 'module.indexed' => 1 } }, |
119 |
+ { term => { 'module.name' => $module } }, |
120 |
+ ]; |
121 |
+ my $nest = { |
122 |
+ path => 'module', |
123 |
+ query => { constant_score => { filter => { bool => { must => $module_rules, } } } }, |
124 |
+ size => 5, |
125 |
+ }; |
126 |
$q->{query} = { |
127 |
constant_score => { |
128 |
- query => { |
129 |
- nested => { |
130 |
- path => 'module', |
131 |
- query => { |
132 |
- constant_score => { |
133 |
- filter => { |
134 |
- bool => { |
135 |
- must => [ |
136 |
- { term => { 'module.authorized' => 1 } }, |
137 |
- { term => { 'module.indexed' => 1 } }, |
138 |
- { term => { 'module.name' => $module } }, |
139 |
- ] |
140 |
- } |
141 |
- } |
142 |
- } |
143 |
- }, |
144 |
- size => 5, |
145 |
- } |
146 |
- } |
147 |
+ query => |
148 |
+ { bool => { must => [ ( $opts->{latest} ? { term => { 'status' => 'latest' } } : () ), { nested => $nest }, ], } } |
149 |
} |
150 |
}; |
151 |
} |
152 |
else { |
153 |
- $q->{query} = { |
154 |
- constant_score => { |
155 |
- filter => { |
156 |
- bool => { |
157 |
- must => [ |
158 |
- { term => { 'file.module.authorized' => 1 } }, |
159 |
- { term => { 'file.module.indexed' => 1 } }, |
160 |
- { term => { 'file.module.name' => $module } }, |
161 |
- { term => { 'directory' => 0 } }, |
162 |
- ] |
163 |
- } |
164 |
- } |
165 |
- } |
166 |
- }; |
167 |
+ |
168 |
+ my $document_rules = [ |
169 |
+ { term => { 'file.module.authorized' => 1 } }, |
170 |
+ { term => { 'file.module.indexed' => 1 } }, |
171 |
+ { term => { 'file.module.name' => $module } }, |
172 |
+ { term => { 'directory' => 0 } }, |
173 |
+ ( $opts->{latest} ? { term => { 'status' => 'latest' } } : () ), |
174 |
+ ]; |
175 |
+ |
176 |
+ $q->{query} = { constant_score => { filter => { bool => { must => $document_rules } } } }; |
177 |
} |
178 |
|
179 |
if ( $opts->{version} ) { |
180 |
@@ -215,7 +232,7 @@ sub _skip_result { |
181 |
sub find_release { |
182 |
my ( $class, $author, $distrelease, $opts ) = @_; |
183 |
my @terms = ( { term => { author => $author } }, { term => { name => $distrelease } }, ); |
184 |
- my $filter = { filter => { and => [ @terms ] } }; |
185 |
+ my $filter = { filter => { and => [@terms] } }; |
186 |
my $q = { |
187 |
explain => 1, |
188 |
query => { constant_score => $filter }, |
189 |
|
190 |
diff --git a/scripts/module_log.pl b/scripts/module_log.pl |
191 |
index ef1c592..92f976b 100755 |
192 |
--- a/scripts/module_log.pl |
193 |
+++ b/scripts/module_log.pl |
194 |
@@ -15,14 +15,19 @@ my $flags; |
195 |
my $singleflags; |
196 |
|
197 |
@ARGV = grep { defined } map { |
198 |
- $_ =~ /^--(\w+)/ |
199 |
+ $_ =~ /^--(.+)/ |
200 |
? do { $flags->{$1}++; undef } |
201 |
: do { |
202 |
- $_ =~ /^-(\w+)/ |
203 |
+ $_ =~ /^-(.+)/ |
204 |
? do { $singleflags->{$1}++; undef } |
205 |
: do { $_ } |
206 |
} |
207 |
} @ARGV; |
208 |
+for my $f ( keys %{$flags} ) { |
209 |
+ if ( $f =~ /^([^=]+)=(.*$)/ ) { |
210 |
+ $flags->{$1} = $2; |
211 |
+ } |
212 |
+} |
213 |
|
214 |
if ( $flags->{help} or $singleflags->{h} ) { print help(); exit 0; } |