| 1 | package KinoSearch1::Index::Term; | ||||||||||
| 2 | 35 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 35 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 35 | ▶ | use KinoSearch1::Util::ToolSet; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 35 | ▶ | use base qw( KinoSearch1::Util::Class ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 35 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 35 | __PACKAGE__->init_instance_vars( | |||||||||
| 9 | field => undef, | ||||||||||
| 10 | text => undef, | ||||||||||
| 11 | ); | ||||||||||
| 12 | 35 | __PACKAGE__->ready_get_set(qw( field text )); | |||||||||
| 13 | } | ||||||||||
| 14 | |||||||||||
| 15 | 636 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 16 | 636 | ▶ | croak("usage: KinoSearch1::Index::Term->new( field, text )") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | unless @_ == 3; | ||||||||||
| 18 | 636 | return bless { | |||||||||
| 19 | field => $_[1], | ||||||||||
| 20 | text => $_[2], | ||||||||||
| 21 | }, | ||||||||||
| 22 | __PACKAGE__; | ||||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | # Alternate, internal constructor. | ||||||||||
| 26 | 10 | ▶ | sub new_from_string { | ||||||||
|
Subroutine
new_from_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 27 | 10 | my ( $class, $termstring, $finfos ) = @_; | |||||||||
| 28 | 10 | my $field_num = unpack( 'n', bytes::substr( $termstring, 0, 2, '' ) ); | |||||||||
| 29 | 10 | my $field_name = $finfos->field_name($field_num); | |||||||||
| 30 | 10 | return __PACKAGE__->new( $field_name, $termstring ); | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | # Return an encoded termstring. Requires a FieldInfos to discover fieldnum. | ||||||||||
| 34 | 2026 | ▶ | sub get_termstring { | ||||||||
|
Subroutine
get_termstring: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 35 | 2026 | ▶ | confess('usage: $term->get_termstring($finfos)') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | unless @_ == 2; | ||||||||||
| 37 | 2026 | my ( $self, $finfos ) = @_; | |||||||||
| 38 | 2026 | my $field_num = $finfos->get_field_num( $self->{field} ); | |||||||||
| 39 | 2026 | ▶ | return unless defined $field_num; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 1980 | return pack( 'n', $field_num ) . $self->{text}; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 12 | ▶ | sub to_string { | ||||||||
|
Subroutine
to_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 44 | 12 | my $self = shift; | |||||||||
| 45 | 12 | return "$self->{field}:$self->{text}"; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 35 | 1; | |||||||||
| 49 | |||||||||||
| 50 | __END__ | ||||||||||