001/*
002 *  Copyright 2018 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.web.frontoffice.search.requesttime;
017
018import org.ametys.cms.search.solr.SearcherFactory.Searcher;
019
020/**
021 * A component which will execute a part of a FO search through {@link SearchServiceGenerator}.
022 */
023public interface SearchComponent
024{
025    /** Minimum priority */
026    public static final int MIN_PRIORITY = Integer.MAX_VALUE;
027    /** 
028     * Priority of the component executing the {@link Searcher#searchWithFacets() search} and {@link SearchComponentArguments#setResults(org.ametys.cms.search.SearchResults) setting the results}.
029     * <br>Thus, this constant can be used to define {@link #priority()} method whether the component must execute before or after the search.
030     */
031    public static final int SEARCH_PRIORITY = 0;
032    /** Maximum priority */
033    public static final int MAX_PRIORITY = Integer.MIN_VALUE;
034    
035    /** A {@link SearchComponentArguments#generatorParameters() generator parameter name} for disabling default sax and use a custom search component instead */
036    public static final String DISABLE_DEFAULT_SAX_PARAMETER_NAME = "disableDefaultSax";
037    
038    /**
039     * Get the priority of the component. The lowest one will be executed first, and so on.
040     * @return the priority of the component
041     */
042    int priority();
043    
044    /**
045     * Returns <code>true</code> if the component must be {@link SearchComponent#execute(SearchComponentArguments) executed}.
046     * @param args the arguments
047     * @return <code>true</code> if the component must be {@link SearchComponent#execute(SearchComponentArguments) executed}.
048     */
049    boolean supports(SearchComponentArguments args);
050    
051    /**
052     * Executes the component.
053     * @param args the arguments
054     * @throws Exception if an exception occurs. Other search components will be attempted to be executed
055     */
056    void execute(SearchComponentArguments args) throws Exception;
057}