Cleanup and renaming of facets to fields
diff --git a/lib/Krawfish.pm b/lib/Krawfish.pm
index 9747094..d41da4c 100644
--- a/lib/Krawfish.pm
+++ b/lib/Krawfish.pm
@@ -45,7 +45,7 @@
   #   - random
   # - limited
   # - accompanied with
-  #   - field-facets
+  #   - fields
   #   - frequencies
   #   - length information
   #   - field value aggregated information
diff --git a/lib/Krawfish/Index/Rank/MultiFields.pm b/lib/Krawfish/Index/Rank/MultiFields.pm
index 37bffca..bde54b7 100644
--- a/lib/Krawfish/Index/Rank/MultiFields.pm
+++ b/lib/Krawfish/Index/Rank/MultiFields.pm
@@ -5,7 +5,7 @@
 
 # TODO!
 
-# Fields with multiple value need to create
+# Fields with multiple values need to create
 # two ranking vectors: a forward rank and a
 # backward rank.
 #
diff --git a/lib/Krawfish/Koral.pm b/lib/Krawfish/Koral.pm
index 4b08cb8..e029e35 100644
--- a/lib/Krawfish/Koral.pm
+++ b/lib/Krawfish/Koral.pm
@@ -31,10 +31,10 @@
 #   my $mb = $koral->meta_builder;
 #   $koral->meta(
 #     $mb->aggregate(
-#       $mb->aggr_frequencies,
-#       $mb->aggr_facets('license'),
-#       $mb->aggr_facets('corpus'),
-#       $mb->aggr_length
+#       $mb->a_frequencies,
+#       $mb->a_fields('license'),
+#       $mb->a_fields('corpus'),
+#       $mb->a_length
 #     )->start_index(0)
 #     ->items_per_page(20)
 #     ->sort_by(
diff --git a/lib/Krawfish/Koral/Meta/Aggregate.pm b/lib/Krawfish/Koral/Meta/Aggregate.pm
index c008932..ed8f9c2 100644
--- a/lib/Krawfish/Koral/Meta/Aggregate.pm
+++ b/lib/Krawfish/Koral/Meta/Aggregate.pm
@@ -14,7 +14,7 @@
 our %AGGR_ORDER = (
   'length' => 1,
   'freq'   => 2,
-  'facets' => 3,
+  'fields' => 3,
   'values' => 4
 );
 
