001/*
002 *  Copyright 2016 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.solr.field;
017
018import java.util.List;
019import java.util.Optional;
020
021import org.apache.commons.lang3.StringUtils;
022
023/**
024 * String generic search field.
025 */
026public class MultilingualStringSearchField extends AbstractMetadataSearchField
027{
028    private Optional<String> _language;
029
030    /**
031     * Build a multilingual string search field.
032     * @param path The field path.
033     * @param language The current language
034     */
035    public MultilingualStringSearchField(String path, Optional<String> language)
036    {
037        super(path);
038        _language = language;
039    }
040    
041    /**
042     * Build a string search field.
043     * @param joinPaths The join field paths
044     * @param finalPath The final field path.
045     * @param language The current language
046     */
047    public MultilingualStringSearchField(List<String> joinPaths, String finalPath, Optional<String> language)
048    {
049        super(joinPaths, finalPath);
050        _language = language;
051    }
052
053    @Override
054    protected String _getSortFieldSuffix()
055    {
056        return _language.map("_"::concat).orElse(StringUtils.EMPTY) + "_s_sort";
057    }
058    
059    @Override
060    protected String _getFacetFieldSuffix()
061    {
062        return "_s_dv";
063    }
064
065}