search.jsp revision 830
8900b9eb2514c07047541833286428572493a9fdStéphane Graber<%--
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiCDDL HEADER START
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiThe contents of this file are subject to the terms of the
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiCommon Development and Distribution License (the "License").
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiYou may not use this file except in compliance with the License.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiSee LICENSE.txt included in this distribution for the specific
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumilanguage governing permissions and limitations under the License.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiWhen distributing Covered Code, include this CDDL HEADER in each
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumifile and include the License file at LICENSE.txt.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiIf applicable, add the following below this CDDL HEADER, with the
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumifields enclosed by brackets "[]" replaced with your own identifying
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiinformation: Portions Copyright [yyyy] [name of copyright owner]
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiCDDL HEADER END
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiCopyright 2009 Sun Microsystems, Inc. All rights reserved.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiUse is subject to license terms.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
a5ba96715d4ef264c43d4f187251de491ba198c0KATOH Yasufumiident "%Z%%M% %I% %E% SMI"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
8900b9eb2514c07047541833286428572493a9fdStéphane Graber--%><%@ page import = "javax.servlet.*,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumijava.lang.Integer,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumijavax.servlet.http.*,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumijava.util.Hashtable,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumijava.util.Vector,
faefa7f8584a7d1567df2e6f1f9240a28a6466abStéphane Graberjava.util.Date,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumijava.util.ArrayList,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumijava.util.List,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumijava.lang.*,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumijava.io.*,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumijava.io.StringReader,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiorg.opensolaris.opengrok.analysis.*,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiorg.opensolaris.opengrok.index.IndexDatabase,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiorg.opensolaris.opengrok.search.*,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiorg.opensolaris.opengrok.web.*,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiorg.opensolaris.opengrok.search.context.*,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiorg.opensolaris.opengrok.configuration.*,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiorg.apache.lucene.search.spell.LuceneDictionary,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiorg.apache.lucene.search.spell.SpellChecker,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiorg.apache.lucene.store.FSDirectory,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiorg.apache.lucene.analysis.*,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiorg.apache.lucene.document.*,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiorg.apache.lucene.index.*,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiorg.apache.lucene.search.*,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiorg.apache.lucene.queryParser.*"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi%><%@ page session="false" %><%@ page errorPage="error.jsp" %><%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiDate starttime = new Date();
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiString q = request.getParameter("q");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiString defs = request.getParameter("defs");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiString refs = request.getParameter("refs");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiString hist = request.getParameter("hist");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiString path = request.getParameter("path");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi%><%@ include file="projects.jspf" %><%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiString sort = null;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumifinal String LASTMODTIME = "lastmodtime";
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumifinal String RELEVANCY = "relevancy";
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumifinal String BY_PATH = "fullpath";
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiCookie[] cookies = request.getCookies();
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiif (cookies != null) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi for (Cookie cookie : cookies) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (cookie.getName().equals("OpenGrok/sorting")) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi sort = cookie.getValue();
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (!LASTMODTIME.equals(sort) && !RELEVANCY.equals(sort) && !BY_PATH.equals(sort)) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi sort = RELEVANCY;
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi }
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi break;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi}
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiString sortParam = request.getParameter("sort");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiif (sortParam != null) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (LASTMODTIME.equals(sortParam)) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi sort = LASTMODTIME;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else if (RELEVANCY.equals(sortParam)) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi sort = RELEVANCY;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else if (BY_PATH.equals(sortParam)) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi sort = BY_PATH;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (sort != null) {
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi Cookie cookie = new Cookie("OpenGrok/sorting", sort);
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi response.addCookie(cookie);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi} else { sort = RELEVANCY; }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi//List<org.apache.lucene.document.Document> docs=new ArrayList<org.apache.lucene.document.Document>();
57da8c32f85c0255efa61ee32e260068afdaa565KATOH YasufumiString errorMsg = null;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiif( q!= null && q.equals("")) q = null;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiif( defs != null && defs.equals("")) defs = null;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiif( refs != null && refs.equals("")) refs = null;
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumiif( hist != null && hist.equals("")) hist = null;
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumiif( path != null && path.equals("")) path = null;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiif (project != null && project.size()<1) project = null;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiif (q != null || defs != null || refs != null || hist != null || path != null) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi Searcher searcher = null; //the searcher used to open/search the index
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi TopDocCollector collector=null; // the collector used
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ScoreDoc[] hits = null; // list of documents which result from the query
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi IndexReader ireader = null; //the reader used to open/search the index
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi Query query = null, defQuery = null; //the Query created by the QueryParser
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi boolean allCollected=false;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi int totalHits=0;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi int start = 0; //the first index displayed on this page
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi //TODO deprecate max this and merge with paging and param n - TEST needed
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi //int max = 25; //the maximum items displayed on this page
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi int max=RuntimeEnvironment.getInstance().getHitsPerPage();
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi int hitsPerPage = RuntimeEnvironment.getInstance().getHitsPerPage();
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi int cachePages= RuntimeEnvironment.getInstance().getCachePages();
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi int thispage = 0; //used for the for/next either max or
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi String moreUrl = null;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi CompatibleAnalyser analyzer = new CompatibleAnalyser();
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi String qstr = "";
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi String result = "";
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi try {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi String DATA_ROOT = env.getDataRootPath();
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi if(DATA_ROOT.equals("")) {
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi throw new Exception("DATA_ROOT parameter is not configured in web.xml!");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi File data_root = new File(DATA_ROOT);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if(!data_root.isDirectory()) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi throw new Exception("DATA_ROOT parameter in web.xml does not exist or is not a directory!");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi //String date = request.getParameter("date");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi try {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi //TODO merge paging hitsPerPage with parameter n (has to reflect the search if changed so proper number is cached first time)
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi start = Integer.parseInt(request.getParameter("start")); //parse the max results first
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi max = Integer.parseInt(request.getParameter("n")); //then the start index
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if(max < 0 || (max % 10 != 0) || max > 50) max = 25;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if(start < 0 ) start = 0;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } catch (Exception e) { }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi qstr = Util.buildQueryString(q, defs, refs, path, hist);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi QueryParser qparser = new QueryParser("full", analyzer);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi qparser.setDefaultOperator(QueryParser.AND_OPERATOR);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi qparser.setAllowLeadingWildcard(env.isAllowLeadingWildcard());
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi query = qparser.parse(qstr); //parse the
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi File root = new File(RuntimeEnvironment.getInstance().getDataRootFile(),
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi "index");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (RuntimeEnvironment.getInstance().hasProjects()) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (project == null) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi errorMsg = "<b>Error:</b> You must select a project!";
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (project.size() > 1) { //more projects
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi IndexSearcher[] searchables = new IndexSearcher[project.size()];
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi File droot = new File(RuntimeEnvironment.getInstance().getDataRootFile(), "index");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi int ii = 0;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi //TODO might need to rewrite to Project instead of String , need changes in projects.jspf too
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi for (String proj : project) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ireader = (IndexReader.open(new File(droot, proj)));
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi searchables[ii++] = new IndexSearcher(ireader);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (Runtime.getRuntime().availableProcessors() > 1) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi searcher = new ParallelMultiSearcher(searchables);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi searcher = new MultiSearcher(searchables);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else { // just 1 project selected
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi root = new File(root, project.get(0));
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ireader = IndexReader.open(root);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi searcher = new IndexSearcher(ireader);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else { //no project setup
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ireader = IndexReader.open(root);
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi searcher = new IndexSearcher(ireader);
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi }
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi //TODO check if below is somehow reusing sessions so we don't requery again and again, I guess 2min timeout sessions could be usefull, since you click on the next page within 2mins, if not, then wait ;)
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (errorMsg == null) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi collector = new TopDocCollector(hitsPerPage*cachePages);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (LASTMODTIME.equals(sort)) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi Sort sortf = new Sort("date", true);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi TopFieldDocs fdocs=searcher.search(query, null,hitsPerPage*cachePages, sortf);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi totalHits=fdocs.totalHits;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (start>=hitsPerPage*cachePages && !allCollected) { //fetch ALL results only if above cachePages
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi fdocs=searcher.search(query, null, totalHits, sortf);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi allCollected=true;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi hits = fdocs.scoreDocs;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else if (BY_PATH.equals(sort)) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi Sort sortf = new Sort(BY_PATH);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi TopFieldDocs fdocs=searcher.search(query, null,hitsPerPage*cachePages, sortf);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi totalHits=fdocs.totalHits;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (start>=hitsPerPage*cachePages && !allCollected) { //fetch ALL results only if above cachePages
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi fdocs=searcher.search(query, null,totalHits, sortf);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi allCollected=true;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi hits = fdocs.scoreDocs;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi searcher.search(query,collector);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi totalHits=collector.getTotalHits();
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (start>=hitsPerPage*cachePages && !allCollected) { //fetch ALL results only if above cachePages
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi collector = new TopDocCollector(totalHits);
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi searcher.search(query,collector);
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi allCollected=true;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi hits=collector.topDocs().scoreDocs;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi //below will get all the documents
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi// for (int i = 0; i < hits.length; i++) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi// int docId = hits[i].doc;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi// Document d = searcher.doc(docId);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi// docs.add(d);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi// }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi thispage = max;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } catch (BooleanQuery.TooManyClauses e) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi errorMsg = "<b>Error:</b> Too many results for wildcard!";
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } catch (ParseException e) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi errorMsg = "<b>Error parsing your query:</b><br/>" + Util.htmlize(qstr) +
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi "<p/>You might try to enclose your search term in quotes: <br/>" +
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi "<a href=search?q=\"" + qstr + "\">\"" + Util.htmlize(qstr) +
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi "\"</a><p/> or read the <a href=\"help.jsp\">Help</a> on query language(eventually <a href=\"help.jsp#escaping\">escape special characters</a> with <b>\\</b>)<p/>" +
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi "Error message from parser:<br/>" + Util.htmlize(e.getMessage());
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } catch (FileNotFoundException e) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi errorMsg = "<b>Error:</b> Index database not found";
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } catch (Exception e) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi errorMsg = "<b>Error:</b> " + Util.htmlize(e.getMessage());
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi // @TODO fix me. I should try to figure out where the exact hit is instead
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi // of returning a page with just _one_ entry in....
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (hits != null && hits.length == 1 && request.getServletPath().equals("/s") && (query != null && query instanceof TermQuery)) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi String preFragmentPath = Util.URIEncodePath(context + "/xref" + searcher.doc(hits[0].doc).get("path"));
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi String fragment = Util.URIEncode(((TermQuery)query).getTerm().text());
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi StringBuilder url = new StringBuilder(preFragmentPath);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi url.append("#");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi url.append(fragment);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi response.sendRedirect(url.toString());
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi String pageTitle = "Search";
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi RuntimeEnvironment environment = RuntimeEnvironment.getInstance();
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi environment.register();
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi %><%@ include file="httpheader.jspf" %>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi<body>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi<div id="page">
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi <div id="header"><%@ include file="pageheader.jspf" %></div>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi<div id="Masthead"></div>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi<div id="bar">
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi <table border="0" width="100%"><tr><td><a href="<%=context%>" id="home">Home</a></td><td align="right"><%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi StringBuffer url = request.getRequestURL();
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi url.append('?');
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi String querys = request.getQueryString();
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi if (querys != null) {
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi int idx = querys.indexOf("sort=");
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi if (idx == -1) {
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi url.append(querys);
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi url.append('&');
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi } else {
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi url.append(querys.substring(0, idx));
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi %>Sort by: <%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi url.append("sort=");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (sort == null || RELEVANCY.equals(sort)) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi %><b>relevance</b> | <a href="<%=url.toString()+LASTMODTIME%>">last modified time</a> | <a href="<%=url.toString()+BY_PATH%>">path</a><%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else if (LASTMODTIME.equals(sort)) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi %><a href="<%=url.toString()+RELEVANCY%>">relevance</a> | <b>last modified time</b> | <a href="<%=url.toString()+BY_PATH%>">path</a><%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else if (BY_PATH.equals(sort)) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi %><a href="<%=url.toString()+RELEVANCY%>">relevance</a> | <a href="<%=url.toString()+LASTMODTIME%>">last modified time</a> | <b>path</b><%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi %><a href="<%=url.toString()+RELEVANCY%>">relevance</a> | <a href="<%=url.toString()+LASTMODTIME%>">last modified time</a> | <a href="<%=url.toString()+BY_PATH%>">path</a><%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } %></td></tr></table>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi</div>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi<div id="menu">
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi <%@ include file="menu.jspf"%>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi</div>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi<div id="results">
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi<%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi//TODO spellchecking cycle below is not that great and we only create suggest links for every token in query, not for a query as whole
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiif( hits == null || errorMsg != null) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi %><%=errorMsg%><%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else if (hits.length == 0) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi File spellIndex = new File(env.getDataRootPath(), "spellIndex");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi File[] spellIndexes=null;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (RuntimeEnvironment.getInstance().hasProjects()) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (project.size() > 1) { //more projects
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi spellIndexes = new File[project.size()];
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi int ii = 0;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi //TODO might need to rewrite to Project instead of String , need changes in projects.jspf too
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi for (String proj : project) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi spellIndexes[ii++] = new File(spellIndex,proj);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else { // just 1 project selected
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi spellIndex = new File(spellIndex, project.get(0));
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi int count=1;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (spellIndexes!=null) {count=spellIndexes.length;}
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi for (int idx = 0; idx < count; idx++) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (spellIndexes!=null) spellIndex = spellIndexes[idx];
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (spellIndex.exists()) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi FSDirectory spellDirectory = FSDirectory.getDirectory(spellIndex);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi SpellChecker checker = new SpellChecker(spellDirectory);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi Date sstart = new Date();
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi boolean printHeader = true;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi String[] toks;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if(q != null) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi toks = q.split("[\t ]+");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if(toks != null){
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi for(int j=0; j<toks.length; j++) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if(toks[j].length() > 3) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 5);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi for(int i = 0;i < ret.length; i++) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (printHeader) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi %><p><font color="#cc0000">Did you mean(for <%=spellIndex.getName()%>)</font>:<%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi printHeader = false;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi %> <a href=search?q=<%=ret[i]%>><%=ret[i]%></a> &nbsp; <%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if(refs != null) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi toks = refs.split("[\t ]+");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if(toks != null){
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi for(int j=0; j<toks.length; j++) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if(toks[j].length() > 3) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 5);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi for(int i = 0;i < ret.length; i++) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (printHeader) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi %><p><font color="#cc0000">Did you mean(for <%=spellIndex.getName()%>)</font>:<%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi printHeader = false;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi %> <a href=search?refs=<%=ret[i]%>><%=ret[i]%></a> &nbsp; <%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi //TODO it seems the only true spellchecker is for below field, see IndexDatabase createspellingsuggestions ...
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if(defs != null) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi toks = defs.split("[\t ]+");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if(toks != null){
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi for(int j=0; j<toks.length; j++) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if(toks[j].length() > 3) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 5);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi for(int i = 0;i < ret.length; i++) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (printHeader) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi %><p><font color="#cc0000">Did you mean(for <%=spellIndex.getName()%>)</font>:<%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi printHeader = false;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi %> <a href=search?defs=<%=ret[i]%>><%=ret[i]%></a> &nbsp; <%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (printHeader) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi %></p><%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi spellDirectory.close();
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi }
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi %><p> Your search <b><%=query.toString()%></b> did not match any files.
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi <br />
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi Suggestions:<br/><blockquote>- Make sure all terms are spelled correctly.<br/>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi - Try different keywords.<br/>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi - Try more general keywords.<br/>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi - Use 'wil*' cards if you are looking for partial match.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi </blockquote>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi </p><%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else { // We have a lots of results to show
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi StringBuilder slider = null;
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi if ( max < totalHits) {
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi if((start + max) < totalHits) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi thispage = max;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi thispage = totalHits - start;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi String url = (q == null ? "" : "&amp;q=" + Util.URIEncode(q) ) +
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi (defs == null ? "" : "&amp;defs=" + Util.URIEncode(defs)) +
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi (refs == null ? "" : "&amp;refs=" + Util.URIEncode(refs)) +
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi (path == null ? "" : "&amp;path=" + Util.URIEncode(path)) +
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi (hist == null ? "" : "&amp;hist=" + Util.URIEncode(hist)) +
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi (sort == null ? "" : "&amp;sort=" + Util.URIEncode(sort));
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi for (Iterator it = project.iterator(); it.hasNext();) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi url=url+(project == null ? "" : "&amp;project=" + Util.URIEncode((String)it.next()));
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi slider = new StringBuilder();
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi int labelStart =1;
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi int sstart = start - max* (start / max % 10 + 1) ;
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi if(sstart < 0) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi sstart = 0;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi labelStart = 1;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi labelStart = sstart/max + 1;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi int label = labelStart;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi int labelEnd = label + 11;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi String arr;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi for(int i=sstart; i<totalHits && label <= labelEnd; i+= max) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (i <= start && start < i+ max) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi slider.append("<span class=\"sel\">" + label + "</span>");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if(label == labelStart && label != 1) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi arr = "&lt;&lt";
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else if(label == labelEnd && i < totalHits) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi arr = "&gt;&gt;";
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi arr = label < 10 ? " " + label : String.valueOf(label);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi slider.append("<a class=\"more\" href=\"search?n=" + max + "&amp;start=" + i + url + "\">"+
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi arr + "</a>");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi label++;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } else {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi thispage = totalHits - start; // set the max index to max or last
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi %>&nbsp; &nbsp; Searched <b><%=query.toString()%></b> (Results <b><%=start+1%> -
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi <%=thispage+start%></b> of <b><%=totalHits%></b>) sorted by <%=sort%> <p><%=slider != null ?
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi slider.toString(): ""%></p>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi <table width="100%" cellpadding="3" cellspacing="0" border="0"><%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi Context sourceContext = null;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi Summarizer summer = null;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if (query != null) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi try{
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi sourceContext = new Context(query);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if(sourceContext != null)
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi summer = new Summarizer(query, analyzer);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } catch (Exception e) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi HistoryContext historyContext = null;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi try {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi historyContext = new HistoryContext(query);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } catch (Exception e) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi EftarFileReader ef = null;
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi try{
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ef = new EftarFileReader(env.getDataRootPath() + "/index/dtags.eftar");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } catch (Exception e) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi //TODO also fix the way what and how it is passed to prettyprint, can improve performance! SearchEngine integration is really needed here.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi Results.prettyPrintHTML(searcher,hits, start, start+thispage,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi out,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi sourceContext, historyContext, summer,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi context + "/xref",
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi context + "/more",
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi env.getSourceRootPath(),
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi env.getDataRootPath(),
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ef);
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if(ef != null) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi try{
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi ef.close();
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi } catch (IOException e) {
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi %></table><br/>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi <b> Completed in <%=(new Date()).getTime() - starttime.getTime()%> milliseconds </b> <br/>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi <%=slider != null ? "<p>" + slider + "</p>" : ""%>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi <%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi %><br/></div><%@include file="foot.jspf"%><%
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi }
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi if (ireader != null)
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi ireader.close();
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi} else { // Entry page show the map
9a97d4e4bdf331bb2c2b8ed14bcefa53358c288fKATOH Yasufumi response.sendRedirect(context + "/index.jsp");
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi}
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi%>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi