File tree Expand file tree Collapse file tree 1 file changed +97
-0
lines changed Expand file tree Collapse file tree 1 file changed +97
-0
lines changed Original file line number Diff line number Diff line change
1
+ # !/usr/bin/env perl
2
+
3
+ use strict;
4
+ use warnings;
5
+ use Data::Printer;
6
+ use JSON qw( decode_json ) ;
7
+ use MetaCPAN::Util qw( es ) ;
8
+
9
+ my $search_term = shift @ARGV || ' HTML-Re' ;
10
+ if ( $search_term =~ m { ::} ) {
11
+ $search_term =~ s { ::} { -} g ;
12
+ }
13
+
14
+ my $result = es()-> search(
15
+ index => ' v0' ,
16
+ type => ' file' ,
17
+ query => {
18
+ boosting => {
19
+ negative_boost => 0.5,
20
+ positive => {
21
+ bool => {
22
+ should => [
23
+ {
24
+ term => {
25
+ " file.documentation" => {
26
+ boost => 20,
27
+ value => $search_term ,
28
+ }
29
+ }
30
+ },
31
+ {
32
+ term => {
33
+ " file.module.name" => {
34
+ boost => 20,
35
+ value => $search_term ,
36
+ },
37
+ }
38
+ },
39
+ {
40
+ dis_max => {
41
+ queries => [
42
+ {
43
+ query_string => {
44
+ allow_leading_wildcard => 0,
45
+ boost => 3,
46
+ default_operator => " AND" ,
47
+ fields => [
48
+ " documentation.analyzed^2" ,
49
+ " file.module.name.analyzed^2" ,
50
+ " distribution.analyzed" ,
51
+ " documentation.camelcase" ,
52
+ " file.module.name.camelcase" ,
53
+ " distribution.camelcase" ,
54
+ ],
55
+ query => $search_term ,
56
+ use_dis_max => 1,
57
+ },
58
+ },
59
+ {
60
+ query_string => {
61
+ allow_leading_wildcard => 0,
62
+ default_operator => " AND" ,
63
+ fields => [
64
+ " abstract.analyzed" ,
65
+ " pod.analyzed"
66
+ ],
67
+ query => $search_term ,
68
+ use_dis_max => 1,
69
+ },
70
+ },
71
+ ],
72
+ }
73
+ }
74
+ ]
75
+ }
76
+ },
77
+ negative => {
78
+ term => {
79
+ " file.mime" => { value => " text/x-script.perl" }
80
+ }
81
+ }
82
+ }
83
+ },
84
+ size => 10,
85
+ );
86
+
87
+ my @dists = map { $_ -> {_source } } @{ $result -> {hits }-> {hits } };
88
+
89
+ p @dists ;
90
+
91
+ =pod
92
+
93
+ =head1 DESCRIPTION
94
+
95
+ This script will provide search result almost like on MetaCPAN main search [https://metacpan.org/search?q=$search_term]
96
+
97
+ =cut
You can’t perform that action at this time.
0 commit comments