2 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
7 use PublicInbox::InboxWritable;
8 require_mods(qw(Search::Xapian DBD::SQLite));
9 use_ok 'PublicInbox::MiscSearch';
10 use_ok 'PublicInbox::MiscIdx';
12 my ($tmp, $for_destroy) = tmpdir();
13 my $eidx = { xpfx => "$tmp/eidx", -no_fsync => 1 }; # mock ExtSearchIdx
15 mkdir "$tmp/v1" or BAIL_OUT "mkdir $!";
16 open my $fh, '>', "$tmp/v1/description" or BAIL_OUT "open: $!";
17 print $fh "Everything sucks this year\n" or BAIL_OUT "print $!";
18 close $fh or BAIL_OUT "close $!";
21 my $v1 = PublicInbox::InboxWritable->new({
22 inboxdir => "$tmp/v1",
24 address => [ 'nope@example.com' ],
25 indexlevel => 'basic',
29 my $mi = PublicInbox::MiscIdx->new($eidx);
34 my $ms = PublicInbox::MiscSearch->new("$tmp/eidx/misc");
35 my $mset = $ms->mset('"everything sucks today"');
36 is(scalar($mset->items), 0, 'no match on description phrase');
38 $mset = $ms->mset('"everything sucks this year"');
39 is(scalar($mset->items), 1, 'match phrase on description');
41 $mset = $ms->mset('everything sucks');
42 is(scalar($mset->items), 1, 'match words in description');
44 $mset = $ms->mset('nope@example.com');
45 is(scalar($mset->items), 1, 'match full address');
47 $mset = $ms->mset('nope');
48 is(scalar($mset->items), 1, 'match partial address');
50 $mset = $ms->mset('hope');
51 is(scalar($mset->items), 1, 'match name');
52 my $mi = ($mset->items)[0];
53 my $doc = $mi->get_document;
54 is($doc->get_data, '{}', 'stored empty data');