user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/2] view: show percentage in search results thread skeleton
Date: Thu, 19 Dec 2019 05:18:01 +0000	[thread overview]
Message-ID: <20191219051801.31310-3-e@80x24.org> (raw)
In-Reply-To: <20191219051801.31310-1-e@80x24.org>

The displays the Xapian ->get_percent value in the skeleton to
improve scanning of relevancy; irrelevant results do not display
that.

This fixes broken #anchor links introduced in the previous
commit, irrelevant messages now link to the /$INBOX/$MESSAGE_ID page.
---
 lib/PublicInbox/View.pm | 20 +++++++++++++++-----
 t/psgi_v2.t             |  2 +-
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 33f71990..5924a2a7 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -950,7 +950,18 @@ sub skel_dump {
 	my $obfs_ibx = $ctx->{-obfs_ibx};
 	obfuscate_addrs($obfs_ibx, $f) if $obfs_ibx;
 
-	my $d = fmt_ts($smsg->{ds}) . ' ' . indent_for($level) . th_pfx($level);
+	my $d = fmt_ts($smsg->{ds});
+	my $unmatched; # if lazy-loaded by SearchThread::Msg::visible()
+	if (my $pct = $ctx->{pct}) {
+		$pct = $pct->{$smsg->{mid}};
+		if (defined $pct) {
+			$d .= (sprintf(' % 3u', $pct) . '%');
+		} else {
+			$unmatched = 1;
+			$d .= '     ';
+		}
+	}
+	$d .= ' ' . indent_for($level) . th_pfx($level);
 	my $attr = $f;
 	$ctx->{first_level} ||= $level;
 
@@ -976,7 +987,6 @@ sub skel_dump {
 	# our Xapian which would've resulted in '' if it were
 	# really missing (and Filter rejects empty subjects)
 	my @subj = split(/ /, subject_normalized($smsg->subject));
-
 	# remove common suffixes from the subject if it matches the previous,
 	# so we do not show redundant text at the end.
 	my $prev_subj = $ctx->{prev_subj} || [];
@@ -993,7 +1003,7 @@ sub skel_dump {
 	}
 	my $m;
 	my $id = '';
-	my $mapping = $ctx->{mapping};
+	my $mapping = $unmatched ? undef : $ctx->{mapping};
 	if ($mapping) {
 		my $map = $mapping->{$mid};
 		$id = id_compress($mid, 1);
@@ -1011,8 +1021,8 @@ sub _skel_ghost {
 	my ($ctx, $level, $node) = @_;
 
 	my $mid = $node->{id};
-	my $d = $ctx->{pct} ? '    [irrelevant] ' # search result
-			    : '     [not found] ';
+	my $d = '     [not found] ';
+	$d .= '     '  if exists $ctx->{pct};
 	$d .= indent_for($level) . th_pfx($level);
 	my $upfx = $ctx->{-upfx};
 	my $m = PublicInbox::Hval->new_msgid($mid);
diff --git a/t/psgi_v2.t b/t/psgi_v2.t
index 8e81e89b..10176516 100644
--- a/t/psgi_v2.t
+++ b/t/psgi_v2.t
@@ -155,7 +155,7 @@ test_psgi(sub { $www->call(@_) }, sub {
 	is($res->code, 200, 'success with threaded search');
 	my $raw = $res->content;
 	ok($raw =~ s/\A.*>Results 1-3 of 3\b//s, 'got all results');
-	my @over = ($raw =~ m/\d{4}-\d+-\d+\s+\d+:\d+ (.+)$/gm);
+	my @over = ($raw =~ m/\d{4}-\d+-\d+\s+\d+:\d+ +(?:\d+\% )?(.+)$/gm);
 	is_deeply(\@over, [ '<a', '` <a', '` <a' ], 'threaded messages show up');
 
 	local $SIG{__WARN__} = 'DEFAULT';

      parent reply	other threads:[~2019-12-19  5:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-19  5:17 [PATCH 0/2] improve "&x=t" search results Eric Wong
2019-12-19  5:18 ` [PATCH 1/2] searchthread: fix usage of user-supplied parameter Eric Wong
2019-12-19  5:18 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191219051801.31310-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).