search.jsp revision 985
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk<%--
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkCDDL HEADER START
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkThe contents of this file are subject to the terms of the
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkCommon Development and Distribution License (the "License").
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkYou may not use this file except in compliance with the License.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkSee LICENSE.txt included in this distribution for the specific
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenklanguage governing permissions and limitations under the License.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkWhen distributing Covered Code, include this CDDL HEADER in each
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkfile and include the License file at LICENSE.txt.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkIf applicable, add the following below this CDDL HEADER, with the
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkfields enclosed by brackets "[]" replaced with your own identifying
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkinformation: Portions Copyright [yyyy] [name of copyright owner]
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkCDDL HEADER END
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkCopyright 2010 Sun Microsystems, Inc. All rights reserved.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkUse is subject to license terms.
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk--%><%@ page import = "javax.servlet.*,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkjava.lang.Integer,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkjavax.servlet.http.*,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkjava.util.Hashtable,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkjava.util.Vector,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkjava.util.Date,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkjava.util.ArrayList,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkjava.util.List,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkjava.lang.*,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkjava.io.*,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkjava.io.StringReader,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkorg.opensolaris.opengrok.analysis.*,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkorg.opensolaris.opengrok.index.IndexDatabase,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkorg.opensolaris.opengrok.search.*,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkorg.opensolaris.opengrok.web.*,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkorg.opensolaris.opengrok.search.context.*,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkorg.opensolaris.opengrok.search.SearchEngine,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkorg.opensolaris.opengrok.configuration.*,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkorg.apache.lucene.search.spell.LuceneDictionary,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkorg.apache.lucene.search.spell.SpellChecker,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkorg.apache.lucene.search.SortField,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkorg.apache.lucene.search.TopScoreDocCollector,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkorg.apache.lucene.store.FSDirectory,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkorg.apache.lucene.analysis.*,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkorg.apache.lucene.document.*,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkorg.apache.lucene.index.*,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkorg.apache.lucene.search.*,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkorg.apache.lucene.queryParser.*"
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk%><%@ page session="false" %><%@ page errorPage="error.jsp" %><%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkDate starttime = new Date();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkString q = request.getParameter("q");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkString defs = request.getParameter("defs");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkString refs = request.getParameter("refs");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkString hist = request.getParameter("hist");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkString path = request.getParameter("path");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk%><%@ include file="projects.jspf" %><%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkString sort = null;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkfinal String LASTMODTIME = "lastmodtime";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkfinal String RELEVANCY = "relevancy";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkfinal String BY_PATH = "fullpath";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkfinal SortField S_BY_PATH = new SortField(BY_PATH,SortField.STRING);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkCookie[] cookies = request.getCookies();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkif (cookies != null) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for (Cookie cookie : cookies) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (cookie.getName().equals("OpenGrok/sorting")) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk sort = cookie.getValue();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (!LASTMODTIME.equals(sort) && !RELEVANCY.equals(sort) && !BY_PATH.equals(sort)) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk sort = RELEVANCY;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk break;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk}
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkString sortParam = request.getParameter("sort");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkif (sortParam != null) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (LASTMODTIME.equals(sortParam)) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk sort = LASTMODTIME;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else if (RELEVANCY.equals(sortParam)) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk sort = RELEVANCY;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else if (BY_PATH.equals(sortParam)) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk sort = BY_PATH;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (sort != null) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Cookie cookie = new Cookie("OpenGrok/sorting", sort);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk response.addCookie(cookie);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk} else { sort = RELEVANCY; }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//List<org.apache.lucene.document.Document> docs=new ArrayList<org.apache.lucene.document.Document>();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkString errorMsg = null;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkif( q!= null && q.equals("")) q = null;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkif( defs != null && defs.equals("")) defs = null;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkif( refs != null && refs.equals("")) refs = null;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkif( hist != null && hist.equals("")) hist = null;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkif( path != null && path.equals("")) path = null;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkif (project != null && project.size()<1) project = null;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkif (q != null || defs != null || refs != null || hist != null || path != null) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Searcher searcher = null; //the searcher used to open/search the index
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk TopScoreDocCollector collector=null; // the collector used
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ScoreDoc[] hits = null; // list of documents which result from the query
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk IndexReader ireader = null; //the reader used to open/search the index
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Query query = null, defQuery = null; //the Query created by the QueryParser
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk boolean allCollected=false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int totalHits=0;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int start = 0; //the first index displayed on this page
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //TODO deprecate max this and merge with paging and param n - TEST needed
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //int max = 25; //the maximum items displayed on this page
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int max=RuntimeEnvironment.getInstance().getHitsPerPage();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int hitsPerPage = RuntimeEnvironment.getInstance().getHitsPerPage();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int cachePages= RuntimeEnvironment.getInstance().getCachePages();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk final boolean docsScoredInOrder=false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int thispage = 0; //used for the for/next either max or
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk QueryParser qparser = null;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String qstr = "";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String DATA_ROOT = env.getDataRootPath();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(DATA_ROOT.equals("")) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk throw new Exception("DATA_ROOT parameter is not configured in web.xml!");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk File data_root = new File(DATA_ROOT);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(!data_root.isDirectory()) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk throw new Exception("DATA_ROOT parameter in web.xml does not exist or is not a directory!");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //String date = request.getParameter("date");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //TODO merge paging hitsPerPage with parameter n (has to reflect the search if changed so proper number is cached first time)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk start = Integer.parseInt(request.getParameter("start")); //parse the max results first
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk max = Integer.parseInt(request.getParameter("n")); //then the start index
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(max < 0 || (max % 10 != 0) || max > 50) max = 25;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(start < 0 ) start = 0;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } catch (Exception e) { }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk qstr = Util.buildQueryString(q, defs, refs, path, hist);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk qparser = SearchEngine.createQueryParser();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk query = qparser.parse(qstr); //parse the
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk File root = new File(RuntimeEnvironment.getInstance().getDataRootFile(),
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk "index");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (RuntimeEnvironment.getInstance().hasProjects()) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (project == null) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk errorMsg = "<b>Error:</b> You must select a project!";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (project.size() > 1) { //more projects
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk IndexSearcher[] searchables = new IndexSearcher[project.size()];
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk File droot = new File(RuntimeEnvironment.getInstance().getDataRootFile(), "index");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int ii = 0;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //TODO might need to rewrite to Project instead of String , need changes in projects.jspf too
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for (String proj : project) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ireader = (IndexReader.open(FSDirectory.open(new File(droot, proj)),true));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk searchables[ii++] = new IndexSearcher(ireader);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (Runtime.getRuntime().availableProcessors() > 1) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk searcher = new ParallelMultiSearcher(searchables);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk searcher = new MultiSearcher(searchables);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else { // just 1 project selected
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk root = new File(root, project.get(0));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ireader = IndexReader.open(FSDirectory.open(root),true);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk searcher = new IndexSearcher(ireader);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else { //no project setup
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ireader = IndexReader.open(FSDirectory.open(root),true);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk searcher = new IndexSearcher(ireader);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //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 ;)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (errorMsg == null) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk collector = TopScoreDocCollector.create(hitsPerPage*cachePages,docsScoredInOrder);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (LASTMODTIME.equals(sort)) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Sort sortf = new Sort(new SortField("date",SortField.STRING,true));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk TopFieldDocs fdocs=searcher.search(query, null,hitsPerPage*cachePages, sortf);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk totalHits=fdocs.totalHits;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (start>=hitsPerPage*cachePages && !allCollected) { //fetch ALL results only if above cachePages
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk fdocs=searcher.search(query, null, totalHits, sortf);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk allCollected=true;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk hits = fdocs.scoreDocs;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else if (BY_PATH.equals(sort)) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Sort sortf = new Sort(S_BY_PATH);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk TopFieldDocs fdocs=searcher.search(query, null,hitsPerPage*cachePages, sortf);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk totalHits=fdocs.totalHits;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (start>=hitsPerPage*cachePages && !allCollected) { //fetch ALL results only if above cachePages
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk fdocs=searcher.search(query, null,totalHits, sortf);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk allCollected=true;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk hits = fdocs.scoreDocs;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk searcher.search(query,collector);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk totalHits=collector.getTotalHits();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (start>=hitsPerPage*cachePages && !allCollected) { //fetch ALL results only if above cachePages
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk collector = TopScoreDocCollector.create(totalHits,docsScoredInOrder);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk searcher.search(query,collector);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk allCollected=true;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk hits=collector.topDocs().scoreDocs;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //below will get all the documents
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// for (int i = 0; i < hits.length; i++) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// int docId = hits[i].doc;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// Document d = searcher.doc(docId);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// docs.add(d);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk thispage = max;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } catch (BooleanQuery.TooManyClauses e) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk errorMsg = "<b>Error:</b> Too many results for wildcard!";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } catch (ParseException e) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk errorMsg = "<b>Error parsing your query:</b><br/>" + Util.htmlize(qstr) +
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk "<p/>You might try to enclose your search term in quotes: <br/>" +
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk "<a href=search?q=\"" + Util.URIEncode(qstr) + "\">\"" + Util.htmlize(qstr) +
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk "\"</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/>" +
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk "Error message from parser:<br/>" + Util.htmlize(e.getMessage());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } catch (FileNotFoundException e) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk errorMsg = "<b>Error:</b> Index database not found";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } catch (Exception e) {
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk errorMsg = "<b>Error:</b> " + Util.htmlize(e.getMessage());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Bug #3900: Check if this is a search for a single term, and that term
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // is a definition. If that's the case, and we only have one match, we'll
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // generate a direct link instead of a listing.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk boolean isSingleDefinitionSearch =
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk (query instanceof TermQuery) && (defs != null);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Attempt to create a direct link to the definition if we search for one
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // single definition term AND we have exactly one match AND there is only
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // one definition of that symbol in the document that matches.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk boolean uniqueDefinition = false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (isSingleDefinitionSearch && hits != null && hits.length == 1) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Document doc = searcher.doc(hits[0].doc);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk byte[] rawTags = doc.getFieldable("tags").getBinaryValue();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Definitions tags = Definitions.deserialize(rawTags);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String symbol = ((TermQuery) query).getTerm().text();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (tags.occurrences(symbol) == 1) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk uniqueDefinition = true;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // @TODO fix me. I should try to figure out where the exact hit is instead
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // of returning a page with just _one_ entry in....
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (uniqueDefinition && request.getServletPath().equals("/s")) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String preFragmentPath = Util.URIEncodePath(context + "/xref" + searcher.doc(hits[0].doc).get("path"));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String fragment = Util.URIEncode(((TermQuery)query).getTerm().text());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk StringBuilder url = new StringBuilder(preFragmentPath);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk url.append("#");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk url.append(fragment);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk response.sendRedirect(url.toString());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String pageTitle = "Search";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk RuntimeEnvironment environment = RuntimeEnvironment.getInstance();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk environment.register();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk %><%@ include file="httpheader.jspf" %>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk<body>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk<div id="page">
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk <div id="header"><%@ include file="pageheader.jspf" %></div>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk<div id="Masthead"></div>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk<div id="bar">
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk <table border="0" width="100%"><tr><td><a href="<%=context%>" id="home">Home</a></td><td align="right"><%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String url = "search?";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk url = url + (q == null ? "" : "&amp;q=" + Util.URIEncode(q)) +
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk (defs == null ? "" : "&amp;defs=" + Util.URIEncode(defs)) +
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk (refs == null ? "" : "&amp;refs=" + Util.URIEncode(refs)) +
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk (path == null ? "" : "&amp;path=" + Util.URIEncode(path)) +
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk (hist == null ? "" : "&amp;hist=" + Util.URIEncode(hist));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (hasProjects) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (project!=null) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk url = url + "&amp;project=";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for (Iterator it = project.iterator(); it.hasNext();) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk url = url + (project == null ? "" : Util.URIEncode((String) it.next()) + ",");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk %>Sort by: <%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk url=url+("&amp;sort=");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (sort == null || RELEVANCY.equals(sort)) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk %><b>relevance</b> | <a href="<%=url+LASTMODTIME%>">last modified time</a> | <a href="<%=url+BY_PATH%>">path</a><%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else if (LASTMODTIME.equals(sort)) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk %><a href="<%=url+RELEVANCY%>">relevance</a> | <b>last modified time</b> | <a href="<%=url+BY_PATH%>">path</a><%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else if (BY_PATH.equals(sort)) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk %><a href="<%=url+RELEVANCY%>">relevance</a> | <a href="<%=url+LASTMODTIME%>">last modified time</a> | <b>path</b><%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk %><a href="<%=url+RELEVANCY%>">relevance</a> | <a href="<%=url+LASTMODTIME%>">last modified time</a> | <a href="<%=url+BY_PATH%>">path</a><%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } %></td></tr></table>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk</div>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk<div id="menu">
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk <%@ include file="menu.jspf"%>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk</div>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk<div id="results">
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk<%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//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
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkif( hits == null || errorMsg != null) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk %><%=errorMsg%><%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else if (hits.length == 0) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk File spellIndex = new File(env.getDataRootPath(), "spellIndex");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk File[] spellIndexes=null;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (RuntimeEnvironment.getInstance().hasProjects()) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (project.size() > 1) { //more projects
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk spellIndexes = new File[project.size()];
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int ii = 0;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //TODO might need to rewrite to Project instead of String , need changes in projects.jspf too
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for (String proj : project) {
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk spellIndexes[ii++] = new File(spellIndex,proj);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else { // just 1 project selected
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk spellIndex = new File(spellIndex, project.get(0));
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int count=1;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (spellIndexes!=null) {count=spellIndexes.length;}
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for (int idx = 0; idx < count; idx++) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (spellIndexes!=null) spellIndex = spellIndexes[idx];
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (spellIndex.exists()) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk FSDirectory spellDirectory = FSDirectory.open(spellIndex);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk SpellChecker checker = new SpellChecker(spellDirectory);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Date sstart = new Date();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk boolean printHeader = true;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String[] toks;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(q != null) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk toks = q.split("[\t ]+");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(toks != null){
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for(int j=0; j<toks.length; j++) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(toks[j].length() > 3) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 5);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for(int i = 0;i < ret.length; i++) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (printHeader) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk %><p><font color="#cc0000">Did you mean(for <%=spellIndex.getName()%>)</font>:<%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk printHeader = false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk %> <a href=search?q=<%=ret[i]%>><%=ret[i]%></a> &nbsp; <%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(refs != null) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk toks = refs.split("[\t ]+");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(toks != null){
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for(int j=0; j<toks.length; j++) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(toks[j].length() > 3) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 5);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for(int i = 0;i < ret.length; i++) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (printHeader) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk %><p><font color="#cc0000">Did you mean(for <%=spellIndex.getName()%>)</font>:<%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk printHeader = false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk %> <a href=search?refs=<%=ret[i]%>><%=ret[i]%></a> &nbsp; <%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //TODO it seems the only true spellchecker is for below field, see IndexDatabase createspellingsuggestions ...
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(defs != null) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk toks = defs.split("[\t ]+");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(toks != null){
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for(int j=0; j<toks.length; j++) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(toks[j].length() > 3) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 5);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for(int i = 0;i < ret.length; i++) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (printHeader) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk %><p><font color="#cc0000">Did you mean(for <%=spellIndex.getName()%>)</font>:<%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk printHeader = false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk %> <a href=search?defs=<%=ret[i]%>><%=ret[i]%></a> &nbsp; <%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (printHeader) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk %></p><%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk spellDirectory.close();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk %><p> Your search <b><%=query.toString()%></b> did not match any files.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk <br />
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Suggestions:<br/><blockquote>- Make sure all terms are spelled correctly.<br/>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk - Try different keywords.<br/>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk - Try more general keywords.<br/>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk - Use 'wil*' cards if you are looking for partial match.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk </blockquote>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk </p><%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else { // We have a lots of results to show
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk StringBuilder slider = null;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if ( max < totalHits) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if((start + max) < totalHits) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk thispage = max;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk thispage = totalHits - start;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String urlp = (q == null ? "" : "&amp;q=" + Util.URIEncode(q)) +
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk (defs == null ? "" : "&amp;defs=" + Util.URIEncode(defs)) +
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk (refs == null ? "" : "&amp;refs=" + Util.URIEncode(refs)) +
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk (path == null ? "" : "&amp;path=" + Util.URIEncode(path)) +
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk (hist == null ? "" : "&amp;hist=" + Util.URIEncode(hist)) +
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk (sort == null ? "" : "&amp;sort=" + Util.URIEncode(sort));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (hasProjects) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk urlp = urlp + "&amp;project=";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for (Iterator it = project.iterator(); it.hasNext();) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk urlp = urlp + (project == null ? "" : Util.URIEncode((String) it.next()) + ",");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk slider = new StringBuilder();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int labelStart =1;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int sstart = start - max* (start / max % 10 + 1) ;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(sstart < 0) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk sstart = 0;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk labelStart = 1;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk labelStart = sstart/max + 1;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int label = labelStart;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int labelEnd = label + 11;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String arr;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for(int i=sstart; i<totalHits && label <= labelEnd; i+= max) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (i <= start && start < i+ max) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk slider.append("<span class=\"sel\">" + label + "</span>");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(label == labelStart && label != 1) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk arr = "&lt;&lt";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else if(label == labelEnd && i < totalHits) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk arr = "&gt;&gt;";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk arr = label < 10 ? " " + label : String.valueOf(label);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk slider.append("<a class=\"more\" href=\"s?n=" + max + "&amp;start=" + i + urlp + "\">"+
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk arr + "</a>");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk label++;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } else {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk thispage = totalHits - start; // set the max index to max or last
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk %>&nbsp; &nbsp; Searched <b><%=query.toString()%></b> (Results <b><%=start+1%> -
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk <%=thispage+start%></b> of <b><%=totalHits%></b>) sorted by <%=sort%> <p><%=slider != null ?
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk slider.toString(): ""%></p>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk <table width="100%" cellpadding="3" cellspacing="0" border="0"><%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Context sourceContext = null;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Summarizer summer = null;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (query != null) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try{
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk sourceContext = new Context(query);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(sourceContext != null)
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk summer = new Summarizer(query,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk qparser.getAnalyzer());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } catch (Exception e) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk HistoryContext historyContext = null;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk historyContext = new HistoryContext(query);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } catch (Exception e) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk EftarFileReader ef = null;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try{
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ef = new EftarFileReader(env.getDataRootPath() + "/index/dtags.eftar");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } catch (Exception e) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //TODO also fix the way what and how it is passed to prettyprint, can improve performance! SearchEngine integration is really needed here.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Results.prettyPrintHTML(searcher,hits, start, start+thispage,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk out,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk sourceContext, historyContext, summer,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk context + "/xref",
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk context + "/more",
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk env.getSourceRootPath(),
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk env.getDataRootPath(),
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ef);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(ef != null) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try{
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ef.close();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } catch (IOException e) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk %></table><br/>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk <b> Completed in <%=(new Date()).getTime() - starttime.getTime()%> milliseconds </b> <br/>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk <%=slider != null ? "<p>" + slider + "</p>" : ""%>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk <%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk %><br/></div><%@include file="foot.jspf"%><%
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (ireader != null)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ireader.close();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk} else { // Entry page show the map
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk response.sendRedirect(context + "/index.jsp");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk}
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk%>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk