Added cloning to queries
diff --git a/lib/Krawfish/Query.pm b/lib/Krawfish/Query.pm
index a9a5454..295a735 100644
--- a/lib/Krawfish/Query.pm
+++ b/lib/Krawfish/Query.pm
@@ -27,9 +27,7 @@
sub next;
-sub clone {
- ...
-};
+sub clone;
# TODO:
diff --git a/lib/Krawfish/Query/Cache.pm b/lib/Krawfish/Query/Cache.pm
index 5f5c4b1..79490f5 100644
--- a/lib/Krawfish/Query/Cache.pm
+++ b/lib/Krawfish/Query/Cache.pm
@@ -21,4 +21,6 @@
sub max_freq;
+sub clone;
+
1;
diff --git a/lib/Krawfish/Query/Class.pm b/lib/Krawfish/Query/Class.pm
index 0d25ffa..76241a8 100644
--- a/lib/Krawfish/Query/Class.pm
+++ b/lib/Krawfish/Query/Class.pm
@@ -14,6 +14,13 @@
}, $class;
};
+sub clone {
+ my $self = shift;
+ __PACKAGE__->new(
+ $self->{span}->clone,
+ $self->{number}
+ );
+};
sub next {
my $self = shift;
diff --git a/lib/Krawfish/Query/Constraint/ClassDistance.pm b/lib/Krawfish/Query/Constraint/ClassDistance.pm
index 9f317fb..28e0c24 100644
--- a/lib/Krawfish/Query/Constraint/ClassDistance.pm
+++ b/lib/Krawfish/Query/Constraint/ClassDistance.pm
@@ -11,6 +11,12 @@
bless \$nr, $class;
};
+sub clone {
+ __PACKAGE__->new(
+ ${$_[0]}
+ );
+};
+
sub check {
my $self = shift;
my ($first, $second) = @_;
diff --git a/lib/Krawfish/Query/Constraint/Depth.pm b/lib/Krawfish/Query/Constraint/Depth.pm
index deb138b..1d3408c 100644
--- a/lib/Krawfish/Query/Constraint/Depth.pm
+++ b/lib/Krawfish/Query/Constraint/Depth.pm
@@ -23,6 +23,13 @@
};
+sub clone {
+ __PACKAGE__->new(
+ $_[0]->{min},
+ $_[0]->{max}
+ );
+};
+
# Overwrite
sub check {
my $self = shift;
diff --git a/lib/Krawfish/Query/Constraint/InBetween.pm b/lib/Krawfish/Query/Constraint/InBetween.pm
index 4a90663..c5c36bb 100644
--- a/lib/Krawfish/Query/Constraint/InBetween.pm
+++ b/lib/Krawfish/Query/Constraint/InBetween.pm
@@ -44,6 +44,15 @@
}, $class;
};
+sub clone {
+ my $self = shift;
+ __PACKAGE__->new(
+ $self->{min},
+ $self->{max},
+ $self->{foundry},
+ $self->{gaps}
+ );
+};
# Initialize foundry
sub init {
diff --git a/lib/Krawfish/Query/Constraint/InDistanceSpan.pm b/lib/Krawfish/Query/Constraint/InDistanceSpan.pm
index 60f139f..b4e2d4a 100644
--- a/lib/Krawfish/Query/Constraint/InDistanceSpan.pm
+++ b/lib/Krawfish/Query/Constraint/InDistanceSpan.pm
@@ -22,6 +22,8 @@
}, $class;
};
+sub clone;
+
sub _init {
return if $_[0]->{init}++;
print_log('c_dist', 'Init distance span') if DEBUG;
diff --git a/lib/Krawfish/Query/Constraint/NotBetween.pm b/lib/Krawfish/Query/Constraint/NotBetween.pm
index 02237e1..fac7543 100644
--- a/lib/Krawfish/Query/Constraint/NotBetween.pm
+++ b/lib/Krawfish/Query/Constraint/NotBetween.pm
@@ -27,6 +27,12 @@
};
+sub clone {
+ __PACKAGE__->new(
+ $_[0]->{query}->clone
+ );
+};
+
# Initialize in-between query
sub init {
my $self = shift;
diff --git a/lib/Krawfish/Query/Constraint/Position.pm b/lib/Krawfish/Query/Constraint/Position.pm
index 11de284..9a3ea7e 100644
--- a/lib/Krawfish/Query/Constraint/Position.pm
+++ b/lib/Krawfish/Query/Constraint/Position.pm
@@ -51,6 +51,12 @@
}, $class;
};
+sub clone {
+ __PACKAGE__->new(
+ $_[0]->{frames}
+ );
+};
+
# In case of a configuration A,
# next_a may result in configuration B and
# next_b may result in configuration C
diff --git a/lib/Krawfish/Query/Constraints.pm b/lib/Krawfish/Query/Constraints.pm
index 6aade0b..15c7fc9 100644
--- a/lib/Krawfish/Query/Constraints.pm
+++ b/lib/Krawfish/Query/Constraints.pm
@@ -33,6 +33,17 @@
};
+sub clone {
+ my $self = shift;
+ __PACKAGE__->new(
+ [map { $_->clone } @{$self->{constraints}}],
+ $self->{first}->clone,
+ $self->{second}->clone
+ );
+};
+
+
+
# Check all constraints sequentially
sub check {
my $self = shift;
diff --git a/lib/Krawfish/Query/Exclusion.pm b/lib/Krawfish/Query/Exclusion.pm
index 17b8517..502375f 100644
--- a/lib/Krawfish/Query/Exclusion.pm
+++ b/lib/Krawfish/Query/Exclusion.pm
@@ -48,6 +48,14 @@
# TODO: Return 'first', if second->max_freq == 0
};
+sub clone {
+ my $self = shift;
+ __PACKAGE__->new(
+ $self->{frames},
+ $self->{first}->clone,
+ $self->{second}->clone
+ );
+};
sub check {
my $self = shift;
diff --git a/lib/Krawfish/Query/Extension.pm b/lib/Krawfish/Query/Extension.pm
index 7e6c4f9..db0baf8 100644
--- a/lib/Krawfish/Query/Extension.pm
+++ b/lib/Krawfish/Query/Extension.pm
@@ -21,6 +21,8 @@
};
+sub clone;
+
# Check the configuration
sub check {
...
diff --git a/lib/Krawfish/Query/Filter.pm b/lib/Krawfish/Query/Filter.pm
index 075c3e5..8c00f11 100644
--- a/lib/Krawfish/Query/Filter.pm
+++ b/lib/Krawfish/Query/Filter.pm
@@ -18,6 +18,14 @@
};
+sub clone {
+ my $self = shift;
+ __PACKAGE__->new(
+ $self->{span}->clone,
+ $self->{docs}->clone
+ );
+};
+
# Initialize spans
sub init {
return if $_[0]->{init}++;
diff --git a/lib/Krawfish/Query/Length.pm b/lib/Krawfish/Query/Length.pm
index ae51271..3c52ff0 100644
--- a/lib/Krawfish/Query/Length.pm
+++ b/lib/Krawfish/Query/Length.pm
@@ -19,6 +19,16 @@
}, $class;
};
+sub clone {
+ my $self = shift;
+ __PACKAGE__->new(
+ $self->{span}->clone,
+ $self->{min},
+ $self->{max},
+ $self->{tokens},
+ );
+};
+
# Overwrite
sub next {
my $self = shift;
diff --git a/lib/Krawfish/Query/Match.pm b/lib/Krawfish/Query/Match.pm
index b1bd0d8..ab51666 100644
--- a/lib/Krawfish/Query/Match.pm
+++ b/lib/Krawfish/Query/Match.pm
@@ -15,6 +15,14 @@
}, $class;
};
+sub clone {
+ my $self = shift;
+ __PACKAGE__->new(
+ $self->{doc}->clone,
+ $self->{start},
+ $self->{end}
+ );
+};
sub init {
return if $_[0]->{init}++;
diff --git a/lib/Krawfish/Query/Nothing.pm b/lib/Krawfish/Query/Nothing.pm
index 5bde979..006fb5f 100644
--- a/lib/Krawfish/Query/Nothing.pm
+++ b/lib/Krawfish/Query/Nothing.pm
@@ -14,6 +14,11 @@
return;
};
+sub clone {
+ __PACKAGE__->new;
+};
+
+
sub next {
return;
};
diff --git a/lib/Krawfish/Query/Or.pm b/lib/Krawfish/Query/Or.pm
index 376929c..d843089 100644
--- a/lib/Krawfish/Query/Or.pm
+++ b/lib/Krawfish/Query/Or.pm
@@ -14,6 +14,14 @@
}, $class;
};
+sub clone {
+ my $self = shift;
+ __PACKAGE__->new(
+ $self->{first}->clone,
+ $self->{second}->clone
+ );
+};
+
sub init {
return if $_[0]->{init}++;
if (DEBUG) {
diff --git a/lib/Krawfish/Query/Reference.pm b/lib/Krawfish/Query/Reference.pm
index 346a68e..a4b582f 100644
--- a/lib/Krawfish/Query/Reference.pm
+++ b/lib/Krawfish/Query/Reference.pm
@@ -37,6 +37,8 @@
};
+sub clone;
+
sub next;
diff --git a/lib/Krawfish/Query/Repetition.pm b/lib/Krawfish/Query/Repetition.pm
index d438cb6..2f5bd07 100644
--- a/lib/Krawfish/Query/Repetition.pm
+++ b/lib/Krawfish/Query/Repetition.pm
@@ -26,6 +26,15 @@
};
+sub clone {
+ my $self = shift;
+ __PACKAGE__->new(
+ $self->{span}->clone,
+ $self->{min},
+ $self->{max}
+ );
+};
+
# Initialize spans and buffer
sub init {
return if $_[0]->{init}++;
diff --git a/lib/Krawfish/Query/TermID.pm b/lib/Krawfish/Query/TermID.pm
index 645e9ab..15428a3 100644
--- a/lib/Krawfish/Query/TermID.pm
+++ b/lib/Krawfish/Query/TermID.pm
@@ -18,12 +18,21 @@
or return Krawfish::Query::Nothing->new;
bless {
+ segment => $segment,
postings => $postings->pointer,
term_id => $term_id
}, $class;
};
+sub clone {
+ my $self = shift;
+ __PACKAGE__->new(
+ $self->{segment},
+ $self->{term_id}
+ );
+};
+
# Skip to next position
# This will initialize the posting list
sub next {
diff --git a/lib/Krawfish/Query/Unique.pm b/lib/Krawfish/Query/Unique.pm
index 4fac4f8..7f7c72c 100644
--- a/lib/Krawfish/Query/Unique.pm
+++ b/lib/Krawfish/Query/Unique.pm
@@ -14,6 +14,13 @@
};
};
+sub clone {
+ my $self = shift;
+ __PACKAGE__->new(
+ $self->{span}->clone
+ );
+};
+
sub next {
my $self = shift;