line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Solr::Schema; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
15
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
44
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
6
|
1
|
|
|
1
|
|
520
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#use Data::Dumper; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
14
|
|
|
|
|
|
|
'all' => [ |
15
|
|
|
|
|
|
|
qw( |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
) |
18
|
|
|
|
|
|
|
] |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our @EXPORT = qw( |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
30
|
|
|
|
|
|
|
my $class = shift; |
31
|
|
|
|
|
|
|
my (%params) = @_; |
32
|
|
|
|
|
|
|
my $self = \%params; |
33
|
|
|
|
|
|
|
bless( $self, $class ); |
34
|
|
|
|
|
|
|
$self->_init; |
35
|
|
|
|
|
|
|
return $self; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _init { |
39
|
|
|
|
|
|
|
my $self = shift; |
40
|
|
|
|
|
|
|
unless ( -f "$self->{schema}" ) { |
41
|
|
|
|
|
|
|
die "$!: must supply the path to the schema.xml file"; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
unless ("$self->{port}") { |
44
|
|
|
|
|
|
|
die "$!: must supply a valid port for solr master server"; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
unless ("$self->{url}") { |
47
|
|
|
|
|
|
|
die "$!: must supply a valid url for solr master server"; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
$self->{update_post_url} = $self->{url} . ":" . $self->{port} . "/solr/update"; |
50
|
|
|
|
|
|
|
$self->_getFields(); |
51
|
|
|
|
|
|
|
return $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _getFields { |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# reads schema file, parses, and takes user declared fields |
57
|
|
|
|
|
|
|
# puts field names into an array of objects under $self->{field} |
58
|
|
|
|
|
|
|
# user defined field attributes can be accessed per object. |
59
|
|
|
|
|
|
|
# example $self->{field}->{indexed} would return 'true' for a field that is indexed |
60
|
|
|
|
|
|
|
my $self = shift; |
61
|
|
|
|
|
|
|
my $xml = XMLin( $self->{schema} ); |
62
|
|
|
|
|
|
|
$self->{defaultSearchField} = $xml->{defaultSearchField}; # put defaultSearchFeild here for easy access. |
63
|
|
|
|
|
|
|
$self->{uniqueKey} = $xml->{uniqueKey}; # put uniqueKey here for easy access |
64
|
|
|
|
|
|
|
$self->{schemaXml} = $xml; # put the entire schema in this hash for access if needed |
65
|
|
|
|
|
|
|
my @fields; |
66
|
|
|
|
|
|
|
$self->{fields} = |
67
|
|
|
|
|
|
|
$xml->{fields}; # puts data structure into $self->{fields} based |
68
|
|
|
|
|
|
|
#on schema data structure. Here's a typical example as in the solr example schema config |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# fields = { |
71
|
|
|
|
|
|
|
# 'dynamicField' => { |
72
|
|
|
|
|
|
|
# '*_t' => { |
73
|
|
|
|
|
|
|
# 'indexed' => 'true', |
74
|
|
|
|
|
|
|
# 'stored' => 'true', |
75
|
|
|
|
|
|
|
# 'type' => 'text' |
76
|
|
|
|
|
|
|
# }, |
77
|
|
|
|
|
|
|
# '*_i' => { |
78
|
|
|
|
|
|
|
# 'indexed' => 'true', |
79
|
|
|
|
|
|
|
# 'stored' => 'true', |
80
|
|
|
|
|
|
|
# 'type' => 'sint' |
81
|
|
|
|
|
|
|
# }, |
82
|
|
|
|
|
|
|
# '*_d' => { |
83
|
|
|
|
|
|
|
# 'indexed' => 'true', |
84
|
|
|
|
|
|
|
# 'stored' => 'true', |
85
|
|
|
|
|
|
|
# 'type' => 'sdouble' |
86
|
|
|
|
|
|
|
# }, |
87
|
|
|
|
|
|
|
# '*_f' => { |
88
|
|
|
|
|
|
|
# 'indexed' => 'true', |
89
|
|
|
|
|
|
|
# 'stored' => 'true', |
90
|
|
|
|
|
|
|
# 'type' => 'sfloat' |
91
|
|
|
|
|
|
|
# }, |
92
|
|
|
|
|
|
|
# '*_l' => { |
93
|
|
|
|
|
|
|
# 'indexed' => 'true', |
94
|
|
|
|
|
|
|
# 'stored' => 'true', |
95
|
|
|
|
|
|
|
# 'type' => 'slong' |
96
|
|
|
|
|
|
|
# }, |
97
|
|
|
|
|
|
|
# '*_b' => { |
98
|
|
|
|
|
|
|
# 'indexed' => 'true', |
99
|
|
|
|
|
|
|
# 'stored' => 'true', |
100
|
|
|
|
|
|
|
# 'type' => 'boolean' |
101
|
|
|
|
|
|
|
# }, |
102
|
|
|
|
|
|
|
# '*_s' => { |
103
|
|
|
|
|
|
|
# 'indexed' => 'true', |
104
|
|
|
|
|
|
|
# 'stored' => 'true', |
105
|
|
|
|
|
|
|
# 'type' => 'string' |
106
|
|
|
|
|
|
|
# }, |
107
|
|
|
|
|
|
|
# '*_dt' => { |
108
|
|
|
|
|
|
|
# 'indexed' => 'true', |
109
|
|
|
|
|
|
|
# 'stored' => 'true', |
110
|
|
|
|
|
|
|
# 'type' => 'date' |
111
|
|
|
|
|
|
|
# } |
112
|
|
|
|
|
|
|
# }, |
113
|
|
|
|
|
|
|
# 'field' => { |
114
|
|
|
|
|
|
|
# 'features' => { |
115
|
|
|
|
|
|
|
# 'indexed' => 'true', |
116
|
|
|
|
|
|
|
# 'multiValued' => 'true', |
117
|
|
|
|
|
|
|
# 'stored' => 'true', |
118
|
|
|
|
|
|
|
# 'type' => 'text' |
119
|
|
|
|
|
|
|
# }, |
120
|
|
|
|
|
|
|
# 'sku' => { |
121
|
|
|
|
|
|
|
# 'indexed' => 'true', |
122
|
|
|
|
|
|
|
# 'omitNorms' => 'true', |
123
|
|
|
|
|
|
|
# 'stored' => 'true', |
124
|
|
|
|
|
|
|
# 'type' => 'textTight' |
125
|
|
|
|
|
|
|
# }, |
126
|
|
|
|
|
|
|
# 'name' => { |
127
|
|
|
|
|
|
|
# 'indexed' => 'true', |
128
|
|
|
|
|
|
|
# 'stored' => 'true', |
129
|
|
|
|
|
|
|
# 'type' => 'text' |
130
|
|
|
|
|
|
|
# }, |
131
|
|
|
|
|
|
|
# 'manu' => { |
132
|
|
|
|
|
|
|
# 'indexed' => 'true', |
133
|
|
|
|
|
|
|
# 'omitNorms' => 'true', |
134
|
|
|
|
|
|
|
# 'stored' => 'true', |
135
|
|
|
|
|
|
|
# 'type' => 'text' |
136
|
|
|
|
|
|
|
# }, |
137
|
|
|
|
|
|
|
# 'popularity' => { |
138
|
|
|
|
|
|
|
# 'indexed' => 'true', |
139
|
|
|
|
|
|
|
# 'stored' => 'true', |
140
|
|
|
|
|
|
|
# 'type' => 'sint' |
141
|
|
|
|
|
|
|
## }, |
142
|
|
|
|
|
|
|
# 'cat' => { |
143
|
|
|
|
|
|
|
# 'indexed' => 'true', |
144
|
|
|
|
|
|
|
# 'multiValued' => 'true', |
145
|
|
|
|
|
|
|
# 'omitNorms' => 'true', |
146
|
|
|
|
|
|
|
# 'stored' => 'true', |
147
|
|
|
|
|
|
|
# 'type' => 'text_ws' |
148
|
|
|
|
|
|
|
# }, |
149
|
|
|
|
|
|
|
# 'manu_exact' => { |
150
|
|
|
|
|
|
|
# 'indexed' => 'true', |
151
|
|
|
|
|
|
|
# 'stored' => 'false', |
152
|
|
|
|
|
|
|
# 'type' => 'string' |
153
|
|
|
|
|
|
|
# }, |
154
|
|
|
|
|
|
|
# 'text' => { |
155
|
|
|
|
|
|
|
# 'indexed' => 'true', |
156
|
|
|
|
|
|
|
# 'multiValued' => 'true', |
157
|
|
|
|
|
|
|
# 'stored' => 'false', |
158
|
|
|
|
|
|
|
# 'type' => 'text' |
159
|
|
|
|
|
|
|
# }, |
160
|
|
|
|
|
|
|
# 'weight' => { |
161
|
|
|
|
|
|
|
# 'indexed' => 'true', |
162
|
|
|
|
|
|
|
# 'stored' => 'true', |
163
|
|
|
|
|
|
|
# 'type' => 'sfloat' |
164
|
|
|
|
|
|
|
# }, |
165
|
|
|
|
|
|
|
# 'price' => { |
166
|
|
|
|
|
|
|
# 'indexed' => 'true', |
167
|
|
|
|
|
|
|
# 'stored' => 'true', |
168
|
|
|
|
|
|
|
# 'type' => 'sfloat' |
169
|
|
|
|
|
|
|
# }, |
170
|
|
|
|
|
|
|
# 'id' => { |
171
|
|
|
|
|
|
|
# 'indexed' => 'true', |
172
|
|
|
|
|
|
|
# 'stored' => 'true', |
173
|
|
|
|
|
|
|
# 'type' => 'string' |
174
|
|
|
|
|
|
|
# }, |
175
|
|
|
|
|
|
|
# 'includes' => { |
176
|
|
|
|
|
|
|
# 'indexed' => 'true', |
177
|
|
|
|
|
|
|
# 'stored' => 'true', |
178
|
|
|
|
|
|
|
# 'type' => 'text' |
179
|
|
|
|
|
|
|
# }, |
180
|
|
|
|
|
|
|
# 'inStock' => { |
181
|
|
|
|
|
|
|
# 'indexed' => 'true', |
182
|
|
|
|
|
|
|
# 'stored' => 'true', |
183
|
|
|
|
|
|
|
# 'type' => 'boolean' |
184
|
|
|
|
|
|
|
# } |
185
|
|
|
|
|
|
|
# } |
186
|
|
|
|
|
|
|
# }; |
187
|
|
|
|
|
|
|
# creates a simply array of non_dyamic fields |
188
|
|
|
|
|
|
|
foreach my $key ( keys %{ $xml->{fields}->{field} } ) { |
189
|
|
|
|
|
|
|
push @fields, $key; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
# store array here |
193
|
|
|
|
|
|
|
$self->{field} = \@fields; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
# creates a simply array of dyamic fields |
197
|
|
|
|
|
|
|
my @dfields; |
198
|
|
|
|
|
|
|
foreach my $key ( keys %{ $xml->{fields}->{dynamicField} } ) { |
199
|
|
|
|
|
|
|
push @dfields, $key; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
# store array here |
203
|
|
|
|
|
|
|
$self->{dyanamic} = \@dfields; |
204
|
|
|
|
|
|
|
return $self; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
1; |
208
|
|
|
|
|
|
|
__END__ |