From 73214b02e581ef0a037d85a1ae37ff425654d7b3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 25 Aug 2015 02:03:16 +0000 Subject: search: implement subject summarization We ought to summarize subjects to avoid exploding line lengths in the web interface. --- lib/PublicInbox/Search.pm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib/PublicInbox/Search.pm') diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index bcc53125..5ef380e8 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -237,6 +237,31 @@ sub subject_normalized { $subj; } +# for doc data +sub subject_summary { + my $subj = pop; + my $max = 68; + if (length($subj) > $max) { + my @subj = split(/\s+/, $subj); + $subj = ''; + my $l; + + while ($l = shift @subj) { + my $new = $subj . $l . ' '; + last if length($new) >= $max; + $subj = $new; + } + if (length $subj) { + my $r = scalar @subj ? ' ...' : ''; + $subj =~ s/ \z/$r/s; + } else { + @subj = ($l =~ /\A(.{1,72})/); + $subj = $subj[0] . ' ...'; + } + } + $subj; +} + sub enquire { my ($self) = @_; $self->{enquire} ||= Search::Xapian::Enquire->new($self->{xdb}); -- cgit v1.2.3-24-ge0c7