]> Sergey Matveev's repositories - public-inbox.git/blob - t/miscsearch.t
www: drop --subject from "git send-email" instructions
[public-inbox.git] / t / miscsearch.t
1 #!perl -w
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>
4 use strict;
5 use v5.10.1;
6 use Test::More;
7 use PublicInbox::TestCommon;
8 require_mods(qw(Search::Xapian DBD::SQLite));
9 use_ok 'PublicInbox::MiscSearch';
10 use_ok 'PublicInbox::MiscIdx';
11
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 {
16         my ($im, $ibx) = @_;
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 $!";
20 };
21 my $midx = PublicInbox::MiscIdx->new($eidx);
22 $midx->index_ibx($v1);
23 $midx->commit_txn;
24 undef $v1;
25
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');
29
30 $mset = $ms->mset('"everything sucks this year"');
31 is(scalar($mset->items), 1, 'match phrase on description');
32
33 $mset = $ms->mset('everything sucks');
34 is(scalar($mset->items), 1, 'match words in description');
35
36 $mset = $ms->mset('nope@example.com');
37 is(scalar($mset->items), 1, 'match full address');
38
39 $mset = $ms->mset('nope');
40 is(scalar($mset->items), 1, 'match partial address');
41
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');
47
48 done_testing;