Solr/Schema.pm

filter: Statementstmt 36.5% 19 / 52 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 1 totaltotal 34.8% 23 / 66 CC 6 SCAR 23.2
CC
6
Cov
33%
_init
20.0
_getFields
12.0
new
2.0
CRAP 10.2
« Solr.pm ↑ Summary
1 package Solr::Schema;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 #use Data::Dumper;
8  
9 1 require Exporter;
10  
11 1 our @ISA = qw(Exporter);
12  
13 1 our %EXPORT_TAGS = (
14 'all' => [
15 qw(
16  
17 )
18 ]
19 );
20  
21 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
22  
23 1 our @EXPORT = qw(
24  
25 );
26  
27 1 our $VERSION = '0.03';
28  
29 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
30 0 my $class = shift;
31 0 my (%params) = @_;
32 0 my $self = \%params;
33 0 bless( $self, $class );
34 0 $self->_init;
35 0 return $self;
36 }
37  
38 0 ▶sub _init {
Subroutine _init: not called CC=4 SCAR=30.0
39 0 my $self = shift;
40 0 ▶ unless ( -f "$self->{schema}" ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f qq[$self->{"schema"}]) 0 0 0
41 0 die "$!: must supply the path to the schema.xml file";
42 }
43 0 ▶ unless ("$self->{port}") {
Branch: 1 branch
BranchTrueFalseTotal
unless (qq[$self->{"port"}]) 0 0 0
44 0 die "$!: must supply a valid port for solr master server";
45 }
46 0 ▶ unless ("$self->{url}") {
Branch: 1 branch
BranchTrueFalseTotal
unless (qq[$self->{"url"}]) 0 0 0
47 0 die "$!: must supply a valid url for solr master server";
48 }
49 0 $self->{update_post_url} = $self->{url} . ":" . $self->{port} . "/solr/update";
50 0 $self->_getFields();
51 0 return $self;
52 }
53  
54 0 ▶sub _getFields {
Subroutine _getFields: not called CC=3 SCAR=24.8
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 0 my $self = shift;
61 0 my $xml = XMLin( $self->{schema} );
62 0 $self->{defaultSearchField} = $xml->{defaultSearchField}; # put defaultSearchFeild here for easy access.
63 0 $self->{uniqueKey} = $xml->{uniqueKey}; # put uniqueKey here for easy access
64 0 $self->{schemaXml} = $xml; # put the entire schema in this hash for access if needed
65 0 my @fields;
66 $self->{fields} =
67 0 $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 0 foreach my $key ( keys %{ $xml->{fields}->{field} } ) {
189 0 push @fields, $key;
190 }
191  
192 # store array here
193 0 $self->{field} = \@fields;
194
195  
196 # creates a simply array of dyamic fields
197 0 my @dfields;
198 0 foreach my $key ( keys %{ $xml->{fields}->{dynamicField} } ) {
199 0 push @dfields, $key;
200 }
201  
202 # store array here
203 0 $self->{dyanamic} = \@dfields;
204 0 return $self;
205 }
206  
207 1 1;
208 __END__
« Solr.pm ↑ Summary