blob: 2ad88c628a5136dd6a9d6c86ab9a106833d20597 [file] [log] [blame]
Akrona1fbdeb2016-12-12 02:06:08 +01001use Test::More;
2use Test::Krawfish;
3use strict;
4use warnings;
5
6use_ok('Krawfish::Index');
Akronc1ed58c2017-08-04 17:26:30 +02007use_ok('Krawfish::Koral');
Akrona1fbdeb2016-12-12 02:06:08 +01008
9my $index = Krawfish::Index->new;
10ok_index($index, {
Akronc1ed58c2017-08-04 17:26:30 +020011 id => 'doc-1',
Akrona1fbdeb2016-12-12 02:06:08 +010012 license => 'free',
13 corpus => 'corpus-2'
Akronc001d362016-12-12 19:07:52 +010014} => [qw/aa bb aa bb/], 'Add new document');
Akrona1fbdeb2016-12-12 02:06:08 +010015
Akronc1ed58c2017-08-04 17:26:30 +020016my $koral = Krawfish::Koral->new;
17my $qb = $koral->query_builder;
18my $mb = $koral->meta_builder;
19
20$koral->query($qb->bool_or('aa', 'bb'));
21
22$koral->meta(
23 $mb->snippet
24);
25
26is($koral->to_string,
27 "meta=[snippet],query=[aa|bb]",
28 'Stringification');
29
30ok(my $koral_query = $koral->to_query, 'Normalization');
31
32# This is a query that is fine to be send to nodes
33is($koral_query->to_string,
34 "snippet(?:fields('id':sort(field='id'<;sortFilter:filter(aa|bb,[1]))))",
35 'Stringification');
36
37# This is a query that is fine to be send to segments:
38ok($koral_query = $koral_query->identify($index->dict), 'Identify');
39
40# This is a query that is fine to be send to nodes
41is($koral_query->to_string,
42 "snippet(?:fields(#4:sort(field=#4<;sortFilter:filter(#7|#8,[1]))))",
43 'Stringification');
44
45TODO: {
46 local $TODO = 'Test further - with matches'
47};
48
49
50
51done_testing;
52__END__
Akrona1fbdeb2016-12-12 02:06:08 +010053
54is($query->to_string, 'aa|bb', 'Stringification');
55
Akronc4bf5fb2017-07-18 02:20:40 +020056my $prepare = $query->normalize->finalize->optimize($index);
Akrona1fbdeb2016-12-12 02:06:08 +010057
58is($prepare->to_string, "or('aa','bb')", 'Stringification');
59
60# Get facets object
Akronc8e9ad12017-07-28 15:17:14 +020061ok(my $snippet = Krawfish::Result::Segment::Enrich::Snippet->new(
Akronc001d362016-12-12 19:07:52 +010062 query => $prepare,
63 index => $index
Akrona1fbdeb2016-12-12 02:06:08 +010064), 'Create count object');
65
66ok($snippet->next, 'Next match');
Akron7c62cc42016-12-28 19:24:35 +010067is($snippet->current_match->to_string, "[0:0-1|snippet='aa bb aa bb']", 'Current match');
Akrona1fbdeb2016-12-12 02:06:08 +010068ok($snippet->next, 'Next match');
Akron7c62cc42016-12-28 19:24:35 +010069is($snippet->current_match->to_string, "[0:1-2|snippet='aa bb aa bb']", 'Current match');
Akrona1fbdeb2016-12-12 02:06:08 +010070ok($snippet->next, 'Next match');
Akron7c62cc42016-12-28 19:24:35 +010071is($snippet->current_match->to_string, "[0:2-3|snippet='aa bb aa bb']", 'Current match');
Akrona1fbdeb2016-12-12 02:06:08 +010072ok($snippet->next, 'Next match');
Akron7c62cc42016-12-28 19:24:35 +010073is($snippet->current_match->to_string, "[0:3-4|snippet='aa bb aa bb']", 'Current match');
Akrona1fbdeb2016-12-12 02:06:08 +010074ok(!$snippet->next, 'No more match');
75
Akrona1fbdeb2016-12-12 02:06:08 +010076
77done_testing;
78
79__END__
80
81