diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f27dc3e --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +.classpath +.project +.externalToolBuilders/ +.settings/ +*.class +*.jar +*.zip +nbproject/ +build/ +dist/ diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..5f155c7 --- /dev/null +++ b/build.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + Builds, tests, and runs the project TalkjaSolr. + + + diff --git a/src/conf/MANIFEST.MF b/src/conf/MANIFEST.MF new file mode 100644 index 0000000..59499bc --- /dev/null +++ b/src/conf/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/src/java/solrbook/client/servlet/Client.java b/src/java/solrbook/client/servlet/Client.java new file mode 100644 index 0000000..041277e --- /dev/null +++ b/src/java/solrbook/client/servlet/Client.java @@ -0,0 +1,28 @@ +package solrbook.client.servlet; + +import org.apache.solr.client.solrj.SolrQuery; +import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.impl.HttpSolrServer; +import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.common.SolrDocument; +import org.apache.solr.common.SolrDocumentList; + +public class Client { + public static void main(String... args) throws Exception + { + final SolrServer solr = new HttpSolrServer("http://172.17.0.1:8983/solr/talkja"); + final SolrQuery solrQuery = new SolrQuery(); + solrQuery.set("q", ":"); + final QueryResponse response = solr.query(solrQuery); + final SolrDocumentList results = response.getResults(); + System.out.println(results.size()); + for (SolrDocument document : results) { + System.out.println(document.get("url")); + System.out.println(document.get("id")); + + System.out.println(document.get("title")); + System.out.println(document.get("name")); + + } + } +} diff --git a/src/java/solrbook/client/servlet/SearchServlet.java b/src/java/solrbook/client/servlet/SearchServlet.java new file mode 100644 index 0000000..a8ce105 --- /dev/null +++ b/src/java/solrbook/client/servlet/SearchServlet.java @@ -0,0 +1,173 @@ +/** + * + */ +package solrbook.client.servlet; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.apache.solr.client.solrj.SolrQuery; +import org.apache.solr.client.solrj.SolrServer; +import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.impl.HttpSolrServer; +import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.common.params.FacetParams; +import org.apache.solr.common.params.HighlightParams; + +import solrbook.client.util.SearchUtil; + +/** + * @author $Author$ + * + */ +public class SearchServlet extends HttpServlet { + + private SolrServer solrServer = null; + + /* + * (非 Javadoc) + * + * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig) + */ + @Override + public void init(ServletConfig config) throws ServletException { + super.init(config); + + solrServer = new HttpSolrServer("http://172.17.0.1:8983/solr/talkja"); + + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doGet(request, response); + } + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doService(request, response); + } + + @SuppressWarnings("CallToPrintStackTrace") + protected void doService( + HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + // 検索条件生成 + SolrQuery query = createSolrQuery(request); + + // 結果受け取り + QueryResponse rsp = null; + try { + rsp = solrServer.query(query); + } catch (SolrServerException sse) { + sse.printStackTrace(); + } + request.setAttribute("rsp", rsp); + + RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/jsp/search.jsp"); + rd.forward(request, response); + } + + private String getQueryString(HttpServletRequest request) { + String vStr = request.getParameter("query"); + String queryStr = null; + if (vStr != null) { + try { + queryStr = new String(vStr.getBytes("8859_1")); + } catch (UnsupportedEncodingException ex) { + Logger.getLogger(SearchServlet.class.getName()).log(Level.SEVERE, null, ex); + } + } + request.setAttribute("query", queryStr); + + if (StringUtils.isEmpty(queryStr)) { + queryStr = "*:*"; + } + + return queryStr; + } + + private String getPerFieldParameterName(String field, String paramName) { + return "f." + field + "." + paramName; + } + + private SolrQuery createSolrQuery(HttpServletRequest request) { + SolrQuery query = new SolrQuery(); + query.setRows(10); + + // fl(取得フィールドの指定) + //query.setFields(SearchUtil.getFields()); + + // ハイライト + query.setHighlight(true); + query.addHighlightField(SearchUtil.getTitleHighlightField()); + for (String field : SearchUtil.getSummaryHighlightFields()) { + query.addHighlightField(field); + } + query.setHighlightSnippets(1); + query.setHighlightSimplePre(""); + query.setHighlightSimplePost(""); + query.set(HighlightParams.USE_PHRASE_HIGHLIGHTER, true); + query.set(getPerFieldParameterName("title", HighlightParams.ALTERNATE_FIELD), "title"); + query.set(getPerFieldParameterName("contents", HighlightParams.ALTERNATE_FIELD), "contents"); + query.set(getPerFieldParameterName("contents", HighlightParams.ALTERNATE_FIELD_LENGTH), 1000); + + // ファセット + /* + query.setFacet(true); + query.setFacetLimit(20); + query.setFacetMinCount(1); + query.setFacetSort(FacetParams.FACET_SORT_COUNT); + // ファセットフィールド + for (String field : SearchUtil.getFacetLabels().keySet()) { + query.addFacetField(field); + } + for (String category : SearchUtil.getFacetQueries().keySet()) { + for (int i = 0; i < SearchUtil.getFacetQueries().get(category).length; i++) { + query.addFacetQuery(SearchUtil.getFacetQueries().get(category)[i][0]); + } + } + + */ + + // 検索語の設定 + String str = getQueryString(request); + if ((str != null) && str.trim().length() > 0) { + query.setQuery(str); + } + + // start(取得開始位置) + int start = 0; + String startStr = request.getParameter("start"); + if (!StringUtils.isEmpty(startStr)) { + try { + start = Integer.parseInt(startStr); + request.setAttribute("start", startStr); + } + catch (NumberFormatException nfe) {} + } + + // fq(絞り込み条件の取得) + /* + String[] filterQueries = request.getParameterValues("fq"); + if (filterQueries != null) { + query.addFilterQuery(filterQueries); + } + request.setAttribute("fq", filterQueries); + */ + + return query; + } +} diff --git a/src/java/solrbook/client/util/SearchUtil.java b/src/java/solrbook/client/util/SearchUtil.java new file mode 100644 index 0000000..53e5fba --- /dev/null +++ b/src/java/solrbook/client/util/SearchUtil.java @@ -0,0 +1,160 @@ +package solrbook.client.util; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.lang.StringUtils; + +/** + * @author $Author$ + * + */ +public class SearchUtil { + public static final String ENCODING = "UTF-8"; + + private static HashMap facetQueries; + + private static Map facetLabels; + + private static final String[] SUMMARY_HIGHLIGHT_FIELDS = { + "contents" + }; + + private static final String TITLE_HIGHLIGHT_FIELDS = "title"; + + private static final String[] FIELDS = { + "path", + "dir", + "url", + "id", + "title", + "name", + "date", + "contents" + }; + + /* + static { + facetQueries = new HashMap(); + String[][] yearsArr = { { "pub_date:[20090101 TO *]", "2009年以降" }, + + { "pub_date:[20080101 TO 20081231]", "2008年" }, + { "pub_date:[20070101 TO 20071231]", "2007年" }, + { "pub_date:[20060101 TO 20061231]", "2006年" }, + { "pub_date:[20050101 TO 20051231]", "2005年" }, + { "pub_date:[* TO 20041231]", "2004年以前" } }; + + //facetQueries.put("発売年", yearsArr); + + facetLabels = new HashMap(); + facetLabels.put("date", "投稿日時"); + facetLabels.put("author_facet", "著者"); + + } + */ + + /** + * @return summaryHighlightFields + */ + public static String[] getSummaryHighlightFields() { + return SUMMARY_HIGHLIGHT_FIELDS; + } + + /** + * @return titleHighlightField + */ + public static String getTitleHighlightField() { + return TITLE_HIGHLIGHT_FIELDS; + } + + /** + * @return fields + */ + public static String[] getFields() { + return FIELDS; + } + + public static HashMap getFacetQueries() { + return facetQueries; + } + + public static Map getFacetLabels() { + return facetLabels; + } + + public static String getFacetLabel(String fieldName) { + String label = facetLabels.get(fieldName); + if (label == null) + label = fieldName; + return label; + } + + public static String getLinkStr( + String query, + String[] filterQueries, + String filterValue, + int start) { + List link = new ArrayList<>(); + + if (!StringUtils.isEmpty(query)) { + link.add(getUrlEncodedParam("query", query)); + } + + if (filterQueries != null && filterQueries.length > 0) { + for (String fq : filterQueries) { + if (!StringUtils.isEmpty(fq)) { + link.add(getUrlEncodedParam("fq", fq)); + } + } + } + + if (!StringUtils.isEmpty(filterValue)) { + link.add(getUrlEncodedParam("fq", filterValue)); + } + + if (start > 0) { + link.add("start=" + start); + } + + String linkStr = ""; + for (int i = 0; i < link.size(); i++) { + if (i == 0) { + linkStr += "?"; + } else { + linkStr += "&"; + } + linkStr += link.get(i); + } + + return linkStr; + } + + private static String getUrlEncodedParam(String paramName, String value) { + String tmp = ""; + try { + tmp = paramName + "=" + URLEncoder.encode(value, ENCODING); + } catch (UnsupportedEncodingException uee) { + } + return tmp; + } + + /* + public static int getFacetQueryTotalCount( + String queryLabelName, + Map facetQueriesMap) { + int total = 0; + if (facetQueriesMap != null) { + String[][] queriesArray = SearchUtil.getFacetQueries().get(queryLabelName); + for (int i = 0; i < queriesArray.length; i++) { + if (facetQueriesMap.containsKey(queriesArray[i][0])) { + total += facetQueriesMap.get(queriesArray[i][0]).intValue(); + } + } + } + return total; + } + */ +} diff --git a/web/IconTarget.png b/web/IconTarget.png new file mode 100644 index 0000000..33b715c --- /dev/null +++ b/web/IconTarget.png Binary files differ diff --git a/web/META-INF/MANIFEST.MF b/web/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5f631a8 --- /dev/null +++ b/web/META-INF/MANIFEST.MF @@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +Ant-Version: Apache Ant 1.9.2 +Created-By: 1.7.0_45-b18 (Oracle Corporation) + diff --git a/web/WEB-INF/glassfish-web.xml b/web/WEB-INF/glassfish-web.xml new file mode 100644 index 0000000..13e0059 --- /dev/null +++ b/web/WEB-INF/glassfish-web.xml @@ -0,0 +1,10 @@ + + + + + + + Keep a copy of the generated servlet class' java code. + + + diff --git a/web/WEB-INF/jsp/_document.jsp b/web/WEB-INF/jsp/_document.jsp new file mode 100644 index 0000000..3f7f42c --- /dev/null +++ b/web/WEB-INF/jsp/_document.jsp @@ -0,0 +1,48 @@ +<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> +<% +Map> highlighting = rsp.getHighlighting().get(document.getFirstValue("url")); +String summary = ""; +String contents = ""; +boolean first = true; +if(document.getFieldValues("contents") != null){ + for(Object line : document.getFieldValues("contents")){ + if(!first){ + contents += ", "; + }else{ + first = false; + } + contents += line.toString(); + } +} + +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; + } + } +} +String info = ""; +if(document.getFirstValue("id") != null){ + info += "id:"+document.getFirstValue("id"); +} +if(document.getFirstValue("name") != null){ + if(info.length() > 0){ + info += " | "; + } + info += document.getFirstValue("name"); +} +%> +

"><%=highlighting.get("title").get(0) %>

+
<%=summary%>
+
+
<%=StringEscapeUtils.escapeHtml(contents)%>
+ +
<%=StringEscapeUtils.escapeHtml(info) %>
+
diff --git a/web/WEB-INF/jsp/_facet_field.jsp b/web/WEB-INF/jsp/_facet_field.jsp new file mode 100644 index 0000000..ab4cc72 --- /dev/null +++ b/web/WEB-INF/jsp/_facet_field.jsp @@ -0,0 +1,19 @@ +<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> +<% +if(facetField != null){ + List facetCountList = facetField.getValues(); +%> +

<%=SearchUtil.getFacetLabel(facetField.getName()) %>

+
+<% + if(facetCountList != null){ + for(Count count : facetCountList){ + String linkStr = SearchUtil.getLinkStr(query,fq, facetField.getName()+":"+count.getName(), 0); +%> +<%=StringEscapeUtils.escapeHtml(count.getName())%>(<%=count.getCount()%>)
+<% + } + } +} +%> +
diff --git a/web/WEB-INF/jsp/_facet_queries.jsp b/web/WEB-INF/jsp/_facet_queries.jsp new file mode 100644 index 0000000..3d4eb4c --- /dev/null +++ b/web/WEB-INF/jsp/_facet_queries.jsp @@ -0,0 +1,23 @@ +<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> +<% if(SearchUtil.getFacetQueryTotalCount(queryLabelName, rsp.getFacetQuery()) > 0){ %> +<% String[][] queriesArray = SearchUtil.getFacetQueries().get(queryLabelName); %> +

<%=queryLabelName %>

+
+<% +Map facetQueriesMap = rsp.getFacetQuery(); +if(facetQueriesMap != null){ + for(int i=0;i 0){ + String linkStr = SearchUtil.getLinkStr(query,fq, queriesArray[i][0], 0); + %> + <%=queriesArray[i][1]%>(<%=count%>)
+ <% + } + } + } + } +} +%> +
diff --git a/web/WEB-INF/jsp/_pagination.jsp b/web/WEB-INF/jsp/_pagination.jsp new file mode 100644 index 0000000..f142d6f --- /dev/null +++ b/web/WEB-INF/jsp/_pagination.jsp @@ -0,0 +1,52 @@ +<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> +
+<% +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 ){ %> +Page + <% if( cpag > 1 ){ %> + <%=p_head%>    + <%=p_prev%>    + <% } %> +   + <% for(int i=wbgn;i + <% if(cpag == i){ %> + <%=i %>    + <% }else{ %> + <%=i %>    + <% } %> + <% } %> +   + <% if( cpag < pcnt ){ %> + <%=p_next%>    + <%=p_tail%>    + <% } %> +<% } %> +
diff --git a/web/WEB-INF/jsp/_result_header.jsp b/web/WEB-INF/jsp/_result_header.jsp new file mode 100644 index 0000000..f78670f --- /dev/null +++ b/web/WEB-INF/jsp/_result_header.jsp @@ -0,0 +1,14 @@ +<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> +
+<%if(!StringUtils.isEmpty(query)){ %> + <%=StringEscapeUtils.escapeHtml(query)%> の検索結果    +<%} +if(found > 0){%> + <%=found%> 件中 + <%=start+1%> - + <%=start+rows > found ? found : start+rows%> 件目 +<%}else{ %> + 0 件 +<%} %> +( <%=qtime/1000%> 秒 ) +
diff --git a/web/WEB-INF/jsp/search.jsp b/web/WEB-INF/jsp/search.jsp new file mode 100644 index 0000000..e68510a --- /dev/null +++ b/web/WEB-INF/jsp/search.jsp @@ -0,0 +1,223 @@ +<%@ 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"%> + + + + + + +<% +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)) { +%> +<%= StringEscapeUtils.escapeHtml(query) %>の検索結果 +<% +} +else { +%> +OSM Talk-ja 検索 +<% +} +%> + + + +
+ + + +
+<% +if (!StringUtils.isEmpty(query)) { +%> + <%= StringEscapeUtils.escapeHtml(query) %> の検索結果    +<% +} +if (found > 0) { +%> + <%= found %> 件中 + <%= start+1 %> - + <%= start+rows > found ? found : start+rows %> 件目 +<% +} +else { +%> + 0 件 +<% +} +%> + ( <%= qtime/1000 %> 秒 ) +
+ +
+<% +if (rsp != null) { + if (found == 0) { +%> + <%= StringEscapeUtils.escapeHtml(query) %> は見つかりませんでした。他の検索語で試してください。 +<% + } + else { +%> +
+<% + 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"); + } +%> +

"><%= StringEscapeUtils.escapeHtml(titleStr) %>

+

<%= info %>

+ +<% + 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(); + } + } + } +%> +
<%= StringEscapeUtils.escapeHtml(contents) %>
+<% + } +%> + +<% + String summary = ""; + Map> 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; + } + } + } +%> +
<%= summary %>
+
+
+<% + } + } +%> +
+ +
+ <%-- facet fields --%> +<% + //for (FacetField facetField : rsp.getFacetFields()) { +%> + +<% + //} +%> + + <%-- facet queries --%> + + + +
+<% +} +%> + +
+ +
+ + <%@include file="_pagination.jsp" %> + + +
+ + \ No newline at end of file diff --git a/web/WEB-INF/jsp/search_1.jsp b/web/WEB-INF/jsp/search_1.jsp new file mode 100644 index 0000000..af99e75 --- /dev/null +++ b/web/WEB-INF/jsp/search_1.jsp @@ -0,0 +1,223 @@ +<%@ 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"%> + + + + + + +<% +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)) { +%> +<%= StringEscapeUtils.escapeHtml(query) %>の検索結果 +<% +} +else { +%> +OSM Talk-ja 検索 +<% +} +%> + + + +
+ + + +
+<% +if (!StringUtils.isEmpty(query)) { +%> + <%= StringEscapeUtils.escapeHtml(query) %> の検索結果    +<% +} +if (found > 0) { +%> + <%= found %> 件中 + <%= start+1 %> - + <%= start+rows > found ? found : start+rows %> 件目 +<% +} +else { +%> + 0 件 +<% +} +%> + ( <%= qtime/1000 %> 秒 ) +
+ +
+<% +if (rsp != null) { + if (found == 0) { +%> + <%= StringEscapeUtils.escapeHtml(query) %> は見つかりませんでした。他の検索語で試してください。 +<% + } + else { +%> +
+<% + 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"); + } +%> +

"><%= StringEscapeUtils.escapeHtml(titleStr) %>

+

<%= info %>

+ +<% + 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(); + } + } + } +%> +
<%= StringEscapeUtils.escapeHtml(contents) %>
+<% + } +%> + +<% + String summary = ""; + Map> 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; + } + } + } +%> +
<%= summary %>
+
+
+<% + } + } +%> +
+ +
+ <%-- facet fields --%> +<% + //for (FacetField facetField : rsp.getFacetFields()) { +%> + +<% + //} +%> + + <%-- facet queries --%> + + + +
+<% +} +%> + +
+ +
+ + <%@include file="_pagination.jsp" %> + + +
+ + diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml new file mode 100644 index 0000000..89c8d40 --- /dev/null +++ b/web/WEB-INF/web.xml @@ -0,0 +1,32 @@ + + + + + SolrSample + + + + + index + solrbook.client.servlet.SearchServlet + + + index + /index.html + + + + + index.html + + + + diff --git a/web/style.css b/web/style.css new file mode 100644 index 0000000..ed3c127 --- /dev/null +++ b/web/style.css @@ -0,0 +1,123 @@ +* { + padding: 0; + margin: 0; +} + +body { +background: #fff; +font-family: 'ヒラギノ角ゴ Pro W3','Hiragino Kaku Gothic Pro','メイリオ',Meiryo,'MS Pゴシック',Arial,Helvetica,sans-serif; +font-size: 12px; +line-height: 18px; +color: #333333;; +} + +img { border: none; } +a { color: #57626a; text-decoration: none; } +a:hover { text-decoration: underline; color : #000; } + +em{ +background: aquamarine; +font-weight: bold; +} + +#wrap { +margin: 0 auto; +width: 800px; +} + +#header { +padding: 10px 0 20px 0; +} +#header h1 { +font-size: 26px; +font-weight: 100; +letter-spacing: -3px; +padding: 12px 0 5px 10px; +} +#header h1 a { +color: #57626a; +text-decoration: none; +} +#header h1 a:hover { +color: #57626a; +text-decoration: none; +} +#header h2 { +color: #ccc; +font-size: 15px; +font-weight: 100; +padding: 0 0 0 11px; +letter-spacing: -1px; +line-height: 12px; +} + +#content { +padding: 10px 20px; +} + +#result_header { +background: #eee; +border-top: 3px solid #57626a; +margin-top: 20px; +color: #333; +font-size: 11px; +padding: 10px; +} + +.right { +width: 568px; +float: right; +text-align: justify; +} +.right h2 { +color: #FF4800; +font-size: 20px; +letter-spacing: -3px; +font-weight: 100; +padding : 10px 0 15px 0; +} + +.left { +width: 150px; +float: left; +padding: 10px; +border-right: 1px solid #bbb; +font-size: 12px; +} +.left ul { +list-style-type: square; +padding: 5px 10px 10px 20px; +color: #57626a; +} +.left h2 { +height: 30px; +font-size: 14px; +color: #666; +line-height: 30px; +font-weight: 600; +} +.left a { text-decoration: none } + +#footer { +background: #eee; +border-top: 3px solid #57626a; +margin-top: 20px; +text-align: center; +color: #333; +font-size: 11px; +padding: 10px; +} + +#page { +margin:10px; +text-align: center; +padding:0px; +} +#page a { +text-align:center;padding:3px 4px 2px 4px; +text-decoration:none;font-weight:bold;color:#555555; +border:1px solid #CCCCCC;background:#FFFFFF; +} +#page a:hover {background:#FFCC99;} +#page a:visited {background:#FFFFFF;} +#page a:active {background:#CCFFCC;}