%@ page pageEncoding="Shift_JIS" contentType="text/html; charset=Shift_JIS" %> <%@ page import = " javax.servlet.*, javax.servlet.http.*, java.io.*, org.apache.lucene.analysis.*, org.apache.lucene.document.*, org.apache.lucene.index.*, org.apache.lucene.search.*, org.apache.lucene.queryParser.*, org.apache.lucene.demo.*, org.apache.lucene.demo.html.Entities" %> <% /* Author: Andrew C. Oliver, SuperLink Software, Inc. (acoliver2@users.sourceforge.net) This jsp page is deliberatly written in the horrble java directly embedded in the page style for an easy and conceise demonstration of Lucene. Due note...if you write pages that look like this...sooner or later you'll have a maintenance nightmere. If you use jsps...use taglibs and beans! That being said, this should be acceptable for a small page demonstrating how one uses Lucene in a web app. このjspページは、Luceneを簡単に簡潔に説明するため、ページ中に直接恐 ろしいjavaを埋め込む形で書かれています。Due note...もしこのようなペー ジを書けば...遅かれ早かれメンテナンスという悪夢を見る事になるでしょ う。もしjspを使うならば、taglibとbeansを使いましょう! 要するに、この ページはWebアプリケーション内でLuceneをどうやって使うのかを説明する 小さなページだから許されるのです。 This is also deliberately overcommented. ;-) このページは故意にコメントを多くしています。 ;-) */ %> <%@include file="header.jsp"%> <% boolean error = false; //used to control flow for error messages //エラーメッセージ用のフローをコントロールするために使用 String indexName = indexLocation; //local copy of the configuration variable //設定変数のローカルコピー IndexSearcher searcher = null; //the searcher used to open/search the index //インデックスを開いたり検索したりするのに使用するサーチャ Query query = null; //the Query created by the QueryParser //クエリパーサによって作られたクエリ Hits hits = null; //the search results //検索結果 int startindex = 0; //the first index displayed on this page //このページに表示された最初のインデックス int maxpage = 50; //the maximum items displayed on this page //このページで表示される最大件数 String queryString = null; //the query entered in the previous page //前のページで入力した検索語 String startVal = null; //string version of startindex //スタートインデックスの文字列バージョン String maxresults = null; //string version of maxpage //最大ページの文字列バージョン int thispage = 0; //used for the for/next either maxpage or //hits.length() - startindex - whichever is //less //最大ページかhits.length() - スタートイン //デックス - どちらか小さい方に使用 try { searcher = new IndexSearcher( IndexReader.open(indexName) //create an indexSearcher for our page //ページ用にindexSearcherを作成 ); } catch (Exception e) { //any error that happens is probably due //to a permission problem or non-existant //or otherwise corrupt index //起こったエラーは、たぶんパー //ミッションの問題か、存在しないか、 //壊れたインデックスのためでしょう。 %>
ERROR opening the Index - contact sysadmin!
インデックスが開けません - システム管理者に連絡してください!
While parsing query: <%=e.getMessage()%>
検索語をパース中にエラーが発生: <%=e.getMessage()%>
<% error = true; //don't do anything up to the footer } %> <% if (error == false) { //did we open the index? //インデックスを開いたか? queryString = request.getParameter("query"); //get the search criteria //検索語を取得 startVal = request.getParameter("startat"); //get the start index //スタートインデックスを取得 maxresults = request.getParameter("maxresults"); //get max results per page //ページ毎の最大検索結果数を取得 try { maxpage = Integer.parseInt(maxresults); //parse the max results first //まず最大検索結果数をパース startindex = Integer.parseInt(startVal); //then the start index //次にスタートインデックス } catch (Exception e) { } //we don't care if something happens we'll just start at 0 //or end at 50 //もし0で始まったり50で終わったりして何か起こっても //気にしません if (queryString == null) throw new ServletException("no query "+ //if you don't have a query then //もしクエリがなければ、 "specified"); //you probably played on the //query string so you get the //treatment //扱い方がわかるように //検索文字列を利用します。 Analyzer analyzer = new StopAnalyzer(); //construct our usual analyzer //通常のアナライザーを作成 try { query = QueryParser.parse(queryString, "contents", analyzer); //parse the } catch (ParseException e) { //query and construct the Query //object //if its just "operator error" //send them a nice error HTML //"オペレータエラー"が適当な //エラーHTMLを送信すれば、 //クエリをパースし、Query //オブジェクトを作成 %>Error While parsing query: <%=e.getMessage()%>
検索語をパース中にエラーが発生: <%=e.getMessage()%>
<% error = true; //don't bother with the rest of //the page //ページの残りは気にしない } } %> <% if (error == false && searcher != null) { // if we've had no errors // searcher != null was to handle // a weird compilation bug //エラーがなければ、 //気味の悪いコンパイルエラーを //nullでないsearcherが処理します。 thispage = maxpage; // default last element to maxpage //デフォルトの最大ページの最後の要素 hits = searcher.search(query); // run the query // クエリを実行 if (hits.length() == 0) { // if we got no results tell the user // ユーザーに伝える結果がなければ %>I'm sorry I couldn't find what you were looking for.
残念ですが、お探しのものが見つかりませんでした。
<% error = true; // don't bother with the rest of the // page // ページの残りは気にしない } } if (error == false && searcher != null) { %>| Document | Summary |
| ドキュメント | 要約 |
| <%=doctitle%> | <%=doc.get("summary")%> |
| More Results>> | |
| 次の検索結果へ>> |