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