line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sphinx::XML::Pipe2; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: generates xml to feed xmlpipe2 of Sphinx Search |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
686
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
7
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
8
|
1
|
|
|
1
|
|
1625
|
use XML::LibXML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
|
|
|
|
|
|
bless { |
12
|
|
|
|
|
|
|
schema => { field => [], attr => [] }, |
13
|
|
|
|
|
|
|
data => [] |
14
|
|
|
|
|
|
|
}, shift; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub field { shift->declare('field', @_) } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub attr { shift->declare('attr', @_) } |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub declare { push @{shift->{schema}->{ do { shift } } }, [@_] } |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub add { push @{shift->{data}}, [@_] } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub xml { shift->process->toString(2) } |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub process { |
28
|
|
|
|
|
|
|
my ($self) = @_; |
29
|
|
|
|
|
|
|
my $dom = XML::LibXML::Document->new(); |
30
|
|
|
|
|
|
|
$dom->addChild(do { |
31
|
|
|
|
|
|
|
my $docset = $dom->createElement('sphinx:docset'); |
32
|
|
|
|
|
|
|
$docset->addChild(do { |
33
|
|
|
|
|
|
|
my $schema = $dom->createElement('sphinx:schema'); |
34
|
|
|
|
|
|
|
map { |
35
|
|
|
|
|
|
|
$schema->addChild(do { |
36
|
|
|
|
|
|
|
my $node = $dom->createElement('sphinx:field'); |
37
|
|
|
|
|
|
|
$node->setAttribute(name => $_->[0]); |
38
|
|
|
|
|
|
|
$node->setAttribute(attr => $_->[1]) if defined $_->[1]; |
39
|
|
|
|
|
|
|
$node; |
40
|
|
|
|
|
|
|
}); |
41
|
|
|
|
|
|
|
} @{$self->{schema}->{field}}; |
42
|
|
|
|
|
|
|
map { |
43
|
|
|
|
|
|
|
$schema->addChild(do { |
44
|
|
|
|
|
|
|
my $node = $dom->createElement('sphinx:attr'); |
45
|
|
|
|
|
|
|
$node->setAttribute(name => $_->[0]); |
46
|
|
|
|
|
|
|
$node->setAttribute(type => $_->[1]) if defined $_->[1]; |
47
|
|
|
|
|
|
|
$node->setAttribute(bits => $_->[2]) if defined $_->[2]; |
48
|
|
|
|
|
|
|
$node->setAttribute(default => $_->[3]) if defined $_->[3]; |
49
|
|
|
|
|
|
|
$node; |
50
|
|
|
|
|
|
|
}); |
51
|
|
|
|
|
|
|
} @{$self->{schema}->{attr}}; |
52
|
|
|
|
|
|
|
$schema; |
53
|
|
|
|
|
|
|
}); |
54
|
|
|
|
|
|
|
map { # write docs with sub elements (id[, @attr[, @field]]) |
55
|
|
|
|
|
|
|
my $i = $_; |
56
|
|
|
|
|
|
|
my $n = 1; |
57
|
|
|
|
|
|
|
my $doc = $dom->createElement('sphinx:document'); |
58
|
|
|
|
|
|
|
$doc->setAttribute('id', $i->[0]); |
59
|
|
|
|
|
|
|
map { |
60
|
|
|
|
|
|
|
my $node = $dom->createElement($_); |
61
|
|
|
|
|
|
|
$node->appendText($i->[$n++]); |
62
|
|
|
|
|
|
|
$doc->addChild($node); |
63
|
|
|
|
|
|
|
} map($_->[0], @{$self->{schema}->{attr}}, @{$self->{schema}->{field}}); |
64
|
|
|
|
|
|
|
$docset->addChild($doc); |
65
|
|
|
|
|
|
|
} @{$self->{data}}; |
66
|
|
|
|
|
|
|
$docset; |
67
|
|
|
|
|
|
|
}); |
68
|
|
|
|
|
|
|
$dom; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |