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>
7 use PublicInbox::TestCommon;
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
14 my $v1 = create_inbox 'hope', address => [ 'nope@example.com' ],
15 indexlevel => 'basic', -no_gc => 1, sub {
17 open my $fh, '>', "$ibx->{inboxdir}/description" or BAIL_OUT "open: $!";
18 print $fh "Everything sucks this year\n" or BAIL_OUT "print $!";
19 close $fh or BAIL_OUT "close $!";
21 my $midx = PublicInbox::MiscIdx->new($eidx);
22 $midx->index_ibx($v1);
26 my $ms = PublicInbox::MiscSearch->new("$tmp/eidx/misc");
27 my $mset = $ms->mset('"everything sucks today"');
28 is(scalar($mset->items), 0, 'no match on description phrase');
30 $mset = $ms->mset('"everything sucks this year"');
31 is(scalar($mset->items), 1, 'match phrase on description');
33 $mset = $ms->mset('everything sucks');
34 is(scalar($mset->items), 1, 'match words in description');
36 $mset = $ms->mset('nope@example.com');
37 is(scalar($mset->items), 1, 'match full address');
39 $mset = $ms->mset('nope');
40 is(scalar($mset->items), 1, 'match partial address');
42 $mset = $ms->mset('hope');
43 is(scalar($mset->items), 1, 'match name');
44 my $mi = ($mset->items)[0];
45 my $doc = $mi->get_document;
46 is($doc->get_data, '{}', 'stored empty data');