Index: src/com/ecyrd/jspwiki/search/BasicSearchProvider.java
===================================================================
--- src/com/ecyrd/jspwiki/search/BasicSearchProvider.java (revision 744053)
+++ src/com/ecyrd/jspwiki/search/BasicSearchProvider.java (working copy)
@@ -21,21 +21,11 @@
package com.ecyrd.jspwiki.search;
import java.io.IOException;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Properties;
-import java.util.StringTokenizer;
-import java.util.TreeSet;
+import java.util.*;
import org.apache.log4j.Logger;
-import com.ecyrd.jspwiki.NoRequiredPropertyException;
-import com.ecyrd.jspwiki.QueryItem;
-import com.ecyrd.jspwiki.SearchMatcher;
-import com.ecyrd.jspwiki.SearchResult;
-import com.ecyrd.jspwiki.SearchResultComparator;
-import com.ecyrd.jspwiki.WikiEngine;
-import com.ecyrd.jspwiki.WikiPage;
+import com.ecyrd.jspwiki.*;
import com.ecyrd.jspwiki.attachment.Attachment;
import com.ecyrd.jspwiki.providers.ProviderException;
import com.ecyrd.jspwiki.providers.WikiPageProvider;
@@ -203,7 +193,7 @@
/**
* {@inheritDoc}
*/
- public Collection findPages(String query)
+ public Collection> findPages(String query)
{
return findPages(parseQuery(query));
}
@@ -216,4 +206,15 @@
return "BasicSearchProvider";
}
+ /**
+ * {@inheritDoc}
+ */
+ public Collection findPages( String query, int showSearchDetailsFrom, int numberOfSearchItems )
+ throws ProviderException, IOException
+ {
+ if (query == null)
+ query = "";
+ return findPages(parseQuery(query));
+ }
+
}
Index: src/com/ecyrd/jspwiki/search/LuceneSearchProvider.java
===================================================================
--- src/com/ecyrd/jspwiki/search/LuceneSearchProvider.java (revision 744053)
+++ src/com/ecyrd/jspwiki/search/LuceneSearchProvider.java (working copy)
@@ -548,9 +548,10 @@
/**
* {@inheritDoc}
+ * @throws IOException
*/
public Collection findPages( String query )
- throws ProviderException
+ throws ProviderException, IOException
{
return findPages( query, FLAG_CONTEXTS );
}
@@ -568,10 +569,40 @@
* @param flags A set of flags
* @return A Collection of SearchResult instances
* @throws ProviderException if there is a problem with the backend
- */
+ * @throws IOException
+ *
+ */
public Collection findPages( String query, int flags )
- throws ProviderException
+ throws ProviderException, IOException
{
+ return findPages( query, flags, -1 , -1 );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+
+
+ public Collection findPages( String query , int showSearchDetailsFrom, int numberOfSearchItems)
+ throws ProviderException, IOException
+ {
+ return findPages( query, FLAG_CONTEXTS, showSearchDetailsFrom ,numberOfSearchItems );
+ }
+ /**
+ * 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.
+ * @param flags A set of flags
+ * @param showSearchDetailsFrom determines from which index of the searchResult-Collection there will be detailed information
+ * @param numberOfSearchItems determines how many items beginning from showSearchDetails will get detailed information
+ * @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 flags , int showSearchDetailsFrom, int numberOfSearchItems)
+ throws ProviderException, IOException
+ {
Searcher searcher = null;
ArrayList list = null;
Highlighter highlighter = null;
@@ -603,6 +634,10 @@
Hits hits = searcher.search(luceneQuery);
+ boolean showAllFragments = (numberOfSearchItems > -1) ? false : true;
+ int fragmentsFrom = showAllFragments ? 0 : showSearchDetailsFrom;
+ int fragmentsTo = showAllFragments ? hits.length() : showSearchDetailsFrom + numberOfSearchItems;
+
list = new ArrayList(hits.length());
for ( int curr = 0; curr < hits.length(); curr++ )
{
@@ -620,18 +655,21 @@
int score = (int)(hits.score(curr) * 100);
-
// 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 );
Index: src/com/ecyrd/jspwiki/search/SearchManager.java
===================================================================
--- src/com/ecyrd/jspwiki/search/SearchManager.java (revision 744053)
+++ src/com/ecyrd/jspwiki/search/SearchManager.java (working copy)
@@ -27,6 +27,7 @@
import org.apache.log4j.Logger;
import com.ecyrd.jspwiki.*;
+import com.ecyrd.jspwiki.SearchMatcher.SearchResultImpl;
import com.ecyrd.jspwiki.event.WikiEvent;
import com.ecyrd.jspwiki.event.WikiEventListener;
import com.ecyrd.jspwiki.event.WikiEventUtils;
@@ -298,11 +299,35 @@
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.
+ * @param showSearchDetailsFrom determines from which index of the searchResult-Collection there will be detailed information
+ * @param numberOfSearchItems determines how many items beginning from showSearchDetails will get detailed information
+ *
+ * @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 showSearchDetailsFrom ,int numberOfSearchItems )
+ throws ProviderException, IOException
+ {
if( query == null ) query = "";
- Collection c = m_searchProvider.findPages( query );
+
+ StopWatch searchSW = new StopWatch();
+ searchSW.start();
+ Collection> c = m_searchProvider.findPages( query , showSearchDetailsFrom , numberOfSearchItems);
+ searchSW.stop();
+ log.info("The search for \"" + query + "\" lasted : " + searchSW.getTime());
return c;
- }
+ }
/**
* Removes the page from the search cache (if any).
Index: src/com/ecyrd/jspwiki/search/SearchProvider.java
===================================================================
--- src/com/ecyrd/jspwiki/search/SearchProvider.java (revision 744053)
+++ src/com/ecyrd/jspwiki/search/SearchProvider.java (working copy)
@@ -58,4 +58,19 @@
* @throws IOException if for some reason the query could not be executed.
*/
public Collection findPages(String query) throws ProviderException, IOException;
+
+ /**
+ * 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.
+ * @param showSearchDetailsFrom determines from which index of the searchResult-Collection there will be detailed information
+ * @param numberOfSearchItems determines how many items beginning from showSearchDetails will get detailed information
+ * @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 showSearchDetailsFrom, int numberOfSearchItems ) throws ProviderException, IOException;
+
}
Index: src/webdocs/Search.jsp
===================================================================
--- src/webdocs/Search.jsp (revision 744053)
+++ src/webdocs/Search.jsp (working copy)
@@ -2,8 +2,10 @@
<%@ page import="com.ecyrd.jspwiki.*" %>
<%@ page import="com.ecyrd.jspwiki.auth.*" %>
<%@ page import="com.ecyrd.jspwiki.auth.permissions.*" %>
+<%@ page import="com.ecyrd.jspwiki.search.SearchManager" %>
<%@ page import="java.util.*" %>
<%@ page errorPage="/Error.jsp" %>
+<%@ page import="org.apache.commons.lang.time.StopWatch" %>
<%@ taglib uri="/WEB-INF/jspwiki.tld" prefix="wiki" %>
<%!
@@ -21,14 +23,18 @@
Collection list = null;
String query = request.getParameter( "query");
String go = request.getParameter("go");
+
+ int startItem = (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);
+ log.info("Searching for string " + query);
try
{
- list = wiki.findPages( query );
+ SearchManager searchMgr = wiki.getSearchManager();
+ list = searchMgr.findPages(query , startItem, maxItems);
//
// Filter down to only those that we actually have a permission to view
Index: src/webdocs/templates/default/AJAXSearch.jsp
===================================================================
--- src/webdocs/templates/default/AJAXSearch.jsp (revision 744053)
+++ src/webdocs/templates/default/AJAXSearch.jsp (working copy)
@@ -9,6 +9,7 @@
<%@ page import="java.net.URLEncoder" %>
<%@ page import="com.ecyrd.jspwiki.auth.*" %>
<%@ page import="com.ecyrd.jspwiki.auth.permissions.*" %>
+<%@ page import="com.ecyrd.jspwiki.search.SearchManager" %>
<%@ 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 +24,73 @@
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
+
+ //Query only if there isn“t already a filtered list (coming from search.jsp)
+ 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();
+ String query = request.getParameter( "query");
- for( Iterator i = list.iterator(); i.hasNext(); )
- {
- SearchResult r = (SearchResult)i.next();
-
- WikiPage p = r.getPage();
-
- PagePermission pp = new PagePermission( p, PagePermission.VIEW_ACTION );
-
- 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() );
- }
+ if( (query != null) && ( !query.trim().equals("") ) )
+ {
+ try
+ {
+ SearchManager searchMgr = wiki.getSearchManager();
+ Collection list = searchMgr.findPages(query , startItem, maxItems);
+
+ // 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 );
+
+ try
+ {
+ if( mgr.checkPermission( wikiContext.getWikiSession(), pp ) )
+ {
+ items.add( r );
+ }
+ }
+ catch( Exception e ) { log.error( "Searching for page "+p, e ); }
+ }
+
+ filteredList = items;
+
+ 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 +108,7 @@
target="_blank">Wikipedia
-
@@ -109,7 +121,7 @@
|
-
+
|
<%= searchref.getScore() %> |