- <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
- <%@ page session="false"%>
- <%@page import="org.apache.solr.client.solrj.response.QueryResponse"%>
- <%@page import="org.apache.solr.client.solrj.response.FacetField"%>
- <%@page import="org.apache.solr.client.solrj.response.FacetField.Count"%>
- <%@page import="org.apache.solr.common.util.NamedList"%>
- <%@page import="org.apache.solr.common.SolrDocument"%>
- <%@page import="org.apache.commons.lang.StringUtils" %>
- <%@page import="org.apache.commons.lang.StringEscapeUtils" %>
- <%@page import="java.util.List"%>
- <%@page import="java.util.Map"%>
-
- <%@page import="solrbook.client.util.SearchUtil"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <link media="screen" href="./style.css" type="text/css" rel="stylesheet" />
- <%
- QueryResponse rsp = (QueryResponse)request.getAttribute("rsp");
- String query = (String)request.getAttribute("query");
- String startStr = (String)request.getAttribute("start");
- String[] fq = (String[])request.getAttribute("fq");
- if(query == null){
- query ="";
- }
- long found = 0;
- long start = 0;
- int rows = 10;
- int qtime = 0;
- if(rsp != null){
- qtime = rsp.getQTime();
-
- //start = rsp.getResults().getStart();
- if (startStr != null) {
- try {
- start = Long.parseLong(startStr);
- }
- catch (NumberFormatException nfe) {
- start = 0;
- }
- }
-
- String rowsStr = (String)((NamedList)rsp.getResponseHeader().get("params")).get("rows");
- try {
- rows = Integer.parseInt(rowsStr);
- }
- catch (NumberFormatException nfe) {}
- found = rsp.getResults().getNumFound();
- }
-
- if (!StringUtils.isEmpty(query)) {
- %>
- <title><%= StringEscapeUtils.escapeHtml(query) %>の検索結果</title>
- <%
- }
- else {
- %>
- <title>OSM Talk-ja 検索</title>
- <%
- }
- %>
-
- </head>
- <body onload="document.f1.query.focus();">
- <div id="wrap">
- <div id="header">
- <h1><a href="#">OSM Talk-ja 検索</a></h1>
- <br/>
- <form name="f1" action="index.html">
- <input type="text" name="query" value="<%= StringEscapeUtils.escapeHtml(query) %>"/>
- <input value="検索" type="submit"/>
- </form>
- </div>
-
- <!-- %@include file="_result_header.jsp" % -->
- <div id="result_header">
- <%
- if (!StringUtils.isEmpty(query)) {
- %>
- <b><%= StringEscapeUtils.escapeHtml(query) %></b> の検索結果
- <%
- }
- if (found > 0) {
- %>
- <b><%= found %></b> 件中
- <b><%= start+1 %></b> -
- <b><%= start+rows > found ? found : start+rows %></b> 件目
- <%
- }
- else {
- %>
- <b>0</b> 件
- <%
- }
- %>
- ( <%= qtime/1000 %> 秒 )
- </div>
-
- <div id="content">
- <%
- if (rsp != null) {
- if (found == 0) {
- %>
- <b><%= StringEscapeUtils.escapeHtml(query) %></b> は見つかりませんでした。他の検索語で試してください。
- <%
- }
- else {
- %>
- <div id="result" class="right">
- <%
- for (SolrDocument document : rsp.getResults()) {
- String info = "";
- if(document.getFirstValue("id") != null){
- info += document.getFirstValue("id");
- }
- if(document.getFirstValue("date") != null){
- if(info.length() > 0){
- info += " | ";
- }
- info += document.getFirstValue("date");
- }
- if(document.getFirstValue("name") != null){
- if(info.length() > 0){
- info += " | ";
- }
- info += document.getFirstValue("name");
- }
-
- String titleStr = "";
- if (document.getFirstValue("title") != null) {
- titleStr = (String)document.getFirstValue("title");
- }
- %>
- <h2><a href="<%= document.getFieldValue("url") %>"><img src="IconTarget.png"/><%= StringEscapeUtils.escapeHtml(titleStr) %></a></h2>
- <h3><%= info %></h3>
-
- <%
- if(!StringUtils.isEmpty(query)){
- String contents = "";
- boolean first = true;
- if (document.getFieldValues("contents") != null){
- int i = 10;
- for (Object line : document.getFieldValues("contents")) {
- i--;
- if (i < 0) {
- break;
- }
- String str = line.toString();
- if ((str != null) && (str.trim().length() > 0)) {
- if (!first) {
- contents += " / ";
- }
- else {
- first = false;
- }
- contents += line.toString();
- }
- }
- }
- %>
- <div class="articles"><i><%= StringEscapeUtils.escapeHtml(contents) %></i></div>
- <%
- }
- %>
-
- <%
- String summary = "";
- Map<String, List<String>> highlighting = rsp.getHighlighting().get(document.getFirstValue("url"));
- boolean first = true;
- for (String field : SearchUtil.getSummaryHighlightFields()){
- if (highlighting.get(field) != null){
- for (String text : highlighting.get(field)){
- if (!first) {
- summary += "...";
- }
- else {
- first = false;
- }
- summary += text;
- }
- }
- }
- %>
- <div class="articles"><%= summary %></div>
- <br/>
- <hr/>
- <%
- }
- }
- %>
- </div><!-- end of #result -->
-
- <div id="facet" class="left">
- <%-- facet fields --%>
- <%
- //for (FacetField facetField : rsp.getFacetFields()) {
- %>
- <!-- %@include file="_facet_field.jsp"% -->
- <%
- //}
- %>
-
- <%-- facet queries --%>
- <!-- % for(String queryLabelName : SearchUtil.getFacetQueries().keySet()){ % -->
- <!-- %@include file="_facet_queries.jsp"% -->
- <!-- % } % -->
- </div><!-- end of #facet -->
- <%
- }
- %>
-
- </div><!-- end of #content -->
-
- <div style="CLEAR: both"></div>
-
-
- <div id="page">
- <%
- String p_head = "|<<先頭ページへ";
- String p_prev = "<前へ";
- String p_next = "次へ>";
- String p_tail = "末尾ページへ>>|";
-
- int wsiz = 10;
- int w1 = 5;
- int w2 = 5;
-
- int pcnt = (int)(found / rows + ( ( found % rows ) == 0 ? 0 : 1 ));
- int cpag = (int)(start / rows + 1);
- int wbgn = cpag - w1;
- int wend = cpag + w2;
- if( wbgn < 1 ){
- wbgn = 1;
- wend = wbgn + wsiz;
- if( wend > pcnt + 1 ){
- wend = pcnt + 1;
- }
- }
- if( wend > pcnt + 1 ){
- wend = pcnt + 1;
- wbgn = wend - wsiz;
- if( wbgn < 1 ){
- wbgn = 1;
- }
- }
- %>
- <%
- if( pcnt > 1 ) {
- %>
- <strong>Page</strong>
- <%
- if( cpag > 1 ) {
- %>
- <a href="./index.html<%=SearchUtil.getLinkStr(query,fq, null, 0)%>"><%=p_head%></a>
- <a href="./index.html<%=SearchUtil.getLinkStr(query,fq, null, ((cpag-2)*rows))%>"><%=p_prev%></a>
- <%
- }
- %>
-
- <%
- for(int i=wbgn;i<wend;i++) {
- %>
- <%
- if(cpag == i) {
- %>
- <%= i %>
- <%
- }
- else {
- %>
- <a href="./index.html<%=SearchUtil.getLinkStr(query,fq, null, ((i-1)*rows))%>"><%=i %></a>
- <%
- }
- }
- %>
-
- <%
- if ( cpag < pcnt ) {
- %>
- <a href="./index.html<%=SearchUtil.getLinkStr(query,fq, null, (cpag*rows))%>"><%=p_next%></a>
- <a href="./index.html<%=SearchUtil.getLinkStr(query,fq, null, ((pcnt-1)*rows))%>"><%=p_tail%></a>
- <%
- }
- }
- %>
- </div>
-
- <div id="footer">powered by Apache Solr4.</div>
-
- </div><!-- end of #wrap -->
- </body>
- </html>