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
021import org.ametys.runtime.model.ModelViewItem;
022import org.ametys.runtime.model.ViewHelper;
023import org.ametys.runtime.model.ViewItemContainer;
024
025/**
026 * This interface represents a search model.
027 */
028public interface SearchModel
029{
030    /**
031     * Get the list of content types.
032     * @param contextualParameters the contextual parameters.
033     * @return The list of content types.
034     */
035    Set<String> getContentTypes(Map<String, Object> contextualParameters);
036    
037    /**
038     * Get the list of excluded content types.
039     * @param contextualParameters the contextual parameters
040     * @return The list of excluded content types.
041     */
042    Set<String> getExcludedContentTypes(Map<String, Object> contextualParameters);
043    
044    /**
045     * Get the list of search criteria in simple mode
046     * @param contextualParameters the contextual parameters
047     * @return the list of search criteria in simple mode
048     */
049    Map<String, ? extends SearchCriterion> getCriteria(Map<String, Object> contextualParameters);
050    
051    /**
052     * Get a simple search criterion by its id
053     * @param id The search criterion id
054     * @param contextualParameters the contextual parameters
055     * @return the criterion or <code>null</code> if not found
056     */
057    default SearchCriterion getCriterion(String id, Map<String, Object> contextualParameters)
058    {
059        return getCriteria(contextualParameters).get(id);
060    }
061    
062    /**
063     * Get the list of faceted search criteria.
064     * @param contextualParameters the contextual parameters
065     * @return the list of faceted search criteria.
066     */
067    Map<String, ? extends SearchCriterion> getFacetedCriteria(Map<String, Object> contextualParameters);
068    
069    /**
070     * Get a faceted search criterion by its id.
071     * @param id The faceted search criterion id.
072     * @param contextualParameters the contextual parameters
073     * @return the faceted criterion or <code>null</code> if not found
074     */
075    default SearchCriterion getFacetedCriterion(String id, Map<String, Object> contextualParameters)
076    {
077        return getFacetedCriteria(contextualParameters).get(id);
078    }
079    
080    /**
081     * Retrieves the search result items 
082     * @param contextualParameters the contextual parameters
083     * @return the search result items
084     */
085    ViewItemContainer getResultItems(Map<String, Object> contextualParameters);
086    
087    /**
088     * Retrieves the search result item with the given path
089     * @param itemPath the path of the result item to retrieve
090     * @param contextualParameters the contextual parameters
091     * @return the search result item with
092     */
093    default ModelViewItem getResultItem(String itemPath, Map<String, Object> contextualParameters)
094    {
095        ViewItemContainer resultItems = getResultItems(contextualParameters);
096        return ViewHelper.getModelViewItem(resultItems, itemPath);
097    }
098    
099    /**
100     * Get the specific workspace to use.
101     * @param contextualParameters the contextual parameters.
102     * @return the workspace to use when searching, or null to use the default workspace.
103     */
104    String getWorkspace(Map<String, Object> contextualParameters);
105}