@@ -73,8 +73,8 @@
     # Two consecutive operations are identical
     if ($ops[$i]->type eq $ops[$i-1]->type) {
 
-      # Merge facets or values
-      if ($ops[$i]->type eq 'facets' || $ops[$i]->type eq 'values') {
+      # Merge fields or values
+      if ($ops[$i]->type eq 'fields' || $ops[$i]->type eq 'values') {
         $ops[$i-1]->operations(
           $ops[$i-1]->operations,
           $ops[$i]->operations
diff --git a/lib/Krawfish/Koral/Meta/Aggregate/Facets.pm b/lib/Krawfish/Koral/Meta/Aggregate/Fields.pm
similarity index 79%
rename from lib/Krawfish/Koral/Meta/Aggregate/Facets.pm
rename to lib/Krawfish/Koral/Meta/Aggregate/Fields.pm
index 11a52b7..eaa66e4 100644
--- a/lib/Krawfish/Koral/Meta/Aggregate/Facets.pm
+++ b/lib/Krawfish/Koral/Meta/Aggregate/Fields.pm
@@ -1,11 +1,8 @@
-package Krawfish::Koral::Meta::Aggregate::Facets;
-use Krawfish::Result::Segment::Aggregate::Facets;
+package Krawfish::Koral::Meta::Aggregate::Fields;
+use Krawfish::Result::Segment::Aggregate::Fields;
 use strict;
 use warnings;
 
-# TODO:
-#   Rename to 'Fields'
-
 sub new {
   my $class = shift;
   bless [@_], $class;
@@ -13,7 +10,7 @@
 
 
 sub type {
-  'facets'
+  'fields'
 };
 
 
@@ -68,14 +65,14 @@
 
 sub to_string {
   my $self = shift;
-  return 'facets:[' . join(',', map { defined $_ ? $_->to_string : '?' } @$self) . ']';
+  return 'fields:[' . join(',', map { defined $_ ? $_->to_string : '?' } @$self) . ']';
 };
 
 
 sub optimize {
   my ($self, $segment) = @_;
 
-  return Krawfish::Result::Segment::Aggregate::Facets->new(
+  return Krawfish::Result::Segment::Aggregate::Fields->new(
     $segment->fields,
     [$self->operations]
   );
diff --git a/lib/Krawfish/Koral/Meta/Builder.pm b/lib/Krawfish/Koral/Meta/Builder.pm
index 390bfb5..b11fd51 100644
--- a/lib/Krawfish/Koral/Meta/Builder.pm
+++ b/lib/Krawfish/Koral/Meta/Builder.pm
@@ -7,7 +7,7 @@
 use Krawfish::Koral::Meta::Sort;
 use Krawfish::Koral::Meta::Sort::Field;
 use Krawfish::Koral::Meta::Aggregate::Frequencies;
-use Krawfish::Koral::Meta::Aggregate::Facets;
+use Krawfish::Koral::Meta::Aggregate::Fields;
 use Krawfish::Koral::Meta::Aggregate::Length;
 use Krawfish::Koral::Meta::Aggregate::Values;
 use Krawfish::Koral::Meta::Group;
@@ -36,10 +36,10 @@
 
 #   $koral->meta(
 #     $mb->aggregate(
-#       $mb->aggr_frequencies,
-#       $mb->aggr_facets('license'),
-#       $mb->aggr_facets('corpus'),
-#       $mb->aggr_length
+#       $mb->a_frequencies,
+#       $mb->a_fields('license'),
+#       $mb->a_fields('corpus'),
+#       $mb->a_length
 #     ),
 #     $mb->start_index(0),
 #     $mn->items_per_page(20)
@@ -61,13 +61,10 @@
 };
 
 
-# Aggregate facets
-# TODO:
-#   Rename to fields, as this is similar to
-#   'group by fields' and 'enrich with fields'
-sub a_facets {
+# Aggregate fields
+sub a_fields {
   shift;
-  return Krawfish::Koral::Meta::Aggregate::Facets->new(
+  return Krawfish::Koral::Meta::Aggregate::Fields->new(
     map {
       blessed $_ ? $_ : Krawfish::Koral::Meta::Type::Key->new($_)
     } @_
diff --git a/lib/Krawfish/Koral/Meta/Enrich.pm b/lib/Krawfish/Koral/Meta/Enrich.pm
index 713c222..fa4605b 100644
--- a/lib/Krawfish/Koral/Meta/Enrich.pm
+++ b/lib/Krawfish/Koral/Meta/Enrich.pm
@@ -68,7 +68,7 @@
     # Two consecutive operations are identical
     if ($ops[$i]->type eq $ops[$i-1]->type) {
 
-      # Merge facets or values
+      # Merge fields or values
       if ($ops[$i]->type eq 'fields') {
         $ops[$i-1]->operations(
           $ops[$i-1]->operations,
diff --git a/lib/Krawfish/Posting.pm b/lib/Krawfish/Posting.pm
index fd3d912..b5bef0b 100644
--- a/lib/Krawfish/Posting.pm
+++ b/lib/Krawfish/Posting.pm
@@ -40,6 +40,7 @@
   return $_[0]->{flags} //= 0b0000_0000_0000_0000;
 };
 
+
 # Compare posting order
 sub compare {
   my ($self, $post) = @_;
@@ -157,7 +158,7 @@
 
 
 # Check if two postings are identical
-sub is_identical {
+sub same_as {
   my ($self, $comp) = @_;
   return unless $comp;
   return $self->to_string eq $comp->to_string;
diff --git a/lib/Krawfish/Posting/Aggregate/Fields.pm b/lib/Krawfish/Posting/Aggregate/Fields.pm
index 04283f2..84d6ccc 100644
--- a/lib/Krawfish/Posting/Aggregate/Fields.pm
+++ b/lib/Krawfish/Posting/Aggregate/Fields.pm
@@ -44,7 +44,7 @@
   $field_freq->[0]++;
 
   if (DEBUG) {
-    print_log('p_a_facets', 'Increment doc frequency for ' . $key_id . ':' . $field_id);
+    print_log('p_a_fields', 'Increment doc frequency for ' . $key_id . ':' . $field_id);
   };
 
 
@@ -60,7 +60,7 @@
   $_[0]->{freq}++;
 
   if (DEBUG) {
-    print_log('p_a_facets', 'Increment match frequency');
+    print_log('p_a_fields', 'Increment match frequency');
   };
 };
 
@@ -78,7 +78,7 @@
     $self->{freq} = 0;
 
     if (DEBUG) {
-      print_log('p_a_facets', 'Flush field frequency for all remembered frequencies');
+      print_log('p_a_fields', 'Flush field frequency for all remembered frequencies');
     };
   };
 };
@@ -109,10 +109,10 @@
     foreach my $value (keys %$values) {
 
       # Get the 
-      my $facet = $dict->term_by_term_id($value);
-      $facet =~ s/^\+$field_term://;
+      my $field = $dict->term_by_term_id($value);
+      $field =~ s/^\+$field_term://;
 
-      $aggr->{$facet} = $values->{$value};
+      $aggr->{$field} = $values->{$value};
     };
   };
 
@@ -125,7 +125,7 @@
 sub to_string {
   my $self = shift;
   if ($self->{fields_terms}) {
-    my $str = 'facets=';
+    my $str = 'fields=';
 
     my $fields = $self->{fields_terms};
 
diff --git a/lib/Krawfish/Posting/Bundle.pm b/lib/Krawfish/Posting/Bundle.pm
index cb8616b..79d679a 100644
--- a/lib/Krawfish/Posting/Bundle.pm
+++ b/lib/Krawfish/Posting/Bundle.pm
@@ -93,4 +93,5 @@
   return @{$_[0]};
 };
 
+
 1;
diff --git a/lib/Krawfish/Posting/DocWithFlags.pm b/lib/Krawfish/Posting/DocWithFlags.pm
deleted file mode 100644
index a95172b..0000000
--- a/lib/Krawfish/Posting/DocWithFlags.pm
+++ /dev/null
@@ -1,26 +0,0 @@
-package Krawfish::Posting::DocWithFlags;
-use strict;
-use warnings;
-use Krawfish::Util::Bits 'bitstring';
-
-
-sub new {
-  my ($class, $id, $flags) = @_;
-  bless [$id, $flags], $class;
-};
-
-# Current document
-sub doc_id {
-  return $_[0]->[0];
-};
-
-sub flags {
-  return $_[0]->[1];
-};
-
-sub to_string {
-  '[' . $_[0]->[0] .
-    '$flags=' . bitstring($_[0]->[1]) . ']';
-};
-
-1;
diff --git a/lib/Krawfish/Posting/Snippet.pm b/lib/Krawfish/Posting/Snippet.pm
deleted file mode 100644
index 78db1e3..0000000
--- a/lib/Krawfish/Posting/Snippet.pm
+++ /dev/null
@@ -1,31 +0,0 @@
-package Krawfish::Posting::Snippet;
-use parent 'Krawfish::Posting';
-use strict;
-use warnings;
-
-sub index {
-  shift->{index} = shift;
-};
-
-sub to_snippet {
-  my $self = shift;
-
-  my $offsets = $self->index->offsets;
-  my $start_subtoken = $offsets->get(
-    $self->doc_id,
-    $self->start
-  );
-
-  my $end_subtoken = $offsets->get(
-    $self->doc_id,
-    $self->end
-  );
-
-  return $self->index->primary->get(
-    $self->doc_id,
-    $start_subtoken,
-    $end_subtoken
-  );
-};
-
-1;
diff --git a/lib/Krawfish/Posting/Token.pm b/lib/Krawfish/Posting/Token.pm
index 769959a..49a8e26 100644
--- a/lib/Krawfish/Posting/Token.pm
+++ b/lib/Krawfish/Posting/Token.pm
@@ -3,10 +3,6 @@
 use strict;
 use warnings;
 
-# TODO:
-#   Join with Krawfish::Posting::Span and make
-#   Krawfish::Query::SpanID useless.
-
 sub new {
   my $class = shift;
   bless [@_], $class;
diff --git a/lib/Krawfish/Query/Unique.pm b/lib/Krawfish/Query/Unique.pm
index 7f7c72c..95d28f1 100644
--- a/lib/Krawfish/Query/Unique.pm
+++ b/lib/Krawfish/Query/Unique.pm
@@ -32,7 +32,7 @@
 
     print_log('unique', 'Found ' . $current->to_string) if DEBUG;
 
-    unless ($current->is_identical($self->{last})) {
+    unless ($current->same_as($self->{last})) {
 
       print_log('unique', 'Span is unique') if DEBUG;
 
diff --git a/lib/Krawfish/Result/Segment/Aggregate/Facets.pm b/lib/Krawfish/Result/Segment/Aggregate/Fields.pm
similarity index 85%
rename from lib/Krawfish/Result/Segment/Aggregate/Facets.pm
rename to lib/Krawfish/Result/Segment/Aggregate/Fields.pm
index da44242..32c13d2 100644
--- a/lib/Krawfish/Result/Segment/Aggregate/Facets.pm
+++ b/lib/Krawfish/Result/Segment/Aggregate/Fields.pm
@@ -1,4 +1,4 @@
-package Krawfish::Result::Segment::Aggregate::Facets;
+package Krawfish::Result::Segment::Aggregate::Fields;
 use parent 'Krawfish::Result::Segment::Aggregate::Base';
 use Krawfish::Posting::Aggregate::Fields;
 use Krawfish::Util::String qw/squote/;
@@ -21,10 +21,6 @@
 
 # TODO:
 #   Support corpus classes!
-#
-# TODO:
-#   Currently this would not work for fields with multiple values!
-#   There may be a need for K::R::S::A::MultiFacets!
 
 # TODO:
 #   In case the field has no rank, because it is a multivalued field,
@@ -64,7 +60,7 @@
 
   my $self = shift;
 
-  print_log('aggr_facets', 'Create pointer on fields') if DEBUG;
+  print_log('aggr_fields', 'Create pointer on fields') if DEBUG;
 
   # Load the ranked list - may be too large for memory!
   $self->{field_pointer} = $self->{field_obj}->pointer;
@@ -77,7 +73,7 @@
 
   $self->_init;
 
-  print_log('aggr_facets', 'Aggregate on fields') if DEBUG;
+  print_log('aggr_fields', 'Aggregate on fields') if DEBUG;
 
   my $doc_id = $current->doc_id;
 
@@ -100,7 +96,7 @@
     # my @fields;
 
     if (DEBUG) {
-      print_log('aggr_facets', 'Look for frequencies for key ids ' .
+      print_log('aggr_fields', 'Look for frequencies for key ids ' .
                   join(',', @{$self->{field_keys}}) . " in $doc_id");
     };
 
@@ -114,7 +110,7 @@
       $aggr->incr_doc($field->key_id, $field->term_id);
 
       if (DEBUG) {
-        print_log('aggr_facets', '#' . $field->term_id . ' has frequencies');
+        print_log('aggr_fields', '#' . $field->term_id . ' has frequencies');
       };
     };
   }
@@ -143,7 +139,7 @@
 
 
 sub collection {
-  # Return facets
+  # Return fields
   # Example structure for year
   # {
   #   1997 => [4, 67],
@@ -155,7 +151,7 @@
 
 
 sub to_string {
-  return 'facets:' . join(',', map { '#' . $_ } @{$_[0]->{field_keys}});
+  return 'fields:' . join(',', map { '#' . $_ } @{$_[0]->{field_keys}});
 };
 
 
diff --git a/lib/Krawfish/Util/SortedList.pm b/lib/Krawfish/Util/SortedList.pm
index 9c6caad..c66cfda 100644
--- a/lib/Krawfish/Util/SortedList.pm
+++ b/lib/Krawfish/Util/SortedList.pm
@@ -1,8 +1,8 @@
 package Krawfish::Util::SortedList;
 use parent 'Krawfish::Query';
+use Krawfish::Posting::Sorted;
 use strict;
 use warnings;
-use Krawfish::Posting::Sorted;
 
 
 use constant {
diff --git a/t/koral/flow.t b/t/koral/flow.t
index 99ba508..ad5e296 100644
--- a/t/koral/flow.t
+++ b/t/koral/flow.t
@@ -13,7 +13,7 @@
 # Create meta
 $koral->meta(
   $mb->aggregate(
-    $mb->a_facets('size', 'age'),
+    $mb->a_fields('size', 'age'),
     $mb->a_frequencies,
     $mb->a_length,
   ),
@@ -47,12 +47,12 @@
   )
 );
 
-is($koral->to_string, "meta=[aggr=[facets:['size','age'],freq,length],enrich=[fields:['age']],sort=[field='author'<]],corpus=[1880&author=Goethe],query=[[/b./|aa][]cc]", 'Serialization');
+is($koral->to_string, "meta=[aggr=[fields:['size','age'],freq,length],enrich=[fields:['age']],sort=[field='author'<]],corpus=[1880&author=Goethe],query=[[/b./|aa][]cc]", 'Serialization');
 
 # Get the query
 ok(my $query = $koral->to_query, 'Create complex query construct');
 
-is($query->to_string, "sort(field='author'<:fields('age':aggr(length,freq,facets:['size','age']:filter(/b./|aa[]cc,1880&author=Goethe))))", 'Stringification');
+is($query->to_string, "sort(field='author'<:fields('age':aggr(length,freq,fields:['size','age']:filter(/b./|aa[]cc,1880&author=Goethe))))", 'Stringification');
 
 # Identify
 # ok($query = $query->identify($index->dict), 'Create complex query construct');
diff --git a/t/koral/meta.t b/t/koral/meta.t
index 0b93fe6..9eccb12 100644
--- a/t/koral/meta.t
+++ b/t/koral/meta.t
@@ -12,11 +12,11 @@
 is($meta->to_string, 'aggr=[freq]', 'Stringification');
 
 ok($meta = $mb->aggregate(
-  $mb->a_facets('size', 'age'),
+  $mb->a_fields('size', 'age'),
   $mb->a_frequencies,
   $mb->a_length
 ), 'Add aggregation');
-is($meta->to_string, "aggr=[facets:['size','age'],freq,length]", 'Stringification');
+is($meta->to_string, "aggr=[fields:['size','age'],freq,length]", 'Stringification');
 
 ok($meta = $mb->enrich(
   $mb->e_fields('author', 'title', 'id')
@@ -72,16 +72,16 @@
 $meta_koral = Krawfish::Koral::Meta->new(
   $mb->aggregate(
     $mb->a_length,
-    $mb->a_facets('author', 'age'),
+    $mb->a_fields('author', 'age'),
     $mb->a_frequencies,
-    $mb->a_facets('corpus', 'age')
+    $mb->a_fields('corpus', 'age')
   )
 );
 
 ok($meta_koral = $meta_koral->normalize, 'Normalization');
 
 is($meta_koral->to_string,
-   "aggr=[length,freq,facets:['author','age','corpus']]",
+   "aggr=[length,freq,fields:['author','age','corpus']]",
    'stringification');
 
 done_testing;
diff --git a/t/plan/meta.t b/t/plan/meta.t
index 0f7a951..d36c924 100644
--- a/t/plan/meta.t
+++ b/t/plan/meta.t
@@ -109,71 +109,3 @@
 __END__
 
 
-
-# Simple meta definition
-$koral->meta(
-  $koral->meta_builder->items_per_page(3)->field_sort_asc_by('author')
-);
-
-ok($koral = $koral->normalize, 'Normalization');
-
-#is($koral->prepare_for($index)->to_string,
-is($koral->to_string,
-   q!resultLimit([0-3]:resultSorted(['author'<,'id'<],0-3:constr(pos=2:'Der','<>opennlp/c=NP')))!,
-   'Stringification');
-
-
-
-
-# Meta definition with start index
-$koral->meta(
-  $koral->meta_builder->items_per_page(5)->start_index(2)->field_sort_asc_by('author')
-);
-
-
-
-is($koral->prepare_for($index)->to_string,
-   q!resultLimit([2-7]:resultSorted(['author'<,'id'<],0-7:constr(pos=2:'Der','<>opennlp/c=NP')))!,
-   'Stringification');
-
-# Meta definition with facets
-$koral->meta(
-  $koral->meta_builder->facets('author')->start_index(2)->field_sort_asc_by('author')
-);
-
-is($koral->prepare_for($index)->to_string,
-   q!resultLimit([2-]:resultSorted(['author'<,'id'<]:aggregate([facet:'author']:constr(pos=2:'Der','<>opennlp/c=NP'))))!,
-   'Stringification');
-
-# Meta definition with facets (different order)
-$koral->meta(
-  $koral->meta_builder->start_index(2)->facets('author')->field_sort_asc_by('author')
-);
-
-is($koral->prepare_for($index)->to_string,
-   q!resultLimit([2-]:resultSorted(['author'<,'id'<]:aggregate([facet:'author']:constr(pos=2:'Der','<>opennlp/c=NP'))))!,
-   'Stringification');
-
-
-# Meta definition with count
-$koral->meta(
-  $koral->meta_builder->count(1)
-);
-
-is($koral->prepare_for($index)->to_string,
-   q!resultSorted(['id'<]:aggregate([count]:constr(pos=2:'Der','<>opennlp/c=NP')))!,
-   'Stringification');
-
-
-# Meta definition with length
-$koral->meta(
-  $koral->meta_builder->length(1)
-);
-
-is($koral->prepare_for($index)->to_string,
-   q!resultSorted(['id'<]:aggregate([length]:constr(pos=2:'Der','<>opennlp/c=NP')))!,
-   'Stringification');
-
-
-done_testing;
-__END__
diff --git a/t/result/segment/aggregate_facets.t b/t/result/segment/aggregate_fields.t
similarity index 87%
rename from t/result/segment/aggregate_facets.t
rename to t/result/segment/aggregate_fields.t
index 679a39a..29ced0d 100644
--- a/t/result/segment/aggregate_facets.t
+++ b/t/result/segment/aggregate_fields.t
@@ -50,20 +50,20 @@
 
 $koral->meta(
   $mb->aggregate(
-    $mb->a_facets('genre'),
-    $mb->a_facets('age')
+    $mb->a_fields('genre'),
+    $mb->a_fields('age')
   )
 );
 
 is($koral->to_string,
-   "meta=[aggr=[facets:['genre'],facets:['age']]],query=[[aa]]",
+   "meta=[aggr=[fields:['genre'],fields:['age']]],query=[[aa]]",
    'Stringification');
 
 ok(my $koral_query = $koral->to_query, 'Normalization');
 
 # This is a query that is fine to be send to nodes
 is($koral_query->to_string,
-   "aggr(facets:['genre','age']:filter(aa,[1]))",
+   "aggr(fields:['genre','age']:filter(aa,[1]))",
    'Stringification');
 
 # This is a query that is fine to be send to segments:
@@ -72,13 +72,13 @@
 
 # This is a query that is fine to be send to nodes
 is($koral_query->to_string,
-   "aggr(facets:[#1,#5]:filter(#10,[1]))",
+   "aggr(fields:[#1,#5]:filter(#10,[1]))",
    'Stringification');
 
 ok(my $query = $koral_query->optimize($index->segment),
    'Queryfication');
 
-is($query->to_string, 'aggr([facets:#1,#5]:filter(#10,[1]))', 'Stringification');
+is($query->to_string, 'aggr([fields:#1,#5]:filter(#10,[1]))', 'Stringification');
 
 ok($query->next, 'Next');
 ok($query->next, 'Next');
@@ -90,7 +90,7 @@
 # TODO:
 #   This API is only temporarily implemented
 ok(my $coll = $query->collection->{fields}->inflate($index->dict), 'To terms');
-is($coll->to_string, 'facets=age:3[1,1],4[2,3],7[1,1];genre:newsletter[2,3],novel[2,2]');
+is($coll->to_string, 'fields=age:3[1,1],4[2,3],7[1,1];genre:newsletter[2,3],novel[2,2]');
 
 diag 'check for multivalued fields';