blob: 224b4d0621224997a39471923c35ff417954d3b3 [file] [log] [blame]
Akron5f521532016-10-21 19:30:23 +02001package Krawfish::Index::PostingsList;
Akron73ca2452016-11-20 17:09:39 +01002use Krawfish::Index::PostingPointer;
Akronded01ae2016-11-23 13:43:54 +01003use Krawfish::Log;
Akron5f521532016-10-21 19:30:23 +02004use strict;
5use warnings;
Akron8781e6b2016-12-09 02:04:17 +01006use constant DEBUG => 0;
Akron5f521532016-10-21 19:30:23 +02007
8# TODO: Use different PostingsList for different term types
Akron93271d82016-11-24 09:18:41 +01009#
Akron33f1dcb2016-10-29 17:27:23 +020010# TODO: Split postinglists, so they have different sizes,
Akron73ca2452016-11-20 17:09:39 +010011# that may be fragmented.
Akron5f521532016-10-21 19:30:23 +020012
13sub new {
Akron6e13a062017-01-13 11:55:28 +010014 my ($class, $index_file, $term, $term_id) = @_;
Akron5f521532016-10-21 19:30:23 +020015 bless {
16 term => $term,
Akron6e13a062017-01-13 11:55:28 +010017 term_id => $term_id,
Akronded01ae2016-11-23 13:43:54 +010018 index_file => $index_file,
Akron5f521532016-10-21 19:30:23 +020019 array => [],
Akron73ca2452016-11-20 17:09:39 +010020 pointers => []
Akron5f521532016-10-21 19:30:23 +020021 }, $class;
22};
23
24sub append {
25 my $self = shift;
Akronded01ae2016-11-23 13:43:54 +010026 my (@data) = @_;
27 if (DEBUG) {
28 print_log(
29 'post',
30 "Appended " . $self->term . " with " . join(',', @data)
31 );
32 };
33 push (@{$self->{array}}, [@data]);
Akron5f521532016-10-21 19:30:23 +020034};
35
36sub freq {
37 return scalar @{$_[0]->{array}};
38};
39
40sub term {
41 return $_[0]->{term};
42};
43
Akron6e13a062017-01-13 11:55:28 +010044sub term_id {
45 return $_[0]->{term_id};
46};
47
Akron73ca2452016-11-20 17:09:39 +010048sub at {
49 return $_[0]->{array}->[$_[1]];
50};
51
52sub pointer {
Akron5f521532016-10-21 19:30:23 +020053 my $self = shift;
Akron73ca2452016-11-20 17:09:39 +010054 # TODO: Add pointer to pointer list
55 # so the PostingsList knows, which fragments to lift
56 # Be aware, this may result in circular structures
57 Krawfish::Index::PostingPointer->new($self);
Akron5f521532016-10-21 19:30:23 +020058};
59
Akronded01ae2016-11-23 13:43:54 +010060sub to_string {
61 my $self = shift;
62 join(',', map { '[' . $_ . ']' } @{$self->{array}});
63};
64
65
Akron5f521532016-10-21 19:30:23 +0200661;
67
68__END__
69
Akron5f521532016-10-21 19:30:23 +020070
71
72