search.jsp revision c6e0f8b39af7343c04ec7558a085c965159f4ea0
fa9e4066f08beec538e775443c5be79dd423fcabahrensCDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrensThe contents of this file are subject to the terms of the
fa9e4066f08beec538e775443c5be79dd423fcabahrensCommon Development and Distribution License (the "License").
fa9e4066f08beec538e775443c5be79dd423fcabahrensYou may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrensSee LICENSE.txt included in this distribution for the specific
fa9e4066f08beec538e775443c5be79dd423fcabahrenslanguage governing permissions and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrensWhen distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrensfile and include the License file at LICENSE.txt.
fa9e4066f08beec538e775443c5be79dd423fcabahrensIf applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrensfields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrensinformation: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrensCDDL HEADER END
fa9e4066f08beec538e775443c5be79dd423fcabahrensCopyright 2009 Sun Microsystems, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrensUse is subject to license terms.
fa9e4066f08beec538e775443c5be79dd423fcabahrensident "%Z%%M% %I% %E% SMI"
fa9e4066f08beec538e775443c5be79dd423fcabahrens--%><%@ page import = "javax.servlet.*,
fa9e4066f08beec538e775443c5be79dd423fcabahrens%><%@ page session="false" %><%@ page errorPage="error.jsp" %><%
fa9e4066f08beec538e775443c5be79dd423fcabahrensDate starttime = new Date();
fa9e4066f08beec538e775443c5be79dd423fcabahrensString q = request.getParameter("q");
fa9e4066f08beec538e775443c5be79dd423fcabahrensString defs = request.getParameter("defs");
fa9e4066f08beec538e775443c5be79dd423fcabahrensString refs = request.getParameter("refs");
fa9e4066f08beec538e775443c5be79dd423fcabahrensString hist = request.getParameter("hist");
fa9e4066f08beec538e775443c5be79dd423fcabahrensString path = request.getParameter("path");
fa9e4066f08beec538e775443c5be79dd423fcabahrens%><%@ include file="projects.jspf" %><%
fa9e4066f08beec538e775443c5be79dd423fcabahrensString sort = null;
fa9e4066f08beec538e775443c5be79dd423fcabahrensfinal String LASTMODTIME = "lastmodtime";
fa9e4066f08beec538e775443c5be79dd423fcabahrensfinal String RELEVANCY = "relevancy";
fa9e4066f08beec538e775443c5be79dd423fcabahrensfinal String BY_PATH = "fullpath";
fa9e4066f08beec538e775443c5be79dd423fcabahrensCookie[] cookies = request.getCookies();
fa9e4066f08beec538e775443c5be79dd423fcabahrensif (cookies != null) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (Cookie cookie : cookies) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (!LASTMODTIME.equals(sort) && !RELEVANCY.equals(sort) && !BY_PATH.equals(sort)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens sort = RELEVANCY;
fa9e4066f08beec538e775443c5be79dd423fcabahrensString sortParam = request.getParameter("sort");
fa9e4066f08beec538e775443c5be79dd423fcabahrensif (sortParam != null) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (LASTMODTIME.equals(sortParam)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens sort = LASTMODTIME;
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else if (RELEVANCY.equals(sortParam)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens sort = RELEVANCY;
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else if (BY_PATH.equals(sortParam)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens sort = BY_PATH;
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (sort != null) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens Cookie cookie = new Cookie("OpenGrok/sorting", sort);
fa9e4066f08beec538e775443c5be79dd423fcabahrens} else { sort = RELEVANCY; }
fa9e4066f08beec538e775443c5be79dd423fcabahrens//List<org.apache.lucene.document.Document> docs=new ArrayList<org.apache.lucene.document.Document>();
fa9e4066f08beec538e775443c5be79dd423fcabahrensString errorMsg = null;
fa9e4066f08beec538e775443c5be79dd423fcabahrensif( q!= null && q.equals("")) q = null;
fa9e4066f08beec538e775443c5be79dd423fcabahrensif( defs != null && defs.equals("")) defs = null;
fa9e4066f08beec538e775443c5be79dd423fcabahrensif( refs != null && refs.equals("")) refs = null;
fa9e4066f08beec538e775443c5be79dd423fcabahrensif( hist != null && hist.equals("")) hist = null;
fa9e4066f08beec538e775443c5be79dd423fcabahrensif( path != null && path.equals("")) path = null;
fa9e4066f08beec538e775443c5be79dd423fcabahrensif (project != null && project.size()<1) project = null;
fa9e4066f08beec538e775443c5be79dd423fcabahrensif (q != null || defs != null || refs != null || hist != null || path != null) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens Searcher searcher = null; //the searcher used to open/search the index
fa9e4066f08beec538e775443c5be79dd423fcabahrens TopDocCollector collector=null; // the collector used
fa9e4066f08beec538e775443c5be79dd423fcabahrens ScoreDoc[] hits = null; // list of documents which result from the query
fa9e4066f08beec538e775443c5be79dd423fcabahrens IndexReader ireader = null; //the reader used to open/search the index
fa9e4066f08beec538e775443c5be79dd423fcabahrens Query query = null, defQuery = null; //the Query created by the QueryParser
fa9e4066f08beec538e775443c5be79dd423fcabahrens boolean allCollected=false;
fa9e4066f08beec538e775443c5be79dd423fcabahrens int totalHits=0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens int start = 0; //the first index displayed on this page
fa9e4066f08beec538e775443c5be79dd423fcabahrens //TODO deprecate max this and merge with paging and param n - TEST needed
fa9e4066f08beec538e775443c5be79dd423fcabahrens //int max = 25; //the maximum items displayed on this page
fa9e4066f08beec538e775443c5be79dd423fcabahrens int max=RuntimeEnvironment.getInstance().getHitsPerPage();
fa9e4066f08beec538e775443c5be79dd423fcabahrens int hitsPerPage = RuntimeEnvironment.getInstance().getHitsPerPage();
fa9e4066f08beec538e775443c5be79dd423fcabahrens int cachePages= RuntimeEnvironment.getInstance().getCachePages();
fa9e4066f08beec538e775443c5be79dd423fcabahrens int thispage = 0; //used for the for/next either max or
fa9e4066f08beec538e775443c5be79dd423fcabahrens String moreUrl = null;
fa9e4066f08beec538e775443c5be79dd423fcabahrens CompatibleAnalyser analyzer = new CompatibleAnalyser();
fa9e4066f08beec538e775443c5be79dd423fcabahrens String qstr = "";
fa9e4066f08beec538e775443c5be79dd423fcabahrens String result = "";
fa9e4066f08beec538e775443c5be79dd423fcabahrens String DATA_ROOT = env.getDataRootPath();
fa9e4066f08beec538e775443c5be79dd423fcabahrens throw new Exception("DATA_ROOT parameter is not configured in web.xml!");
fa9e4066f08beec538e775443c5be79dd423fcabahrens File data_root = new File(DATA_ROOT);
fa9e4066f08beec538e775443c5be79dd423fcabahrens throw new Exception("DATA_ROOT parameter in web.xml does not exist or is not a directory!");
fa9e4066f08beec538e775443c5be79dd423fcabahrens //String date = request.getParameter("date");
fa9e4066f08beec538e775443c5be79dd423fcabahrens //TODO merge paging hitsPerPage with parameter n (has to reflect the search if changed so proper number is cached first time)
fa9e4066f08beec538e775443c5be79dd423fcabahrens start = Integer.parseInt(request.getParameter("start")); //parse the max results first
fa9e4066f08beec538e775443c5be79dd423fcabahrens max = Integer.parseInt(request.getParameter("n")); //then the start index
fa9e4066f08beec538e775443c5be79dd423fcabahrens if(max < 0 || (max % 10 != 0) || max > 50) max = 25;
fa9e4066f08beec538e775443c5be79dd423fcabahrens if(start < 0 ) start = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens } catch (Exception e) { }
fa9e4066f08beec538e775443c5be79dd423fcabahrens qstr = Util.buildQueryString(q, defs, refs, path, hist);
fa9e4066f08beec538e775443c5be79dd423fcabahrens QueryParser qparser = new QueryParser("full", analyzer);
fa9e4066f08beec538e775443c5be79dd423fcabahrens qparser.setDefaultOperator(QueryParser.AND_OPERATOR);
fa9e4066f08beec538e775443c5be79dd423fcabahrens qparser.setAllowLeadingWildcard(env.isAllowLeadingWildcard());
fa9e4066f08beec538e775443c5be79dd423fcabahrens query = qparser.parse(qstr); //parse the
fa9e4066f08beec538e775443c5be79dd423fcabahrens File root = new File(RuntimeEnvironment.getInstance().getDataRootFile(),
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (RuntimeEnvironment.getInstance().hasProjects()) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (project == null) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens errorMsg = "<b>Error:</b> You must select a project!";
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (project.size() > 1) { //more projects
fa9e4066f08beec538e775443c5be79dd423fcabahrens IndexSearcher[] searchables = new IndexSearcher[project.size()];
fa9e4066f08beec538e775443c5be79dd423fcabahrens File droot = new File(RuntimeEnvironment.getInstance().getDataRootFile(), "index");
fa9e4066f08beec538e775443c5be79dd423fcabahrens int ii = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens //TODO might need to rewrite to Project instead of String , need changes in projects.jspf too
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (String proj : project) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens ireader = (IndexReader.open(new File(droot, proj)));
fa9e4066f08beec538e775443c5be79dd423fcabahrens searchables[ii++] = new IndexSearcher(ireader);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (Runtime.getRuntime().availableProcessors() > 1) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens searcher = new ParallelMultiSearcher(searchables);
fa9e4066f08beec538e775443c5be79dd423fcabahrens searcher = new MultiSearcher(searchables);
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else { // just 1 project selected
fa9e4066f08beec538e775443c5be79dd423fcabahrens root = new File(root, project.get(0));
fa9e4066f08beec538e775443c5be79dd423fcabahrens ireader = IndexReader.open(root);
fa9e4066f08beec538e775443c5be79dd423fcabahrens searcher = new IndexSearcher(ireader);
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else { //no project setup
fa9e4066f08beec538e775443c5be79dd423fcabahrens ireader = IndexReader.open(root);
fa9e4066f08beec538e775443c5be79dd423fcabahrens searcher = new IndexSearcher(ireader);
fa9e4066f08beec538e775443c5be79dd423fcabahrens //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 ;)
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (errorMsg == null) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens collector = new TopDocCollector(hitsPerPage*cachePages);
fa9e4066f08beec538e775443c5be79dd423fcabahrens Sort sortf = new Sort("date", true);
fa9e4066f08beec538e775443c5be79dd423fcabahrens TopFieldDocs fdocs=searcher.search(query, null,hitsPerPage*cachePages, sortf);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (start>=hitsPerPage*cachePages && !allCollected) { //fetch ALL results only if above cachePages
fa9e4066f08beec538e775443c5be79dd423fcabahrens fdocs=searcher.search(query, null, totalHits, sortf);
fa9e4066f08beec538e775443c5be79dd423fcabahrens allCollected=true;
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else if (BY_PATH.equals(sort)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens Sort sortf = new Sort(BY_PATH);
fa9e4066f08beec538e775443c5be79dd423fcabahrens TopFieldDocs fdocs=searcher.search(query, null,hitsPerPage*cachePages, sortf);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (start>=hitsPerPage*cachePages && !allCollected) { //fetch ALL results only if above cachePages
fa9e4066f08beec538e775443c5be79dd423fcabahrens fdocs=searcher.search(query, null,totalHits, sortf);
fa9e4066f08beec538e775443c5be79dd423fcabahrens allCollected=true;
fa9e4066f08beec538e775443c5be79dd423fcabahrens searcher.search(query,collector);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (start>=hitsPerPage*cachePages && !allCollected) { //fetch ALL results only if above cachePages
fa9e4066f08beec538e775443c5be79dd423fcabahrens collector = new TopDocCollector(totalHits);
fa9e4066f08beec538e775443c5be79dd423fcabahrens searcher.search(query,collector);
fa9e4066f08beec538e775443c5be79dd423fcabahrens allCollected=true;
fa9e4066f08beec538e775443c5be79dd423fcabahrens hits=collector.topDocs().scoreDocs;
fa9e4066f08beec538e775443c5be79dd423fcabahrens //below will get all the documents
fa9e4066f08beec538e775443c5be79dd423fcabahrens// for (int i = 0; i < hits.length; i++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens// int docId = hits[i].doc;
fa9e4066f08beec538e775443c5be79dd423fcabahrens// Document d = searcher.doc(docId);
fa9e4066f08beec538e775443c5be79dd423fcabahrens thispage = max;
fa9e4066f08beec538e775443c5be79dd423fcabahrens errorMsg = "<b>Error:</b> Too many results for wildcard!";
fa9e4066f08beec538e775443c5be79dd423fcabahrens } catch (ParseException e) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens errorMsg = "<b>Error parsing your query:</b><br/>" + Util.htmlize(qstr) +
fa9e4066f08beec538e775443c5be79dd423fcabahrens "<p/>You might try to enclose your search term in quotes: <br/>" +
fa9e4066f08beec538e775443c5be79dd423fcabahrens "<a href=search?q=\"" + Util.URIEncode(qstr) + "\">\"" + Util.htmlize(qstr) +
fa9e4066f08beec538e775443c5be79dd423fcabahrens "\"</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/>" +
fa9e4066f08beec538e775443c5be79dd423fcabahrens "Error message from parser:<br/>" + Util.htmlize(e.getMessage());
fa9e4066f08beec538e775443c5be79dd423fcabahrens } catch (FileNotFoundException e) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens errorMsg = "<b>Error:</b> Index database not found";
fa9e4066f08beec538e775443c5be79dd423fcabahrens } catch (Exception e) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens errorMsg = "<b>Error:</b> " + Util.htmlize(e.getMessage());
fa9e4066f08beec538e775443c5be79dd423fcabahrens // @TODO fix me. I should try to figure out where the exact hit is instead
fa9e4066f08beec538e775443c5be79dd423fcabahrens // of returning a page with just _one_ entry in....
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (hits != null && hits.length == 1 && request.getServletPath().equals("/s") && (query != null && query instanceof TermQuery)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens String preFragmentPath = Util.URIEncodePath(context + "/xref" + searcher.doc(hits[0].doc).get("path"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens String fragment = Util.URIEncode(((TermQuery)query).getTerm().text());
fa9e4066f08beec538e775443c5be79dd423fcabahrens StringBuilder url = new StringBuilder(preFragmentPath);
fa9e4066f08beec538e775443c5be79dd423fcabahrens String pageTitle = "Search";
fa9e4066f08beec538e775443c5be79dd423fcabahrens RuntimeEnvironment environment = RuntimeEnvironment.getInstance();
fa9e4066f08beec538e775443c5be79dd423fcabahrens %><%@ include file="httpheader.jspf" %>
fa9e4066f08beec538e775443c5be79dd423fcabahrens<div id="page">
fa9e4066f08beec538e775443c5be79dd423fcabahrens <div id="header"><%@ include file="pageheader.jspf" %></div>
fa9e4066f08beec538e775443c5be79dd423fcabahrens<div id="Masthead"></div>
fa9e4066f08beec538e775443c5be79dd423fcabahrens<div id="bar">
fa9e4066f08beec538e775443c5be79dd423fcabahrens <table border="0" width="100%"><tr><td><a href="<%=context%>" id="home">Home</a></td><td align="right"><%
fa9e4066f08beec538e775443c5be79dd423fcabahrens StringBuffer url = request.getRequestURL();
fa9e4066f08beec538e775443c5be79dd423fcabahrens String querys = request.getQueryString();
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (querys != null) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens int idx = querys.indexOf("sort=");
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (idx == -1) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens %>Sort by: <%
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (sort == null || RELEVANCY.equals(sort)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens %><b>relevance</b> | <a href="<%=url.toString()+LASTMODTIME%>">last modified time</a> | <a href="<%=url.toString()+BY_PATH%>">path</a><%
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else if (LASTMODTIME.equals(sort)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens %><a href="<%=url.toString()+RELEVANCY%>">relevance</a> | <b>last modified time</b> | <a href="<%=url.toString()+BY_PATH%>">path</a><%
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else if (BY_PATH.equals(sort)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens %><a href="<%=url.toString()+RELEVANCY%>">relevance</a> | <a href="<%=url.toString()+LASTMODTIME%>">last modified time</a> | <b>path</b><%
fa9e4066f08beec538e775443c5be79dd423fcabahrens %><a href="<%=url.toString()+RELEVANCY%>">relevance</a> | <a href="<%=url.toString()+LASTMODTIME%>">last modified time</a> | <a href="<%=url.toString()+BY_PATH%>">path</a><%
fa9e4066f08beec538e775443c5be79dd423fcabahrens } %></td></tr></table>
fa9e4066f08beec538e775443c5be79dd423fcabahrens<div id="menu">
fa9e4066f08beec538e775443c5be79dd423fcabahrens <%@ include file="menu.jspf"%>
fa9e4066f08beec538e775443c5be79dd423fcabahrens<div id="results">
fa9e4066f08beec538e775443c5be79dd423fcabahrens//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
fa9e4066f08beec538e775443c5be79dd423fcabahrensif( hits == null || errorMsg != null) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens %><%=errorMsg%><%
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else if (hits.length == 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens File spellIndex = new File(env.getDataRootPath(), "spellIndex");
fa9e4066f08beec538e775443c5be79dd423fcabahrens File[] spellIndexes=null;
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (RuntimeEnvironment.getInstance().hasProjects()) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (project.size() > 1) { //more projects
fa9e4066f08beec538e775443c5be79dd423fcabahrens spellIndexes = new File[project.size()];
fa9e4066f08beec538e775443c5be79dd423fcabahrens int ii = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens //TODO might need to rewrite to Project instead of String , need changes in projects.jspf too
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (String proj : project) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens spellIndexes[ii++] = new File(spellIndex,proj);
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else { // just 1 project selected
fa9e4066f08beec538e775443c5be79dd423fcabahrens spellIndex = new File(spellIndex, project.get(0));
fa9e4066f08beec538e775443c5be79dd423fcabahrens int count=1;
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (spellIndexes!=null) {count=spellIndexes.length;}
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (int idx = 0; idx < count; idx++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (spellIndexes!=null) spellIndex = spellIndexes[idx];
fa9e4066f08beec538e775443c5be79dd423fcabahrens FSDirectory spellDirectory = FSDirectory.getDirectory(spellIndex);
fa9e4066f08beec538e775443c5be79dd423fcabahrens SpellChecker checker = new SpellChecker(spellDirectory);
fa9e4066f08beec538e775443c5be79dd423fcabahrens Date sstart = new Date();
fa9e4066f08beec538e775443c5be79dd423fcabahrens boolean printHeader = true;
fa9e4066f08beec538e775443c5be79dd423fcabahrens String[] toks;
fa9e4066f08beec538e775443c5be79dd423fcabahrens if(q != null) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens toks = q.split("[\t ]+");
fa9e4066f08beec538e775443c5be79dd423fcabahrens if(toks != null){
fa9e4066f08beec538e775443c5be79dd423fcabahrens for(int j=0; j<toks.length; j++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if(toks[j].length() > 3) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 5);
fa9e4066f08beec538e775443c5be79dd423fcabahrens for(int i = 0;i < ret.length; i++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (printHeader) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens %><p><font color="#cc0000">Did you mean(for <%=spellIndex.getName()%>)</font>:<%
fa9e4066f08beec538e775443c5be79dd423fcabahrens printHeader = false;
fa9e4066f08beec538e775443c5be79dd423fcabahrens %> <a href=search?q=<%=ret[i]%>><%=ret[i]%></a> <%
fa9e4066f08beec538e775443c5be79dd423fcabahrens if(refs != null) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens toks = refs.split("[\t ]+");
fa9e4066f08beec538e775443c5be79dd423fcabahrens if(toks != null){
fa9e4066f08beec538e775443c5be79dd423fcabahrens for(int j=0; j<toks.length; j++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if(toks[j].length() > 3) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 5);
fa9e4066f08beec538e775443c5be79dd423fcabahrens for(int i = 0;i < ret.length; i++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (printHeader) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens %><p><font color="#cc0000">Did you mean(for <%=spellIndex.getName()%>)</font>:<%
fa9e4066f08beec538e775443c5be79dd423fcabahrens printHeader = false;
fa9e4066f08beec538e775443c5be79dd423fcabahrens %> <a href=search?refs=<%=ret[i]%>><%=ret[i]%></a> <%
fa9e4066f08beec538e775443c5be79dd423fcabahrens //TODO it seems the only true spellchecker is for below field, see IndexDatabase createspellingsuggestions ...
fa9e4066f08beec538e775443c5be79dd423fcabahrens if(defs != null) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens toks = defs.split("[\t ]+");
fa9e4066f08beec538e775443c5be79dd423fcabahrens if(toks != null){
fa9e4066f08beec538e775443c5be79dd423fcabahrens for(int j=0; j<toks.length; j++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if(toks[j].length() > 3) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 5);
fa9e4066f08beec538e775443c5be79dd423fcabahrens for(int i = 0;i < ret.length; i++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (printHeader) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens %><p><font color="#cc0000">Did you mean(for <%=spellIndex.getName()%>)</font>:<%
fa9e4066f08beec538e775443c5be79dd423fcabahrens printHeader = false;
fa9e4066f08beec538e775443c5be79dd423fcabahrens %> <a href=search?defs=<%=ret[i]%>><%=ret[i]%></a> <%
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (printHeader) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens %><p> Your search <b><%=query.toString()%></b> did not match any files.
fa9e4066f08beec538e775443c5be79dd423fcabahrens Suggestions:<br/><blockquote>- Make sure all terms are spelled correctly.<br/>
fa9e4066f08beec538e775443c5be79dd423fcabahrens - Try different keywords.<br/>
fa9e4066f08beec538e775443c5be79dd423fcabahrens - Try more general keywords.<br/>
fa9e4066f08beec538e775443c5be79dd423fcabahrens - Use 'wil*' cards if you are looking for partial match.
fa9e4066f08beec538e775443c5be79dd423fcabahrens </blockquote>
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else { // We have a lots of results to show
fa9e4066f08beec538e775443c5be79dd423fcabahrens StringBuilder slider = null;
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ( max < totalHits) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if((start + max) < totalHits) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens thispage = max;
fa9e4066f08beec538e775443c5be79dd423fcabahrens thispage = totalHits - start;
fa9e4066f08beec538e775443c5be79dd423fcabahrens String url = (q == null ? "" : "&q=" + Util.URIEncode(q) ) +
fa9e4066f08beec538e775443c5be79dd423fcabahrens (defs == null ? "" : "&defs=" + Util.URIEncode(defs)) +
fa9e4066f08beec538e775443c5be79dd423fcabahrens (refs == null ? "" : "&refs=" + Util.URIEncode(refs)) +
fa9e4066f08beec538e775443c5be79dd423fcabahrens (path == null ? "" : "&path=" + Util.URIEncode(path)) +
fa9e4066f08beec538e775443c5be79dd423fcabahrens (hist == null ? "" : "&hist=" + Util.URIEncode(hist)) +
fa9e4066f08beec538e775443c5be79dd423fcabahrens (sort == null ? "" : "&sort=" + Util.URIEncode(sort));
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (Iterator it = project.iterator(); it.hasNext();) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens url=url+(project == null ? "" : "&project=" + Util.URIEncode((String)it.next()));
fa9e4066f08beec538e775443c5be79dd423fcabahrens slider = new StringBuilder();
fa9e4066f08beec538e775443c5be79dd423fcabahrens int labelStart =1;
fa9e4066f08beec538e775443c5be79dd423fcabahrens int sstart = start - max* (start / max % 10 + 1) ;
fa9e4066f08beec538e775443c5be79dd423fcabahrens if(sstart < 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens sstart = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens labelStart = 1;
fa9e4066f08beec538e775443c5be79dd423fcabahrens labelStart = sstart/max + 1;
fa9e4066f08beec538e775443c5be79dd423fcabahrens int label = labelStart;
fa9e4066f08beec538e775443c5be79dd423fcabahrens int labelEnd = label + 11;
fa9e4066f08beec538e775443c5be79dd423fcabahrens String arr;
fa9e4066f08beec538e775443c5be79dd423fcabahrens for(int i=sstart; i<totalHits && label <= labelEnd; i+= max) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (i <= start && start < i+ max) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens slider.append("<span class=\"sel\">" + label + "</span>");
fa9e4066f08beec538e775443c5be79dd423fcabahrens if(label == labelStart && label != 1) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens arr = "<<";
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else if(label == labelEnd && i < totalHits) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens arr = ">>";
fa9e4066f08beec538e775443c5be79dd423fcabahrens arr = label < 10 ? " " + label : String.valueOf(label);
fa9e4066f08beec538e775443c5be79dd423fcabahrens slider.append("<a class=\"more\" href=\"search?n=" + max + "&start=" + i + url + "\">"+
fa9e4066f08beec538e775443c5be79dd423fcabahrens arr + "</a>");
fa9e4066f08beec538e775443c5be79dd423fcabahrens thispage = totalHits - start; // set the max index to max or last
fa9e4066f08beec538e775443c5be79dd423fcabahrens %> Searched <b><%=query.toString()%></b> (Results <b><%=start+1%> -
fa9e4066f08beec538e775443c5be79dd423fcabahrens <%=thispage+start%></b> of <b><%=totalHits%></b>) sorted by <%=sort%> <p><%=slider != null ?
fa9e4066f08beec538e775443c5be79dd423fcabahrens <table width="100%" cellpadding="3" cellspacing="0" border="0"><%
fa9e4066f08beec538e775443c5be79dd423fcabahrens Context sourceContext = null;
fa9e4066f08beec538e775443c5be79dd423fcabahrens Summarizer summer = null;
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (query != null) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens sourceContext = new Context(query);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if(sourceContext != null)
fa9e4066f08beec538e775443c5be79dd423fcabahrens summer = new Summarizer(query, analyzer);
fa9e4066f08beec538e775443c5be79dd423fcabahrens } catch (Exception e) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens HistoryContext historyContext = null;
fa9e4066f08beec538e775443c5be79dd423fcabahrens historyContext = new HistoryContext(query);
fa9e4066f08beec538e775443c5be79dd423fcabahrens } catch (Exception e) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens EftarFileReader ef = null;
fa9e4066f08beec538e775443c5be79dd423fcabahrens ef = new EftarFileReader(env.getDataRootPath() + "/index/dtags.eftar");
fa9e4066f08beec538e775443c5be79dd423fcabahrens } catch (Exception e) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens //TODO also fix the way what and how it is passed to prettyprint, can improve performance! SearchEngine integration is really needed here.
fa9e4066f08beec538e775443c5be79dd423fcabahrens Results.prettyPrintHTML(searcher,hits, start, start+thispage,
fa9e4066f08beec538e775443c5be79dd423fcabahrens sourceContext, historyContext, summer,
fa9e4066f08beec538e775443c5be79dd423fcabahrens context + "/xref",
fa9e4066f08beec538e775443c5be79dd423fcabahrens context + "/more",
fa9e4066f08beec538e775443c5be79dd423fcabahrens if(ef != null) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens } catch (IOException e) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens %></table><br/>
fa9e4066f08beec538e775443c5be79dd423fcabahrens <b> Completed in <%=(new Date()).getTime() - starttime.getTime()%> milliseconds </b> <br/>
fa9e4066f08beec538e775443c5be79dd423fcabahrens <%=slider != null ? "<p>" + slider + "</p>" : ""%>
fa9e4066f08beec538e775443c5be79dd423fcabahrens %><br/></div><%@include file="foot.jspf"%><%
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (ireader != null)
fa9e4066f08beec538e775443c5be79dd423fcabahrens} else { // Entry page show the map