Move K::Posting::Match to K::Koral::Result::Match and K::Koral::Result::Enrich::*

Change-Id: If244612f02f7a75e65ce75a943f48c9c61a15815
diff --git a/lib/Krawfish/Posting/Match/Fields.pm b/lib/Krawfish/Koral/Result/Enrich/Fields.pm
similarity index 89%
rename from lib/Krawfish/Posting/Match/Fields.pm
rename to lib/Krawfish/Koral/Result/Enrich/Fields.pm
index 34c04d5..f9e6e56 100644
--- a/lib/Krawfish/Posting/Match/Fields.pm
+++ b/lib/Krawfish/Koral/Result/Enrich/Fields.pm
@@ -1,4 +1,4 @@
-package Krawfish::Posting::Match::Fields;
+package Krawfish::Koral::Result::Enrich::Fields;
 use strict;
 use warnings;
 
diff --git a/lib/Krawfish/Posting/Match/Snippet.pm b/lib/Krawfish/Koral/Result/Enrich/Snippet.pm
similarity index 91%
rename from lib/Krawfish/Posting/Match/Snippet.pm
rename to lib/Krawfish/Koral/Result/Enrich/Snippet.pm
index b04ac8e..1672094 100644
--- a/lib/Krawfish/Posting/Match/Snippet.pm
+++ b/lib/Krawfish/Koral/Result/Enrich/Snippet.pm
@@ -1,4 +1,4 @@
-package Krawfish::Posting::Match::Snippet;
+package Krawfish::Koral::Result::Enrich::Snippet;
 use strict;
 use warnings;
 
diff --git a/lib/Krawfish/Posting/Match/SortCriteria.pm b/lib/Krawfish/Koral/Result/Enrich/SortCriteria.pm
similarity index 89%
rename from lib/Krawfish/Posting/Match/SortCriteria.pm
rename to lib/Krawfish/Koral/Result/Enrich/SortCriteria.pm
index e2120de..9c9798e 100644
--- a/lib/Krawfish/Posting/Match/SortCriteria.pm
+++ b/lib/Krawfish/Koral/Result/Enrich/SortCriteria.pm
@@ -1,4 +1,4 @@
-package Krawfish::Posting::Match::SortCriteria;
+package Krawfish::Koral::Result::Enrich::SortCriteria;
 use strict;
 use warnings;
 
diff --git a/lib/Krawfish/Posting/Match/Terms.pm b/lib/Krawfish/Koral/Result/Enrich/Terms.pm
similarity index 95%
rename from lib/Krawfish/Posting/Match/Terms.pm
rename to lib/Krawfish/Koral/Result/Enrich/Terms.pm
index 70aa186..8c8b039 100644
--- a/lib/Krawfish/Posting/Match/Terms.pm
+++ b/lib/Krawfish/Koral/Result/Enrich/Terms.pm
@@ -1,4 +1,4 @@
-package Krawfish::Posting::Match::Terms;
+package Krawfish::Koral::Result::Enrich::Terms;
 use strict;
 use warnings;
 
diff --git a/lib/Krawfish/Koral/Result/Match.pm b/lib/Krawfish/Koral/Result/Match.pm
index 96e340a..84e22f2 100644
--- a/lib/Krawfish/Koral/Result/Match.pm
+++ b/lib/Krawfish/Koral/Result/Match.pm
@@ -1,18 +1,95 @@
 package Krawfish::Koral::Result::Match;
-use strict;
+use parent 'Krawfish::Posting';
+use Krawfish::Util::String qw/squote/;
 use warnings;
+use strict;
 
 # TODO:
-#   This may be embedded in documents!
-#
-# TODO:
-#   This may rather be Krawish::Posting::Match ...
+#   Move Posting::Match, Posting::Aggregate, Posting::Group,
+#   Posting etc. to Koral::Result
 
