]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/search.t
v1: remove articles from overview DB
[public-inbox.git] / t / search.t
index 2f7b795ed8ea89bc0106c401d92a5f9f49c7d870..48c2511c80723be2712e92ec9d1dc1c1fd749795 100644 (file)
@@ -89,10 +89,9 @@ sub filter_mids {
 {
        $rw_commit->();
        $ro->reopen;
-       my $found = $ro->first_smsg_by_mid('root@s');
-       ok($found, "message found");
-       is($root_id, $found->{doc_id}, 'doc_id set correctly');
-       is($found->mid, 'root@s', 'mid set correctly');
+       my $found = $ro->query('m:root@s');
+       is(scalar(@$found), 1, "message found");
+       is($found->[0]->mid, 'root@s', 'mid set correctly');
 
        my ($res, @res);
        my @exp = sort qw(root@s last@s);
@@ -276,10 +275,9 @@ sub filter_mids {
                ],
                body => "LOOP!\n"));
        ok($doc_id > 0, "doc_id defined with circular reference");
-       my $smsg = $rw->first_smsg_by_mid('circle@a');
+       my $smsg = $rw->query('m:circle@a', {limit=>1})->[0];
        is($smsg->references, '', "no references created");
-       my $msg = PublicInbox::SearchMsg->load_doc($smsg->{doc});
-       is($s, $msg->subject, 'long subject not rewritten');
+       is($s, $smsg->subject, 'long subject not rewritten');
 }
 
 {
@@ -293,9 +291,7 @@ sub filter_mids {
        my $mime = Email::MIME->new($str);
        my $doc_id = $rw->add_message($mime);
        ok($doc_id > 0, 'message indexed doc_id with UTF-8');
-       my $smsg = $rw->first_smsg_by_mid('testmessage@example.com');
-       my $msg = PublicInbox::SearchMsg->load_doc($smsg->{doc});
-
+       my $msg = $rw->query('m:testmessage@example.com', {limit => 1})->[0];
        is($mime->header('Subject'), $msg->subject, 'UTF-8 subject preserved');
 }
 
@@ -310,31 +306,33 @@ sub filter_mids {
 
 # names and addresses
 {
-       my $res = $ro->query('t:list@example.com');
-       is(scalar @$res, 6, 'searched To: successfully');
-       foreach my $smsg (@$res) {
+       my $mset = $ro->query('t:list@example.com', {mset => 1});
+       is($mset->size, 6, 'searched To: successfully');
+       foreach my $m ($mset->items) {
+               my $smsg = $ro->lookup_article($m->get_docid);
                like($smsg->to, qr/\blist\@example\.com\b/, 'to appears');
        }
 
-       $res = $ro->query('tc:list@example.com');
-       is(scalar @$res, 6, 'searched To+Cc: successfully');
-       foreach my $smsg (@$res) {
+       $mset = $ro->query('tc:list@example.com', {mset => 1});
+       is($mset->size, 6, 'searched To+Cc: successfully');
+       foreach my $m ($mset->items) {
+               my $smsg = $ro->lookup_article($m->get_docid);
                my $tocc = join("\n", $smsg->to, $smsg->cc);
                like($tocc, qr/\blist\@example\.com\b/, 'tocc appears');
        }
 
        foreach my $pfx ('tcf:', 'c:') {
-               $res = $ro->query($pfx . 'foo@example.com');
-               is(scalar @$res, 1,
-                       "searched $pfx successfully for Cc:");
-               foreach my $smsg (@$res) {
+               my $mset = $ro->query($pfx . 'foo@example.com', { mset => 1 });
+               is($mset->items, 1, "searched $pfx successfully for Cc:");
+               foreach my $m ($mset->items) {
+                       my $smsg = $ro->lookup_article($m->get_docid);
                        like($smsg->cc, qr/\bfoo\@example\.com\b/,
                                'cc appears');
                }
        }
 
        foreach my $pfx ('', 'tcf:', 'f:') {
-               $res = $ro->query($pfx . 'Laggy');
+               my $res = $ro->query($pfx . 'Laggy');
                is(scalar(@$res), 1,
                        "searched $pfx successfully for From:");
                foreach my $smsg (@$res) {
@@ -411,8 +409,15 @@ sub filter_mids {
        my $txt = $ro->query('"inside another"');
        is($txt->[0]->mid, $res->[0]->mid,
                'search inside text attachments works');
+
+       my $mid = $n->[0]->mid;
+       my ($id, $prev);
+       my $art = $ro->next_by_mid($mid, \$id, \$prev);
+       ok($art, 'article exists in OVER DB');
+       $rw->unindex_blob($amsg);
+       $rw->commit_txn_lazy;
+       is($ro->lookup_article($art->{num}), undef, 'gone from OVER DB');
 }
-$rw->commit_txn_lazy;
 
 done_testing();