lib/KinoSearch1/Document/Field.pm

filter: Statementstmt 100% 40 / 40 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 97.9% 47 / 48 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« lib/KinoSearch1/Search/TermScorer.pm ↑ Summary lib/KinoSearch1/Search/BooleanScorer.pm »
1 package KinoSearch1::Document::Field;
2 use strict;
3 use warnings;
4 use KinoSearch1::Util::ToolSet;
5 use base qw( KinoSearch1::Util::Class );
6  
7 BEGIN {
8 __PACKAGE__->init_instance_vars(
9 # constructor args / members
10 name => undef,
11 analyzer => undef,
12 boost => 1,
13 stored => 1,
14 indexed => 1,
15 analyzed => 1,
16 vectorized => 1,
17 binary => 0,
18 compressed => 0,
19 omit_norms => 0,
20 field_num => undef,
21 value => '',
22 fnm_bits => undef,
23 fdt_bits => undef,
24 tv_string => '',
25 tv_cache => undef,
26 );
27 __PACKAGE__->ready_get_set(
28 qw(
29 value
30 tv_string
31 boost
32 indexed
33 stored
34 analyzed
35 vectorized
36 binary
37 compressed
38 analyzer
39 field_num
40 name
41 omit_norms
42 )
43 );
44 }
45  
46 use KinoSearch1::Index::FieldsReader;
47 use KinoSearch1::Index::FieldInfos;
48 use KinoSearch1::Index::TermVector;
49  
50 use Storable qw( dclone );
51  
52 sub init_instance {
53 my $self = shift;
54  
55 # field name is required
56 croak("Missing required parameter 'name'")
57 unless length $self->{name};
58  
59 # don't index binary fields
60 if ( $self->{binary} ) {
61 $self->{indexed} = 0;
62 $self->{analyzed} = 0;
63 }
64 }
65  
66 sub clone {
67 my $self = shift;
68 return dclone($self);
69 }
70  
71 # Given two Field objects, return a child which has all the positive
72 # attributes of both parents (meaning: values are OR'd).
73 sub breed_with {
74 my ( $self, $other ) = @_;
75 my $kid = $self->clone;
76 for (qw( indexed vectorized )) {
77 $kid->{$_} ||= $other->{$_};
78 }
79 return $kid;
80 }
81  
82 sub set_fnm_bits { $_[0]->{fnm_bits} = $_[1] }
83  
84 sub get_fnm_bits {
85 my $self = shift;
86 $self->{fnm_bits} = KinoSearch1::Index::FieldInfos->encode_fnm_bits($self)
87 unless defined $self->{fnm_bits};
88 return $self->{fnm_bits};
89 }
90  
91 sub set_fdt_bits { $_[0]->{fdt_bits} = $_[1] }
92  
93 sub get_fdt_bits {
94 my $self = shift;
95 $self->{fdt_bits}
96 = KinoSearch1::Index::FieldsReader->encode_fdt_bits($self)
97 unless defined $self->{fdt_bits};
98 return $self->{fdt_bits};
99 }
100  
101 sub get_value_len { bytes::length( $_[0]->{value} ) }
102  
103 # Return a TermVector object for a given Term, if it's in this field.
104 sub term_vector {
105 my ( $self, $term_text ) = @_;
106 return unless bytes::length( $self->{tv_string} );
107 if ( !defined $self->{tv_cache} ) {
108 $self->{tv_cache} = _extract_tv_cache( $self->{tv_string} );
109 }
110 if ( exists $self->{tv_cache}{$term_text} ) {
111 my ( $positions, $starts, $ends )
112 = _unpack_posdata( $self->{tv_cache}{$term_text} );
113 my $term_vector = KinoSearch1::Index::TermVector->new(
114 text => $term_text,
115 field => $self->{name},
116 positions => $positions,
117 start_offsets => $starts,
118 end_offsets => $ends,
119 );
120 return $term_vector;
121 }
122  
123 return;
124 }
125  
126 1;
127  
128 __END__
« lib/KinoSearch1/Search/TermScorer.pm ↑ Summary lib/KinoSearch1/Search/BooleanScorer.pm »