Skip to content

Commit

Permalink
Add route for RSS feed of search results #114
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed May 19, 2017
1 parent 88d1d27 commit 3ab297a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/searchcode/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ public static void main(String[] args) {
return new JsonTransformer().render(searchRouteService.codeSearch(request, response));
});

get("/codesearch/rss/", (request, response) -> {
addXmlHeaders(response);
SearchRouteService searchRouteService = new SearchRouteService();
Map<String, Object> map = new HashMap<>();
map.put("result", searchRouteService.codeSearch(request, response));
return new FreeMarkerEngine().render(new ModelAndView(map, "codesearchrss.ftl"));
});

get("/timecodesearch/", (request, response) -> {
addJsonHeaders(response);
TimeSearchRouteService ars = new TimeSearchRouteService();
Expand Down Expand Up @@ -435,6 +443,11 @@ private static void addJsonHeaders(Response response) {
response.header("Content-Type", "application/json");
}

private static void addXmlHeaders(Response response) {
response.header("Content-Encoding", "gzip");
response.header("Content-Type", "application/rss+xml; charset=UTF-8");
}

private static void addAuthenticatedUser(Request request) {
request.session().attribute(Values.USERSESSIONID, true);
}
Expand Down
30 changes: 30 additions & 0 deletions src/main/resources/spark/template/freemarker/codesearchrss.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Search for "${result.query}"</title>
<link>https://searchcode.com/</link>
<description>Search for "${result.query}"</description>
<#list result.codeResultList>
<#items as result>
<item>
<title>${result.fileName} in ${result.repoName}</title>
<link>https:/searchcode.com/file/${result.codeId}/${result.codePath}</link>
<guid>https:/searchcode.com/file/${result.codeId}/${result.codePath}</guid>
<description>
&lt;ol class="code-result"&gt;
<#list result.matchingResults>
<#items as line>
&lt;li value="${line.lineNumber?c}"&gt;
&lt;a href="https:/searchcode.com/file/${result.documentId?c}/${result.codePath}#${line.lineNumber?c}"&gt;
&lt;pre&gt;${line.line?html}&lt;/pre&gt;
&lt;/a&gt;
&lt;/li&gt;
</#items>
</#list>
&lt;/ol&gt;
</description>
</item>
</#items>
</#list>
</channel>
</rss>

0 comments on commit 3ab297a

Please sign in to comment.