    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    /**
    049     *  Returns the SearchProvider used.
    050     *
    051     *  @return The current SearchProvider.
    052     */
    053    SearchProvider getSearchEngine();
    054
    055    /**
    056     *  Sends a search to the current search provider. The query is is whatever native format the query engine wants to use.
    057     *
    058     * @param query The query.  Null is safe, and is interpreted as an empty query.
    059     * @param wikiContext the context within which to run the search
    060     * @return A collection of WikiPages that matched.
    061     * @throws ProviderException If the provider fails and a search cannot be completed.
    062     * @throws IOException If something else goes wrong.
    063     */
    064    default Collection< SearchResult > findPages( String query, final Context wikiContext ) throws ProviderException, IOException {
    065        if( query == null ) {
    066            query = "";
    067        }
    068        return getSearchEngine().findPages( query, wikiContext );
    069    }
    070
    071    /**
    072     *  Removes the page from the search cache (if any).
    073     *
    074     *  @param page  The page to remove
    075     */
    076    default void pageRemoved( final Page page ) {
    077        getSearchEngine().pageRemoved( page );
    078    }
    079
    080    /**
    081     *   Forces the reindex of the given page.
    082     *
    083     *   @param page The page.
    084     */
    085    default void reindexPage( final Page page ) {
    086        getSearchEngine().reindexPage( page );
    087    }
    088
    089}