%--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--%>
<%@ page
session="false"
contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
import="java.io.*"
import="java.util.*"
import="java.net.*"
import="org.apache.nutch.html.Entities"
import="org.apache.nutch.metadata.Nutch"
import="org.apache.nutch.searcher.*"
import="org.apache.nutch.plugin.*"
import="org.apache.nutch.clustering.*"
import="org.apache.hadoop.conf.*"
import="org.apache.nutch.util.NutchConfiguration"
%><%
Configuration nutchConf = NutchConfiguration.get(application);
/**
* Number of hits to retrieve and cluster if clustering extension is available
* and clustering is on. By default, 100. Configurable via nutch-conf.xml.
*/
int HITS_TO_CLUSTER =
nutchConf.getInt("extension.clustering.hits-to-cluster", 100);
/**
* An instance of the clustering extension, if available.
*/
OnlineClusterer clusterer = null;
try {
clusterer = new OnlineClustererFactory(nutchConf).getOnlineClusterer();
} catch (PluginRuntimeException e) {
// NOTE: Dawid Weiss
// should we ignore plugin exceptions, or rethrow it? Rethrowing
// it effectively prevents the servlet class from being loaded into
// the JVM
}
%>
<%--
// Uncomment this to enable query refinement.
// Do the same to "refine-query.jsp" below.,
<%@ include file="./refine-query-init.jsp" %>
--%>
<%
NutchBean bean = NutchBean.get(application, nutchConf);
// set the character encoding to use when interpreting request values
request.setCharacterEncoding("UTF-8");
bean.LOG.info("query request from " + request.getRemoteAddr());
// get query from request
String queryString = request.getParameter("query");
if (queryString == null)
queryString = "";
String htmlQueryString = Entities.encode(queryString);
// a flag to make the code cleaner a bit.
boolean clusteringAvailable = (clusterer != null);
String clustering = "";
if (clusteringAvailable && "yes".equals(request.getParameter("clustering")))
clustering = "yes";
int start = 0; // first hit to display
String startString = request.getParameter("start");
if (startString != null)
start = Integer.parseInt(startString);
int hitsPerPage = 10; // number of hits to display
String hitsString = request.getParameter("hitsPerPage");
if (hitsString != null)
hitsPerPage = Integer.parseInt(hitsString);
int hitsPerSite = 2; // max hits per site
String hitsPerSiteString = request.getParameter("hitsPerSite");
if (hitsPerSiteString != null)
hitsPerSite = Integer.parseInt(hitsPerSiteString);
String sort = request.getParameter("sort");
boolean reverse =
sort!=null && "true".equals(request.getParameter("reverse"));
String params = "&hitsPerPage="+hitsPerPage
+(sort==null ? "" : "&sort="+sort+(reverse?"&reverse=true":""));
int hitsToCluster = HITS_TO_CLUSTER; // number of hits to cluster
// get the lang from request
String queryLang = request.getParameter("lang");
if (queryLang == null) { queryLang = ""; }
Query query = Query.parse(queryString, queryLang, nutchConf);
bean.LOG.info("query: " + queryString);
bean.LOG.info("lang: " + queryLang);
String language =
ResourceBundle.getBundle("org.nutch.jsp.search", request.getLocale())
.getLocale().getLanguage();
String requestURI = HttpUtils.getRequestURL(request).toString();
String base = requestURI.substring(0, requestURI.lastIndexOf('/'));
String rss = "../opensearch?query="+htmlQueryString
+"&hitsPerSite="+hitsPerSite+"&lang="+queryLang+params;
%>
<%
// To prevent the character encoding declared with 'contentType' page
// directive from being overriden by JSTL (apache i18n), we freeze it
// by flushing the output buffer.
// see http://java.sun.com/developer/technicalArticles/Intl/MultilingualJSP/
out.flush();
%>
<%@ taglib uri="http://jakarta.apache.org/taglibs/i18n" prefix="i18n" %>
<% } %>
<%
for (int i = 0; i < length; i++) { // display the hits
Hit hit = show[i];
HitDetails detail = details[i];
String title = detail.getValue("title");
String url = detail.getValue("url");
String id = "idx=" + hit.getIndexNo() + "&id=" + hit.getIndexDocNo();
String summary = summaries[i].toHtml(true);
String caching = detail.getValue("cache");
boolean showSummary = true;
boolean showCached = true;
if (caching != null) {
showSummary = !caching.equals(Nutch.CACHING_FORBIDDEN_ALL);
showCached = !caching.equals(Nutch.CACHING_FORBIDDEN_NONE);
}
if (title == null || title.equals("")) { // use url for docs w/o title
title = url;
}
%>
<%=Entities.encode(title)%>
<%@ include file="more.jsp" %>
<% if (!"".equals(summary) && showSummary) { %>
<%=summary%> <% } %> <%=Entities.encode(url)%> <% if (showCached) { %>( <% } %> <% if (clustering.equals("yes") && length != 0) { %> |
<%@ include file="cluster.jsp" %> |
RSS |