Index: src/com/ecyrd/jspwiki/SearchMatcher.java =================================================================== --- src/com/ecyrd/jspwiki/SearchMatcher.java (revision 735653) +++ src/com/ecyrd/jspwiki/SearchMatcher.java (working copy) @@ -145,6 +145,7 @@ { int m_score; WikiPage m_page; + private String[] m_contexts; /** * Create a new SearchResult with a given name and a score. @@ -188,6 +189,17 @@ // Unimplemented return new String[0]; } + + /** + * Sets the m_contexts, although BasicSearchProvider does not support + * context matching. + * + * @return an empty array + */ + public void notAuthorized() + { + m_contexts = new String[]{"You are not authorized to view this content."}; + } } } Index: src/com/ecyrd/jspwiki/SearchResult.java =================================================================== --- src/com/ecyrd/jspwiki/SearchResult.java (revision 735653) +++ src/com/ecyrd/jspwiki/SearchResult.java (working copy) @@ -50,4 +50,10 @@ * @since 2.4 */ public String[] getContexts(); + + /* Prevent People from seeing relevant Information. + * @see com.ecyrd.jspwiki.SearchResult#notAuthorized() + */ + public void notAuthorized(); + } Index: src/com/ecyrd/jspwiki/WikiEngine.java =================================================================== --- src/com/ecyrd/jspwiki/WikiEngine.java (revision 735653) +++ src/com/ecyrd/jspwiki/WikiEngine.java (working copy) @@ -1837,12 +1837,37 @@ public Collection findPages( String query ) throws ProviderException, IOException { - Collection results = m_searchManager.findPages( query ); - - return results; + return findPages(query, -1, -1); } /** + * Parses an incoming search request, then + * does a search. + *

+ * The query is dependent on the actual chosen search provider - each one of them has + * a language of its own. + * + * @param query The query string + * @return A Collection of SearchResult objects. + * @throws ProviderException If the searching failed + * @throws IOException If the searching failed + */ + + // + // FIXME: Should also have attributes attached. + // + public Collection findPages( String query , int startSearchFrom ,int SearchItemAmount ) + throws ProviderException, IOException + { + StopWatch sw = new StopWatch(); + sw.start(); + Collection results = m_searchManager.findPages( query , startSearchFrom , SearchItemAmount); + sw.stop(); + log.info("The search for \"" + query + "\" lasted : " + sw.getTime()); + return results; + } + + /** * Finds the corresponding WikiPage object based on the page name. It always finds * the latest version of a page. * Index: src/com/ecyrd/jspwiki/search/BasicSearchProvider.java =================================================================== --- src/com/ecyrd/jspwiki/search/BasicSearchProvider.java (revision 735653) +++ src/com/ecyrd/jspwiki/search/BasicSearchProvider.java (working copy) @@ -168,6 +168,7 @@ return null; } + Iterator it = allPages.iterator(); while( it.hasNext() ) { @@ -203,11 +204,13 @@ /** * {@inheritDoc} */ - public Collection findPages(String query) - { - return findPages(parseQuery(query)); - } + public Collection findPages(String query) throws ProviderException, + IOException + { + return findPages(parseQuery(query)); + } + /** * {@inheritDoc} */ @@ -216,4 +219,13 @@ return "BasicSearchProvider"; } + + public Collection findPages(String query, int startShowFrom, int showAmount) + throws ProviderException, IOException + { + //There is no need to sort the results because he needs to go over every page anymway + return findPages(parseQuery(query)); + } + + } Index: src/com/ecyrd/jspwiki/search/LuceneSearchProvider.java =================================================================== --- src/com/ecyrd/jspwiki/search/LuceneSearchProvider.java (revision 735653) +++ src/com/ecyrd/jspwiki/search/LuceneSearchProvider.java (working copy) @@ -1,27 +1,37 @@ /* - JSPWiki - a JSP-based WikiWiki clone. +JSPWiki - a JSP-based WikiWiki clone. - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at +Copyright (C) 2005 Janne Jalkanen (Janne.Jalkanen@iki.fi) - http://www.apache.org/licenses/LICENSE-2.0 +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ package com.ecyrd.jspwiki.search; -import java.io.*; -import java.util.*; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.Date; +import java.util.Iterator; +import java.util.Properties; +import java.util.Vector; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; @@ -46,7 +56,17 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; -import com.ecyrd.jspwiki.*; +import pl.com.pbpolsoft.wiki.util.attachment.ReadableAttachmentProvider; +import pl.com.pbpolsoft.wiki.util.attachment.ReadableAttachmentProviderFactory; + +import com.ecyrd.jspwiki.FileUtil; +import com.ecyrd.jspwiki.InternalWikiException; +import com.ecyrd.jspwiki.NoRequiredPropertyException; +import com.ecyrd.jspwiki.SearchResult; +import com.ecyrd.jspwiki.TextUtil; +import com.ecyrd.jspwiki.WikiEngine; +import com.ecyrd.jspwiki.WikiPage; +import com.ecyrd.jspwiki.WikiProvider; import com.ecyrd.jspwiki.attachment.Attachment; import com.ecyrd.jspwiki.attachment.AttachmentManager; import com.ecyrd.jspwiki.parser.MarkupParser; @@ -59,10 +79,10 @@ /** * Interface for the search providers that handle searching the Wiki * - * @author Arent-Jan Banck + * @author Arent-Jan Banck for Informatica * @since 2.2.21. */ -public class LuceneSearchProvider implements SearchProvider +public class LuceneSearchProvider implements SearchProvider { protected static final Logger log = Logger.getLogger(LuceneSearchProvider.class); @@ -75,7 +95,7 @@ private static final String PROP_LUCENE_INDEXDELAY = "jspwiki.lucene.indexdelay"; private static final String PROP_LUCENE_INITIALDELAY = "jspwiki.lucene.initialdelay"; - + private String m_analyzerClass = "org.apache.lucene.analysis.standard.StandardAnalyzer"; private static final String LUCENE_DIR = "lucene"; @@ -92,10 +112,11 @@ private String m_luceneDirectory = null; private int m_updateCount = 0; - protected Vector m_updates = new Vector(); // Vector because multi-threaded. - + protected Vector m_updates = new Vector(); // Vector because multi-threaded. + /** Maximum number of fragments from search matches. */ private static final int MAX_FRAGMENTS = 3; + private static String c_punctuationSpaces = StringUtils.repeat(" ", MarkupParser.PUNCTUATION_CHARS_ALLOWED.length() ); @@ -103,7 +124,7 @@ * {@inheritDoc} */ public void initialize(WikiEngine engine, Properties props) - throws NoRequiredPropertyException, IOException + throws NoRequiredPropertyException, IOException { m_engine = engine; @@ -111,7 +132,7 @@ int initialDelay = TextUtil.getIntegerProperty( props, PROP_LUCENE_INITIALDELAY, LuceneUpdater.INITIAL_DELAY ); int indexDelay = TextUtil.getIntegerProperty( props, PROP_LUCENE_INDEXDELAY, LuceneUpdater.INDEX_DELAY ); - + m_analyzerClass = TextUtil.getStringProperty( props, PROP_LUCENE_ANALYZER, m_analyzerClass ); // FIXME: Just to be simple for now, we will do full reindex // only if no files are in lucene directory. @@ -171,9 +192,9 @@ throws IOException { File dir = new File(m_luceneDirectory); - + String[] filelist = dir.list(); - + if( filelist == null ) { throw new IOException( "Invalid Lucene directory: cannot produce listing: "+dir.getAbsolutePath()); @@ -212,33 +233,24 @@ for( Iterator iterator = allPages.iterator(); iterator.hasNext(); ) { WikiPage page = (WikiPage) iterator.next(); - - try - { - String text = m_engine.getPageManager().getPageText( page.getName(), - WikiProvider.LATEST_VERSION ); - luceneIndexPage( page, text, writer ); - } - catch( IOException e ) - { - log.warn( "Unable to index page " + page.getName() + ", continuing to next ", e ); - } + String text = m_engine.getPageManager().getPageText( page.getName(), + WikiProvider.LATEST_VERSION ); + luceneIndexPage( page, text, writer ); } Collection allAttachments = m_engine.getAttachmentManager().getAllAttachments(); for( Iterator iterator = allAttachments.iterator(); iterator.hasNext(); ) { Attachment att = (Attachment) iterator.next(); - try { - String text = getAttachmentContent( att.getName(), - WikiProvider.LATEST_VERSION ); + String text = getAttachmentContent( att.getName(), WikiProvider.LATEST_VERSION ); luceneIndexPage( att, text, writer ); } - catch( IOException e ) + catch (Throwable t) { - log.warn( "Unable to index attachment " + att.getName() + ", continuing to next", e ); + //goto next Attachment iterator + log.error("Error on indexing file " + att.getFileName(), t); } } @@ -283,32 +295,27 @@ { log.error("Unable to start lucene",e); } - + } /** * Fetches the attachment content from the repository. * Content is flat text that can be used for indexing/searching or display - * - * @param attachmentName Name of the attachment. - * @param version The version of the attachment. - * - * @return the content of the Attachment as a String. */ protected String getAttachmentContent( String attachmentName, int version ) { AttachmentManager mgr = m_engine.getAttachmentManager(); - - try + + try { Attachment att = mgr.getAttachmentInfo( attachmentName, version ); //FIXME: Find out why sometimes att is null if(att != null) { - return getAttachmentContent( att ); + return getAttachmentContent( att ); } - } - catch (ProviderException e) + } + catch (ProviderException e) { log.error("Attachment cannot be loaded", e); } @@ -320,26 +327,47 @@ * @param att Attachment to get content for. Filename extension is used to determine the type of the attachment. * @return String representing the content of the file. * FIXME This is a very simple implementation of some text-based attachment, mainly used for testing. - * This should be replaced /moved to Attachment search providers or some other 'plugable' wat to search attachments + * This should be replaced /moved to Attachment search providers or some other 'plugable' wat to search attachments */ protected String getAttachmentContent( Attachment att ) { AttachmentManager mgr = m_engine.getAttachmentManager(); //FIXME: Add attachment plugin structure - + String filename = att.getFileName(); + if(filename.endsWith(".txt") || filename.endsWith(".xml") || filename.endsWith(".ini") || + filename.endsWith(".doc") || + filename.endsWith(".xls") || + filename.endsWith(".ppt") || + filename.endsWith(".pdf") || filename.endsWith(".html")) { + + InputStream attStream; - - try + + try { + ReadableAttachmentProvider attProvider = ReadableAttachmentProviderFactory.getProvider(filename); attStream = mgr.getAttachmentStream( att ); + + log.debug("Start getting content of " + filename + " of Page " + att.getParentName() ); + if(attProvider != null) { + log.debug("Attachment provider: " + attProvider ); + attProvider.setContents(attStream); + log.debug("Finish read " + filename); + String readableAttachment = attProvider.getReadableContents(); + + attStream.close(); + return readableAttachment; + + } + StringWriter sout = new StringWriter(); FileUtil.copyContents( new InputStreamReader(attStream), sout ); @@ -347,13 +375,13 @@ sout.close(); return sout.toString(); - } - catch (ProviderException e) + } + catch (ProviderException e) { log.error("Attachment cannot be loaded", e); return null; - } - catch (IOException e) + } + catch (IOException e) { log.error("Attachment cannot be loaded", e); return null; @@ -432,19 +460,18 @@ protected Document luceneIndexPage( WikiPage page, String text, IndexWriter writer ) throws IOException { - if( log.isDebugEnabled() ) log.debug( "Indexing "+page.getName()+"..." ); - // make a new, empty document Document doc = new Document(); if( text == null ) return doc; + //System.out.println("Test"); // Raw name is the keyword we'll use to refer to this document for updates. Field field = new Field(LUCENE_ID, page.getName(), Field.Store.YES, Field.Index.UN_TOKENIZED); doc.add( field ); // Body text. It is stored in the doc for search contexts. - field = new Field(LUCENE_PAGE_CONTENTS, text, + field = new Field(LUCENE_PAGE_CONTENTS, text, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO); doc.add( field ); @@ -459,31 +486,31 @@ doc.add( field ); // Allow searching by authorname - + if( page.getAuthor() != null ) { - field = new Field(LUCENE_AUTHOR, page.getAuthor(), + field = new Field(LUCENE_AUTHOR, page.getAuthor(), Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO); doc.add( field ); } // Now add the names of the attachments of this page - try + try { Collection attachments = m_engine.getAttachmentManager().listAttachments(page); String attachmentNames = ""; - + for( Iterator it = attachments.iterator(); it.hasNext(); ) { Attachment att = (Attachment) it.next(); attachmentNames += att.getName() + ";"; } - field = new Field(LUCENE_ATTACHMENTS, attachmentNames, + field = new Field(LUCENE_ATTACHMENTS, attachmentNames, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO); doc.add( field ); - } - catch(ProviderException e) + } + catch(ProviderException e) { // Unable to read attachments log.error("Failed to get attachments for page", e); @@ -527,13 +554,13 @@ if( page instanceof Attachment ) { - text = getAttachmentContent( (Attachment) page ); + text = getAttachmentContent( (Attachment) page ); } else { text = m_engine.getPureText( page ); } - + if( text != null ) { // Add work item to m_updates queue. @@ -552,15 +579,40 @@ public Collection findPages( String query ) throws ProviderException { - return findPages( query, FLAG_CONTEXTS ); + return findPages( query, FLAG_CONTEXTS, -1 , -1 ); } + public Collection findPages( String query, int flags ) + throws ProviderException + { + return findPages( query, flags, -1 , -1 ); + } /** + * {@inheritDoc} + */ + public Collection findPages( String query , int Showfrom, int ShowAmount) + throws ProviderException + { + return findPages( query, FLAG_CONTEXTS, Showfrom , ShowAmount ); + } + + + + /** * Create contexts also. Generating contexts can be expensive, * so they're not on by default. */ public static final int FLAG_CONTEXTS = 0x01; - + + public class SearchResultSort implements Comparator + { + public int compare(SearchResult o1, SearchResult o2) + { + System.out.println(((Integer)o1.getScore()).compareTo(((Integer)o2.getScore()))); + return ((Integer)o1.getScore()).compareTo(((Integer)o2.getScore())); + } + } + /** * Searches pages using a particular combination of flags. * @@ -569,11 +621,11 @@ * @return A Collection of SearchResult instances * @throws ProviderException if there is a problem with the backend */ - public Collection findPages( String query, int flags ) + public Collection findPages( String query, int flags , int Showfrom, int ShowAmount) throws ProviderException { Searcher searcher = null; - ArrayList list = null; + ArrayList list = null; Highlighter highlighter = null; try @@ -600,11 +652,16 @@ log.info("Lucene not yet ready; indexing not started",ex); return null; } - Hits hits = searcher.search(luceneQuery); + list = new ArrayList(hits.length()); - list = new ArrayList(hits.length()); - for ( int curr = 0; curr < hits.length(); curr++ ) + + boolean showAllFragments = (ShowAmount > -1) ? false : true; + int fragmentsFrom = showAllFragments ? 0 : Showfrom; + int fragmentsTo = showAllFragments ? hits.length() : Showfrom + ShowAmount; + + + for ( int curr = 0 ; curr < hits.length(); curr++ ) { Document doc = hits.doc(curr); String pageName = doc.get(LUCENE_ID); @@ -624,24 +681,28 @@ // Get highlighted search contexts String text = doc.get(LUCENE_PAGE_CONTENTS); + String[] fragments = new String[0]; - if( text != null && highlighter != null ) + + //Check for values + if (curr >= fragmentsFrom && curr < fragmentsTo) { - TokenStream tokenStream = getLuceneAnalyzer() - .tokenStream(LUCENE_PAGE_CONTENTS, new StringReader(text)); - fragments = highlighter.getBestFragments(tokenStream, - text, MAX_FRAGMENTS); - + if( text != null && highlighter != null) + { + TokenStream tokenStream = getLuceneAnalyzer().tokenStream(LUCENE_PAGE_CONTENTS, new StringReader(text)); + fragments = highlighter.getBestFragments(tokenStream, text, MAX_FRAGMENTS); + + } } - SearchResult result = new SearchResultImpl( page, score, fragments ); + SearchResult result = new SearchResultImpl( page, score, fragments ); list.add(result); } else { log.error("Lucene found a result page '" + pageName + "' that could not be loaded, removing from Lucene cache"); pageRemoved(new WikiPage( m_engine, pageName )); - } + } } } catch( IOException e ) @@ -695,7 +756,7 @@ */ private static final class LuceneUpdater extends WikiBackgroundThread { - protected static final int INDEX_DELAY = 5; + protected static final int INDEX_DELAY = 1; protected static final int INITIAL_DELAY = 60; private final LuceneSearchProvider m_provider; @@ -739,7 +800,7 @@ { while( m_provider.m_updates.size() > 0 ) { - Object[] pair = m_provider.m_updates.remove(0); + Object[] pair = ( Object[] ) m_provider.m_updates.remove(0); WikiPage page = ( WikiPage ) pair[0]; String text = ( String ) pair[1]; m_provider.updateLuceneIndex(page, text); @@ -784,5 +845,21 @@ { return m_contexts; } + + /* Prevent People from seeing relevant Information. + * @see com.ecyrd.jspwiki.SearchResult#notAuthorized() + */ + + public void notAuthorized() + { + m_contexts[0] = "You are not authorized to view this content."; + if (m_contexts.length > 1) + { + for (int i = 1; i < m_contexts.length; i++) + { + m_contexts[i] = ""; + } + } + } } } Index: src/com/ecyrd/jspwiki/search/SearchManager.java =================================================================== --- src/com/ecyrd/jspwiki/search/SearchManager.java (revision 735653) +++ src/com/ecyrd/jspwiki/search/SearchManager.java (working copy) @@ -298,12 +298,27 @@ public Collection findPages( String query ) throws ProviderException, IOException { + return findPages( query , -1, -1 ); + } + + /** + * Sends a search to the current search provider. The query is is whatever native format + * the query engine wants to use. + * + * @param query The query. Null is safe, and is interpreted as an empty query. + * @return A collection of WikiPages that matched. + * @throws ProviderException If the provider fails and a search cannot be completed. + * @throws IOException If something else goes wrong. + */ + public Collection findPages( String query ,int startSearchFrom ,int SearchItemAmount ) + throws ProviderException, IOException + { if( query == null ) query = ""; - Collection c = m_searchProvider.findPages( query ); + Collection c = m_searchProvider.findPages( query , startSearchFrom , SearchItemAmount); return c; - } - + } + /** * Removes the page from the search cache (if any). * @param page The page to remove Index: src/com/ecyrd/jspwiki/search/SearchProvider.java =================================================================== --- src/com/ecyrd/jspwiki/search/SearchProvider.java (revision 735653) +++ src/com/ecyrd/jspwiki/search/SearchProvider.java (working copy) @@ -58,4 +58,15 @@ * @throws IOException if for some reason the query could not be executed. */ public Collection findPages(String query) throws ProviderException, IOException; + + /** + * Search for pages matching a search query + * @param query query to search for + * @param startShowFrom Fragments that needed to be shown + * @param showAmount how many Fragments should be shown + * @return collection of pages that match query + * @throws ProviderException if the search provider failed. + * @throws IOException if for some reason the query could not be executed. + */ + public Collection findPages(String query, int startShowFrom, int showAmount ) throws ProviderException, IOException; } Index: src/webdocs/Search.jsp =================================================================== --- src/webdocs/Search.jsp (revision 735653) +++ src/webdocs/Search.jsp (working copy) @@ -2,6 +2,7 @@ <%@ page import="com.ecyrd.jspwiki.*" %> <%@ page import="com.ecyrd.jspwiki.auth.*" %> <%@ page import="com.ecyrd.jspwiki.auth.permissions.*" %> +<%@ page import="org.apache.commons.lang.time.StopWatch" %> <%@ page import="java.util.*" %> <%@ page errorPage="/Error.jsp" %> <%@ taglib uri="/WEB-INF/jspwiki.tld" prefix="wiki" %> @@ -21,21 +22,28 @@ Collection list = null; String query = request.getParameter( "query"); String go = request.getParameter("go"); + + int start = (request.getParameter( "start") != null) ? Integer.parseInt(request.getParameter("start")) : 0; + int maxitems = (request.getParameter( "maxitems") != null) ? Integer.parseInt(request.getParameter("maxitems")) : 20; if( query != null ) { log.info("Searching for string "+query); + ArrayList filteredList = new ArrayList(); try { - list = wiki.findPages( query ); + StopWatch sw = new StopWatch(); + sw.start(); + list = wiki.findPages( query , start, maxitems ); + sw.stop(); + log.info("The search lasted : "+ sw.getTime() + " ms"); // // Filter down to only those that we actually have a permission to view // AuthorizationManager mgr = wiki.getAuthorizationManager(); - ArrayList filteredList = new ArrayList(); for( Iterator i = list.iterator(); i.hasNext(); ) { @@ -47,11 +55,13 @@ try { - if( mgr.checkPermission( wikiContext.getWikiSession(), pp ) ) + //Show all Pages containing content but not the content itself unless the user authorizes himself + if( !mgr.checkPermission( wikiContext.getWikiSession(), pp ) ) { - filteredList.add( r ); + r.notAuthorized(); } - } + filteredList.add( r ); + } catch( Exception e ) { log.error( "Searching for page "+p, e ); } } @@ -75,9 +85,9 @@ // if( go != null ) { - if( list != null && list.size() > 0 ) + if( filteredList != null && filteredList.size() > 0 ) { - SearchResult sr = (SearchResult) list.iterator().next(); + SearchResult sr = (SearchResult) filteredList.iterator().next(); WikiPage wikiPage = sr.getPage(); Index: src/webdocs/templates/default/AJAXSearch.jsp =================================================================== --- src/webdocs/templates/default/AJAXSearch.jsp (revision 735653) +++ src/webdocs/templates/default/AJAXSearch.jsp (working copy) @@ -1,4 +1,5 @@ <%@ taglib uri="/WEB-INF/jspwiki.tld" prefix="wiki" %> +<%@ taglib uri="/WEB-INF/owiki.tld" prefix="owiki" %> <%@ page language="java" pageEncoding="UTF-8"%> <%@ page import="org.apache.log4j.*" %> <%@ page import="com.ecyrd.jspwiki.*" %> @@ -9,6 +10,7 @@ <%@ page import="java.net.URLEncoder" %> <%@ page import="com.ecyrd.jspwiki.auth.*" %> <%@ page import="com.ecyrd.jspwiki.auth.permissions.*" %> +<%@ page import="org.apache.commons.lang.time.StopWatch" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <%@ page import="javax.servlet.jsp.jstl.fmt.*" %> @@ -23,62 +25,78 @@ WikiEngine wiki; %> <% - /* ********************* actual start ********************* */ + +int startitem = 0; // first item to show +int maxitems = 20; // number of items to show in result + +String parm_start = request.getParameter( "start"); +if( parm_start != null ) startitem = Integer.parseInt( parm_start ) ; + + +/* ********************* actual start ********************* */ /* FIXME: too much hackin on this level -- should better happen in toplevel jsp's */ /* Create wiki context and check for authorization */ WikiContext wikiContext = wiki.createContext( request, WikiContext.FIND ); if(!wikiContext.hasAccess( response )) return; - String query = request.getParameter( "query"); + + ArrayList filteredList = new ArrayList(); + //Read result from Request to prevent doble search + filteredList = (ArrayList) pageContext.getAttribute("searchresults", PageContext.REQUEST_SCOPE); - if( (query != null) && ( !query.trim().equals("") ) ) + if( startitem == -1 ) maxitems = filteredList.size(); //show all + + if (filteredList == null) { - try - { - Collection list = wiki.findPages( query ); - - // Filter down to only those that we actually have a permission to view - AuthorizationManager mgr = wiki.getAuthorizationManager(); - ArrayList items = new ArrayList(); - - for( Iterator i = list.iterator(); i.hasNext(); ) - { - SearchResult r = (SearchResult)i.next(); - - WikiPage p = r.getPage(); - - PagePermission pp = new PagePermission( p, PagePermission.VIEW_ACTION ); + String query = request.getParameter( "query"); + + if( (query != null) && ( !query.trim().equals("") ) ) + { + try + { + Collection list = wiki.findPages( query , startitem, maxitems ); - try - { - if( mgr.checkPermission( wikiContext.getWikiSession(), pp ) ) - { - items.add( r ); - } - } - catch( Exception e ) { log.error( "Searching for page "+p, e ); } - } - - pageContext.setAttribute( "searchresults", items, PageContext.REQUEST_SCOPE ); - } - catch( Exception e ) - { - wikiContext.getWikiSession().addMessage( e.getMessage() ); - } + // Filter down to only those that we actually have a permission to view + AuthorizationManager mgr = wiki.getAuthorizationManager(); + + ArrayList unordered = new ArrayList(); + + for( Iterator i = list.iterator(); i.hasNext(); ) + { + SearchResult r = (SearchResult)i.next(); + + WikiPage p = r.getPage(); + + PagePermission pp = new PagePermission( p, PagePermission.VIEW_ACTION ); + + System.out.println(p.getName() +" Permission " + mgr.checkPermission( wikiContext.getWikiSession(), pp )); + try + { + //Show all Pages containing content but not the content itself unless the user authorizes himself + if( !mgr.checkPermission( wikiContext.getWikiSession(), pp ) ) + { + r.notAuthorized(); + } + unordered.add( r ); + } + catch( Exception e ) + { + log.error( "Searching for page " + p, e ); + } + } + filteredList = unordered; + + pageContext.setAttribute( "searchresults", filteredList, PageContext.REQUEST_SCOPE ); + } + catch( Exception e ) + { + wikiContext.getWikiSession().addMessage( e.getMessage() ); + } + } } %> -<% - int startitem = 0; // first item to show - int maxitems = 20; // number of items to show in result - String parm_start = request.getParameter( "start"); - if( parm_start != null ) startitem = Integer.parseInt( parm_start ) ; - - Collection list = (Collection)pageContext.getAttribute( "searchresults", PageContext.REQUEST_SCOPE ); - if( startitem == -1 ) maxitems = list.size(); //show all -%> -

@@ -96,7 +114,7 @@ target="_blank">Wikipedia

-