comparison src/global/web/tools/Search.jtp @ 0:7ecd1a4ef557

add content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 Mar 2019 19:15:52 -0600
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:7ecd1a4ef557
1 <%
2 package global.web.tools;
3
4 import java.io.IOException;
5 import java.io.PrintWriter;
6 import javax.servlet.http.HttpServlet;
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
11 import org.apache.lucene.queryParser.QueryParser;
12 import org.apache.lucene.queryParser.ParseException;
13 import org.apache.lucene.search.IndexSearcher;
14 import org.apache.lucene.search.Query;
15 import org.apache.lucene.search.TopDocs;
16 import org.apache.lucene.search.ScoreDoc;
17 import org.apache.lucene.util.Version;
18 import nabble.view.lib.Jtp;
19 import global.Site;
20
21
22 public final class Search extends HttpServlet {
23 private static final Logger logger = LoggerFactory.getLogger(Search.class);
24
25 protected void service(HttpServletRequest request,HttpServletResponse response)
26 throws IOException
27 {
28 PrintWriter out = response.getWriter();
29 String query = request.getParameter("query");
30 IndexSearcher searcher;
31 Query q;
32 TopDocs hits;
33 try {
34 searcher = new IndexSearcher(Site.dir());
35 QueryParser parser = new QueryParser(Version.LUCENE_CURRENT,Site.SUBJECT_FLD,Site.analyzer);
36 parser.setDefaultOperator(QueryParser.AND_OPERATOR);
37 q = parser.parse(query);
38 hits = searcher.search(q,100);
39 } catch(IOException e) {
40 throw new RuntimeException(e);
41 } catch(ParseException e) {
42 throw new RuntimeException(e);
43 }
44 try {
45 %>
46 <html>
47 <head>
48 <title>Nabble Search Result</title>
49 </head>
50 <body>
51 <h1>Nabble Search for: <%=q%></h1>
52 <h3>showing <%=hits.scoreDocs.length%> out of <%=hits.totalHits%> results</h3>
53 <%
54 for( ScoreDoc sd : hits.scoreDocs ) {
55 Site site = new Site( searcher.doc(sd.doc) );
56 %>
57 <p><%=site.link()%></p>
58 <%
59 }
60 %>
61 </body>
62 </html>
63 <%
64 } finally {
65 searcher.close();
66 }
67 }
68
69 }
70 %>