line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Metadata::ByInode::Search; |
2
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
276
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1648
|
|
4
|
|
|
|
|
|
|
our $VERSION = sprintf "%d.%02d", q$Revision: 1.11 $ =~ /(\d+)/g; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#returns boolean, did a search complete? |
8
|
|
|
|
|
|
|
sub _sran { |
9
|
10
|
|
|
10
|
|
14
|
my $self= shift; |
10
|
10
|
50
|
|
|
|
27
|
$self->{_search} or return 0; |
11
|
10
|
|
|
|
|
27
|
return 1; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub results_count { |
17
|
8
|
|
|
8
|
0
|
23
|
my $self = shift; |
18
|
8
|
50
|
|
|
|
27
|
$self->_sran or return; |
19
|
|
|
|
|
|
|
|
20
|
8
|
|
|
|
|
33
|
return $self->{_search}->{count}; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub search_results { |
24
|
2
|
|
|
2
|
0
|
6492
|
my $self = shift; |
25
|
2
|
50
|
|
|
|
6
|
$self->_sran or return; |
26
|
|
|
|
|
|
|
|
27
|
2
|
50
|
|
|
|
7
|
$self->results_count or return []; # return empty if none found |
28
|
|
|
|
|
|
|
|
29
|
2
|
50
|
|
|
|
6
|
unless ( defined $self->{_search}->{results_array}) { |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
4
|
for (keys %{$self->{_search}->{data}} ){ |
|
2
|
|
|
|
|
9
|
|
32
|
4
|
|
|
|
|
5
|
my $inode = $_; |
33
|
4
|
|
|
|
|
11
|
my $hash = $self->{_search}->{data}->{$inode}; |
34
|
4
|
|
|
|
|
11
|
$hash->{inode} = $inode; |
35
|
4
|
|
|
|
|
5
|
push @{$self->{_search}->{results_array}},$hash; |
|
4
|
|
|
|
|
13
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
11
|
return $self->{_search}->{results_array}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub search { # multiple key lookup and ranked |
44
|
5
|
|
|
5
|
0
|
2558
|
my $self = shift; |
45
|
5
|
50
|
|
|
|
11
|
my $arg = shift; ref $arg eq 'HASH' or croak('missing arg to search'); |
|
5
|
|
|
|
|
28
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# keys in search args? |
48
|
|
|
|
|
|
|
|
49
|
5
|
50
|
|
|
|
9
|
keys %{$arg} or croak('no arguments, must be hash ref with args and vals'); |
|
5
|
|
|
|
|
24
|
|
50
|
|
|
|
|
|
|
|
51
|
5
|
|
|
|
|
77
|
$self->_search_reset; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
5
|
|
|
|
|
5
|
my $argcount = keys %{$arg}; |
|
5
|
|
|
|
|
11
|
|
55
|
|
|
|
|
|
|
### $argcount |
56
|
|
|
|
|
|
|
|
57
|
5
|
|
|
|
|
25
|
my $select= { |
58
|
|
|
|
|
|
|
'like' => $self->dbh->prepare("SELECT * FROM metadata WHERE mkey=? and mvalue LIKE ?"), |
59
|
|
|
|
|
|
|
'exact' => $self->dbh->prepare("SELECT * FROM metadata WHERE mkey=? and mvalue=?"), |
60
|
|
|
|
|
|
|
}; |
61
|
5
|
|
|
|
|
353
|
my $sk = 'like'; #default |
62
|
|
|
|
|
|
|
|
63
|
5
|
|
|
|
|
10
|
my $RESULT = {}; |
64
|
|
|
|
|
|
|
|
65
|
5
|
|
|
|
|
8
|
for ( keys %{$arg} ){ |
|
5
|
|
|
|
|
19
|
|
66
|
8
|
|
|
|
|
16
|
my ($key,$value)= ($_,undef); |
67
|
|
|
|
|
|
|
|
68
|
8
|
100
|
|
|
|
29
|
if ($key=~s/:exact$//){ # EXACT, so they can override the like |
69
|
1
|
|
|
|
|
3
|
$value = $arg->{$_}; |
70
|
1
|
|
|
|
|
2
|
$sk= 'exact'; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else { # LIKE |
73
|
7
|
|
|
|
|
24
|
$key=~s/:like$//; # just in case |
74
|
7
|
|
|
|
|
22
|
$value = "%".$arg->{$_}."%"; |
75
|
7
|
|
|
|
|
13
|
$sk ='like' |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
8
|
50
|
|
|
|
910
|
$select->{$sk}->execute($key,$value) or warn("cannot search? $DBI::errstr"); |
79
|
|
|
|
|
|
|
|
80
|
8
|
|
|
|
|
109
|
while ( my $row = $select->{$sk}->fetch ){ |
81
|
33
|
|
|
|
|
333
|
$RESULT->{$row->[0]}->{_hit}++; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# just leave the result whose count matches num of args? |
87
|
|
|
|
|
|
|
# instead should order them to the back.. ? |
88
|
5
|
|
|
|
|
14
|
my $count = 0; |
89
|
5
|
|
|
|
|
8
|
for (keys %{$RESULT}){ |
|
5
|
|
|
|
|
20
|
|
90
|
|
|
|
|
|
|
|
91
|
28
|
100
|
|
|
|
70
|
if( $RESULT->{$_}->{_hit} < $argcount ){ |
92
|
22
|
|
|
|
|
37
|
delete $RESULT->{$_}; |
93
|
22
|
|
|
|
|
28
|
next; |
94
|
|
|
|
|
|
|
} |
95
|
6
|
|
|
|
|
25
|
$RESULT->{$_} = $self->get_all($_); |
96
|
6
|
|
|
|
|
16
|
$count++; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
5
|
|
|
|
|
25
|
$self->{_search}->{count} = $count; |
100
|
5
|
|
|
|
|
14
|
$self->{_search}->{data} = $RESULT; |
101
|
5
|
|
|
|
|
132
|
return $RESULT; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _search_reset { |
110
|
5
|
|
|
5
|
|
11
|
my $self = shift; |
111
|
5
|
|
|
|
|
15
|
$self->{_search} = undef; |
112
|
5
|
|
|
|
|
20
|
return 1; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |
116
|
|
|
|
|
|
|
__END__ |