-sub new {
-  my $class = shift;
-  my $self = bless {
-    @_
-  }, $class;
+# TODO:
+#   Rename Koral::Result::Match::* to Koral::Result::Enrich::*
+
+# Matches are returned from searches and can be enriched
+# with various information
+
+# Enrichments can include
+#   snippet
+#   fields
+#   sorting_criteria
+#   segment_id
+#   match_id
+
+
+# Add an enrichment
+sub add {
+  my $self = shift;
+  $self->{enrichments} //= [];
+  push @{$self->{enrichments}}, @_;
 };
 
+
+# Inflate enrichments
+sub inflate {
+  my ($self, $dict) = @_;
+  my $enrichments = $self->{enrichments} // [];
+  for (my $i = 0; $i < @$enrichments; $i++) {
+    $enrichments->[$i] = $enrichments->[$i]->inflate($dict);
+  };
+  return $self;
+};
+
+
+# Stringification
+sub to_string {
+  my $self = shift;
+  my $str = '[';
+
+  # Identical to Posting
+  $str .= $self->doc_id . ':' .
+    $self->start . '-' .
+    $self->end;
+
+  if ($self->payload->length) {
+    $str .= '$' . $self->payload->to_string;
+  };
+
+  foreach (@{$self->{enrichments}}) {
+    $str .= '|' . $_->to_string;
+  };
+
+  return $str . ']';
+};
+
+
+sub to_term_string {
+  my $self = shift;
+  my $str = '[';
+
+  # Identical to Posting
+  $str .= $self->doc_id . ':' .
+    $self->start . '-' .
+    $self->end;
+
+  if ($self->payload->length) {
+    $str .= '$' . $self->payload->to_string;
+  };
+
+  foreach (@{$self->{enrichments}}) {
+    $str .= '|' . $_->to_term_string;
+  };
+
+  return $str . ']';
+};
+
+
+# serialize to koralquery
+sub to_koral_query {
+  ...
+};
+
+
+
+
 1;
diff --git a/lib/Krawfish/Posting/Match.pm b/lib/Krawfish/Posting/Match.pm
deleted file mode 100644
index dffea44..0000000
--- a/lib/Krawfish/Posting/Match.pm
+++ /dev/null
@@ -1,93 +0,0 @@
-package Krawfish::Posting::Match;
-use parent 'Krawfish::Posting';
-use Krawfish::Util::String qw/squote/;
-use warnings;
-use strict;
-
-# TODO:
-#   Move Posting::Match, Posting::Aggregate, Posting::Group,
-#   Posting etc. to Koral::Result
-
-# TODO:
-#   Rename Koral::Result::Match::* to Koral::Result::Enrich::*
-
-# Matches are returned from searches and can be enriched
-# with various information
-
-# Enrichments can include
-#   snippet
-#   fields
-#   sorting_criteria
-#   segment_id
-#   match_id
-
-
-# Add an enrichment
-sub add {
-  my $self = shift;
-  $self->{enrichments} //= [];
-  push @{$self->{enrichments}}, @_;
-};
-
-
-# Inflate enrichments
-sub inflate {
-  my ($self, $dict) = @_;
-  my $enrichments = $self->{enrichments} // [];
-  for (my $i = 0; $i < @$enrichments; $i++) {
-    $enrichments->[$i] = $enrichments->[$i]->inflate($dict);
-  };
-  return $self;
-};
-
-# Stringification
-sub to_string {
-  my $self = shift;
-  my $str = '[';
-
-  # Identical to Posting
-  $str .= $self->doc_id . ':' .
-    $self->start . '-' .
-    $self->end;
-
-  if ($self->payload->length) {
-    $str .= '$' . $self->payload->to_string;
-  };
-
-  foreach (@{$self->{enrichments}}) {
-    $str .= '|' . $_->to_string;
-  };
-
-  return $str . ']';
-};
-
-
-sub to_term_string {
-  my $self = shift;
-  my $str = '[';
-
-  # Identical to Posting
-  $str .= $self->doc_id . ':' .
-    $self->start . '-' .
-    $self->end;
-
-  if ($self->payload->length) {
-    $str .= '$' . $self->payload->to_string;
-  };
-
-  foreach (@{$self->{enrichments}}) {
-    $str .= '|' . $_->to_term_string;
-  };
-
-  return $str . ']';
-};
-
-# serialize to koralquery
-sub to_koral_query {
-  ...
-};
-
-
-
-
-1;
diff --git a/lib/Krawfish/Result.pm b/lib/Krawfish/Result.pm
index 7831d10..1cc873b 100644
--- a/lib/Krawfish/Result.pm
+++ b/lib/Krawfish/Result.pm
@@ -4,7 +4,7 @@
 # TODO:
 #   Rename Krawfish::Result to Krawfish::Meta
 
-use Krawfish::Posting::Match;
+use Krawfish::Koral::Result::Match;
 use Krawfish::Log;
 use strict;
 use warnings;
@@ -15,7 +15,7 @@
   my $self = shift;
   my $current = $self->current;
   return unless $current;
-  return Krawfish::Posting::Match->new(
+  return Krawfish::Koral::Result::Match->new(
     doc_id  => $current->doc_id,
     start   => $current->start,
     end     => $current->end,
@@ -57,7 +57,7 @@
     print_log('result', 'Current posting is '. $self->{query}->to_string) if DEBUG;
 
     # Create new match
-    $match = Krawfish::Posting::Match->new(
+    $match = Krawfish::Koral::Result::Match->new(
       doc_id  => $current->doc_id,
       start   => $current->start,
       end     => $current->end,
diff --git a/lib/Krawfish/Result/Group/Spans.pm b/lib/Krawfish/Result/Group/Spans.pm
index a34a573..6248215 100644
--- a/lib/Krawfish/Result/Group/Spans.pm
+++ b/lib/Krawfish/Result/Group/Spans.pm
@@ -1,7 +1,6 @@
 package Krawfish::Result::Group::Spans;
 use parent 'Krawfish::Result';
 use Krawfish::Log;
-use Krawfish::Posting::Match;
 use strict;
 use warnings;
 
diff --git a/lib/Krawfish/Result/Segment/Enrich/Fields.pm b/lib/Krawfish/Result/Segment/Enrich/Fields.pm
index 1f2c1c2..9368063 100644
--- a/lib/Krawfish/Result/Segment/Enrich/Fields.pm
+++ b/lib/Krawfish/Result/Segment/Enrich/Fields.pm
@@ -1,6 +1,6 @@
 package Krawfish::Result::Segment::Enrich::Fields;
 use parent 'Krawfish::Result';
-use Krawfish::Posting::Match::Fields;
+use Krawfish::Koral::Result::Enrich::Fields;
 use Krawfish::Log;
 use strict;
 use warnings;
@@ -74,7 +74,7 @@
 
     # Create an enrichment
     $match->add(
-      Krawfish::Posting::Match::Fields->new(@{$self->{last_fields}})
+      Krawfish::Koral::Result::Enrich::Fields->new(@{$self->{last_fields}})
       );
 
     # The document has no associated fields
@@ -107,7 +107,7 @@
 
   # Create an enrichment
   $match->add(
-    Krawfish::Posting::Match::Fields->new(@fields)
+    Krawfish::Koral::Result::Enrich::Fields->new(@fields)
     );
 
   $self->{match} = $match;
diff --git a/lib/Krawfish/Result/Segment/Enrich/Snippet.pm b/lib/Krawfish/Result/Segment/Enrich/Snippet.pm
index 8943835..00872d4 100644
--- a/lib/Krawfish/Result/Segment/Enrich/Snippet.pm
+++ b/lib/Krawfish/Result/Segment/Enrich/Snippet.pm
@@ -1,6 +1,6 @@
 package Krawfish::Result::Segment::Enrich::Snippet;
 use parent 'Krawfish::Result';
-use Krawfish::Posting::Match::Snippet;
+use Krawfish::Koral::Result::Enrich::Snippet;
 # use Krawfish::Result::Segment::Enrich::Snippet::Highlights;
 use Krawfish::Log;
 use strict;
@@ -91,7 +91,7 @@
   };
 
   # Create snippet posting
-  my $snippet = Krawfish::Posting::Match::Snippet->new(
+  my $snippet = Krawfish::Koral::Result::Enrich::Snippet->new(
     hit_ids => $hit_data
   );
 
diff --git a/lib/Krawfish/Result/Segment/Enrich/Terms.pm b/lib/Krawfish/Result/Segment/Enrich/Terms.pm
index 23e0b70..7c30951 100644
--- a/lib/Krawfish/Result/Segment/Enrich/Terms.pm
+++ b/lib/Krawfish/Result/Segment/Enrich/Terms.pm
@@ -1,5 +1,5 @@
 package Krawfish::Result::Segment::Enrich::Terms;
-use Krawfish::Posting::Match::Terms;
+use Krawfish::Koral::Result::Enrich::Terms;
 use parent 'Krawfish::Result';
 use Krawfish::Log;
 use strict;
@@ -220,7 +220,7 @@
 
   # Add term id information per class
   $match->add(
-    Krawfish::Posting::Match::Terms->new(
+    Krawfish::Koral::Result::Enrich::Terms->new(
       \%term_id_per_class
     )
   );
diff --git a/lib/Krawfish/Result/Segment/Sort.pm b/lib/Krawfish/Result/Segment/Sort.pm
index 80a354a..907842b 100644
--- a/lib/Krawfish/Result/Segment/Sort.pm
+++ b/lib/Krawfish/Result/Segment/Sort.pm
@@ -2,6 +2,7 @@
 use parent 'Krawfish::Result';
 use Krawfish::Util::String qw/squote/;
 use Krawfish::Util::PriorityQueue::PerDoc;
+use Krawfish::Koral::Result::Match;
 use Krawfish::Posting::Bundle;
 use Krawfish::Log;
 use Data::Dumper;
@@ -440,7 +441,7 @@
 sub current_match {
   my $self = shift;
   my $current = $self->current or return;
-  my $match = Krawfish::Posting::Match->new(
+  my $match = Krawfish::Koral::Result::Match->new(
     doc_id  => $current->doc_id,
     start   => $current->start,
     end     => $current->end,
diff --git a/lib/Krawfish/Result/Segment/Sort/Sample.pm b/lib/Krawfish/Result/Segment/Sort/Sample.pm
index 247e086..809fef4 100644
--- a/lib/Krawfish/Result/Segment/Sort/Sample.pm
+++ b/lib/Krawfish/Result/Segment/Sort/Sample.pm
@@ -1,4 +1,5 @@
 package Krawfish::Result::Segment::Sort::Sample;
+use Krawfish::Koral::Result::Match;
 use Krawfish::Log;
 use strict;
 use warnings;
@@ -134,7 +135,7 @@
 sub current_match {
   my $self = shift;
   my $current = $self->current or return;
-  my $match = Krawfish::Posting::Match->new(
+  my $match = Krawfish::Koral::Result::Match->new(
     doc_id  => $current->doc_id,
     start   => $current->start,
     end     => $current->end,
diff --git a/lib/Krawfish/Result/Sort/PriorityCascade.pm b/lib/Krawfish/Result/Sort/PriorityCascade.pm
index c159d5c..b10f674 100644
--- a/lib/Krawfish/Result/Sort/PriorityCascade.pm
+++ b/lib/Krawfish/Result/Sort/PriorityCascade.pm
@@ -2,6 +2,7 @@
 use parent 'Krawfish::Result';
 use Krawfish::Util::String qw/squote/;
 use Krawfish::Util::PriorityQueue::PerDoc;
+use Krawfish::Koral::Result;
 use Krawfish::Posting::Bundle;
 use Krawfish::Log;
 use Data::Dumper;
@@ -429,7 +430,7 @@
 sub current_match {
   my $self = shift;
   my $current = $self->current or return;
-  my $match = Krawfish::Posting::Match->new(
+  my $match = Krawfish::Koral::Result::Match->new(
     doc_id  => $current->doc_id,
     start   => $current->start,
     end     => $current->end,
diff --git a/t/posting/bundle.t b/t/posting/bundle.t
index 51940fe..b849628 100644
--- a/t/posting/bundle.t
+++ b/t/posting/bundle.t
@@ -3,9 +3,9 @@
 use warnings;
 
 use_ok('Krawfish::Posting::Bundle');
-use_ok('Krawfish::Posting::Match');
+use_ok('Krawfish::Koral::Result::Match');
 
-my $match = Krawfish::Posting::Match->new(
+my $match = Krawfish::Koral::Result::Match->new(
   doc_id => 1,
   start => 2,
   end => 5
@@ -15,7 +15,7 @@
 
 is($matches->to_string, '[[1:2-5]]', 'Stringification');
 
-ok($matches->add(Krawfish::Posting::Match->new(doc_id => 3, start => 5, end => 6)), 'Add');
+ok($matches->add(Krawfish::Koral::Result::Match->new(doc_id => 3, start => 5, end => 6)), 'Add');
 
 is($matches->to_string, '[[1:2-5]|[3:5-6]]', 'Stringification');