001/* 002 Licensed to the Apache Software Foundation (ASF) under one 003 or more contributor license agreements. See the NOTICE file 004 distributed with this work for additional information 005 regarding copyright ownership. The ASF licenses this file 006 to you under the Apache License, Version 2.0 (the 007 "License"); you may not use this file except in compliance 008 with the License. You may obtain a copy of the License at 009 010 http://www.apache.org/licenses/LICENSE-2.0 011 012 Unless required by applicable law or agreed to in writing, 013 software distributed under the License is distributed on an 014 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 KIND, either express or implied. See the License for the 016 specific language governing permissions and limitations 017 under the License. 018 */ 019package org.apache.wiki.search; 020 021import org.apache.wiki.api.core.Context; 022import org.apache.wiki.api.core.Page; 023import org.apache.wiki.api.exceptions.ProviderException; 024import org.apache.wiki.api.filters.PageFilter; 025import org.apache.wiki.api.search.SearchResult; 026import org.apache.wiki.event.WikiEventListener; 027import org.apache.wiki.modules.InternalModule; 028 029import java.io.IOException; 030import java.util.Collection; 031 032 033/** 034 * Manages searching the Wiki. 035 * 036 * @since 2.2.21. 037 */ 038public interface SearchManager extends PageFilter, InternalModule, WikiEventListener { 039 040 String DEFAULT_SEARCHPROVIDER = "org.apache.wiki.search.LuceneSearchProvider"; 041 042 /** Property name for setting the search provider. Value is <tt>{@value}</tt>. */ 043 String PROP_SEARCHPROVIDER = "jspwiki.searchProvider"; 044 045 /** The name of the JSON object that manages search. */ 046 String JSON_SEARCH = "search"; 047 048 /** the name of the Plugin discovery endpoint */ 049 String PLUGIN_SEARCH = "plugins"; 050 051 /** 052 * Returns the SearchProvider used. 053 * 054 * @return The current SearchProvider. 055 */ 056 SearchProvider getSearchEngine(); 057 058 /** 059 * Sends a search to the current search provider. The query is is whatever native format the query engine wants to use. 060 * 061 * @param query The query. Null is safe, and is interpreted as an empty query. 062 * @param wikiContext the context within which to run the search 063 * @return A collection of WikiPages that matched. 064 * @throws ProviderException If the provider fails and a search cannot be completed. 065 * @throws IOException If something else goes wrong. 066 */ 067 default Collection< SearchResult > findPages( String query, final Context wikiContext ) throws ProviderException, IOException { 068 if( query == null ) { 069 query = ""; 070 } 071 return getSearchEngine().findPages( query, wikiContext ); 072 } 073 074 /** 075 * Removes the page from the search cache (if any). 076 * 077 * @param page The page to remove 078 */ 079 default void pageRemoved( final Page page ) { 080 getSearchEngine().pageRemoved( page ); 081 } 082 083 /** 084 * Forces the reindex of the given page. 085 * 086 * @param page The page. 087 */ 088 default void reindexPage( final Page page ) { 089 getSearchEngine().reindexPage( page ); 090 } 091 092}