001/*
002 *  Copyright 2013 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.cms.search.model;
017
018import java.util.Map;
019import java.util.Set;
020
021/**
022 * This interface represents a search model.
023 */
024public interface SearchModel
025{
026    
027    /**
028     * Get the list of content types.
029     * @param contextualParameters the contextual parameters.
030     * @return The list of content types.
031     */
032    Set<String> getContentTypes(Map<String, Object> contextualParameters);
033    
034    /**
035     * Get the list of excluded content types.
036     * @param contextualParameters the contextual parameters
037     * @return The list of excluded content types.
038     */
039    Set<String> getExcludedContentTypes(Map<String, Object> contextualParameters);
040    
041    /**
042     * Get the list of search criteria in simple mode
043     * @param contextualParameters the contextual parameters
044     * @return the list of search criteria in simple mode
045     */
046    Map<String, ? extends SearchCriterion> getCriteria(Map<String, Object> contextualParameters);
047    
048    /**
049     * Get a simple search criterion by its id
050     * @param id The search criterion id
051     * @param contextualParameters the contextual parameters
052     * @return the criterion or <code>null</code> if not found
053     */
054    default SearchCriterion getCriterion(String id, Map<String, Object> contextualParameters)
055    {
056        return getCriteria(contextualParameters).get(id);
057    }
058    
059    /**
060     * Get the list of faceted search criteria.
061     * @param contextualParameters the contextual parameters
062     * @return the list of faceted search criteria.
063     */
064    Map<String, ? extends SearchCriterion> getFacetedCriteria(Map<String, Object> contextualParameters);
065    
066    /**
067     * Get a faceted search criterion by its id.
068     * @param id The faceted search criterion id.
069     * @param contextualParameters the contextual parameters
070     * @return the faceted criterion or <code>null</code> if not found
071     */
072    default SearchCriterion getFacetedCriterion(String id, Map<String, Object> contextualParameters)
073    {
074        return getFacetedCriteria(contextualParameters).get(id);
075    }
076    
077    /**
078     * Get the column for results
079     * @param contextualParameters the contextual parameters. Can be null.
080     * @return the column for results
081     */
082    Map<String, ? extends ResultField> getResultFields(Map<String, Object> contextualParameters);
083    
084    /**
085     * Get the column by its identifier
086     * @param id The column id
087     * @param contextualParameters the contextual parameters
088     * @return the column 
089     */
090    default ResultField getResultField(String id, Map<String, Object> contextualParameters)
091    {
092        return getResultFields(contextualParameters).get(id);
093    }
094    
095}