diff options
author | Eric Wong <e@80x24.org> | 2015-08-25 02:03:16 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-08-25 03:52:54 +0000 |
commit | 73214b02e581ef0a037d85a1ae37ff425654d7b3 (patch) | |
tree | fee5c604b688369e877b1294543701bb2c29b4b4 /lib/PublicInbox/Search.pm | |
parent | 42359e39a591dcf68ce02a5fc2dd703ba68f0f77 (diff) | |
download | public-inbox-73214b02e581ef0a037d85a1ae37ff425654d7b3.tar.gz |
We ought to summarize subjects to avoid exploding line lengths in the web interface.
Diffstat (limited to 'lib/PublicInbox/Search.pm')
-rw-r--r-- | lib/PublicInbox/Search.pm | 25 |
1 files changed, 25 insertions, 0 deletions
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}); |