From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/3] searchview: implement Atom feed for search results
Date: Sun, 13 Sep 2015 22:35:46 +0000 [thread overview]
Message-ID: <20150913223547.5083-2-e@80x24.org> (raw)
In-Reply-To: <20150913223547.5083-1-e@80x24.org>
This can be helpful for folks who want to subscribe
to a particular topic or keyword.
---
lib/PublicInbox/Feed.pm | 6 +++---
lib/PublicInbox/SearchView.pm | 42 +++++++++++++++++++++++++++++++++---------
2 files changed, 36 insertions(+), 12 deletions(-)
diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 5a2f62b..85c598e 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -74,7 +74,7 @@ sub emit_atom {
add_to_feed($feed_opts, $fh, $path, $git);
});
$git = undef; # destroy pipes
- _end_feed($fh);
+ end_feed($fh);
}
sub _no_thread {
@@ -84,7 +84,7 @@ sub _no_thread {
$fh->close;
}
-sub _end_feed {
+sub end_feed {
my ($fh) = @_;
Email::Address->purge_cache;
$fh->write('</feed>');
@@ -108,7 +108,7 @@ sub emit_atom_thread {
add_to_feed($feed_opts, $fh, mid2path($msg->mid), $git);
}
$git = undef; # destroy pipes
- _end_feed($fh);
+ end_feed($fh);
}
sub emit_html_index {
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index c15a046..b65351a 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -30,7 +30,7 @@ sub sres_top_html {
$total = $mset->get_matches_estimated;
};
my $err = $@;
- my $res = html_start($q) . PublicInbox::View::PRE_WRAP;
+ my $res = html_start($q, $ctx) . PublicInbox::View::PRE_WRAP;
if ($err) {
$code = 400;
$res .= err_txt($err) . "</pre><hr /><pre>" . foot($ctx);
@@ -39,8 +39,7 @@ sub sres_top_html {
$res .= "\n\n[No results found]</pre><hr /><pre>".foot($ctx);
} else {
my $x = $q->{x};
- # TODO
- #return sub { adump($_[0], $mset, $q, $ctx) } if ($x eq 'A');
+ return sub { adump($_[0], $mset, $q, $ctx) } if ($x eq 'A');
$res .= search_nav_top($mset, $q);
if ($x eq 't') {
@@ -109,8 +108,8 @@ sub search_nav_top {
$rv .= qq{<a\nhref="?$s">summary</a>|};
$rv .= qq{<b>threaded</b>};
}
- # my $A = $q->qs_html(x => 'a');
- # $rv .= qq{|<a\nhref="?$A">Atom</a>}; # TODO
+ my $A = $q->qs_html(x => 'A');
+ $rv .= qq{|<a\nhref="?$A">Atom</a>};
$rv .= ']';
}
@@ -213,13 +212,16 @@ sub foot {
}
sub html_start {
- my ($q) = @_;
+ my ($q, $ctx) = @_;
my $query = PublicInbox::Hval->new_oneline($q->{q});
my $qh = $query->as_html;
- my $res = "<html><head><title>$qh - search results</title></head>" .
- qq{<body><form\naction="">} .
- qq{<input\nname=q\nvalue="$qh"\ntype=text />};
+ my $A = $q->qs_html(x => 'A');
+ my $res = "<html><head><title>$qh - search results</title>" .
+ qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
+ qq!href="?$A"\ntype="application/atom+xml"/></head>! .
+ qq{<body><form\naction="">} .
+ qq{<input\nname=q\nvalue="$qh"\ntype=text />};
$res .= qq{<input\ntype=hidden\nname=r />} if $q->{r};
if (my $x = $q->{x}) {
@@ -230,6 +232,28 @@ sub html_start {
$res .= qq{<input\ntype=submit\nvalue=search /></form>};
}
+sub adump {
+ my ($cb, $mset, $q, $ctx) = @_;
+ my $fh = $cb->([ 200, ['Content-Type' => 'application/atom+xml']]);
+ require PublicInbox::GitCatFile;
+ my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
+ my $feed_opts = PublicInbox::Feed::get_feedopts($ctx);
+ my $x = PublicInbox::Hval->new_oneline($q->{q})->as_html;
+ $x = qq{$x - search results};
+ $feed_opts->{atomurl} = $feed_opts->{url} . '?'. $q->qs_html;
+ $feed_opts->{url} .= '?'. $q->qs_html(x => undef);
+ $x = PublicInbox::Feed::atom_header($feed_opts, $x);
+ $fh->write($x. PublicInbox::Feed::feed_updated());
+
+ for ($mset->items) {
+ $x = PublicInbox::SearchMsg->load_doc($_->get_document)->mid;
+ $x = mid2path($x);
+ PublicInbox::Feed::add_to_feed($feed_opts, $fh, $x, $git);
+ }
+ $git = undef;
+ PublicInbox::Feed::end_feed($fh);
+}
+
package PublicInbox::SearchQuery;
use strict;
use warnings;
--
EW
next prev parent reply other threads:[~2015-09-13 22:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-13 22:35 [PATCH 1/3] feed: consolidate updated tag generation Eric Wong
2015-09-13 22:35 ` Eric Wong [this message]
2015-09-13 22:35 ` [PATCH 3/3] view: add Atom links in headers for per-message links Eric Wong
2015-09-13 22:37 ` [PATCH 0/3] expand Atom feeds to search results Eric Wong
2015-09-13 23:19 ` [REJECT 4/3] searchview: implement flat view for full message Eric Wong
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: https://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=20150913223547.5083-2-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).