001/*
002 *  Copyright 2015 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.systemprop;
017
018import java.util.Map;
019
020import org.apache.avalon.framework.configuration.Configuration;
021import org.apache.avalon.framework.configuration.ConfigurationException;
022
023import org.ametys.cms.contenttype.MetadataType;
024import org.ametys.cms.repository.Content;
025import org.ametys.cms.search.SearchField;
026import org.ametys.cms.search.model.SystemProperty;
027import org.ametys.cms.search.query.FullTextQuery;
028import org.ametys.cms.search.query.Query;
029import org.ametys.cms.search.query.Query.Operator;
030
031/**
032 * {@link SystemProperty} which represents the full textual content of a Content.
033 */
034public class FulltextSystemProperty extends AbstractSystemProperty
035{
036    
037    /** True for a stemmed full-text search, false otherwise. */
038    protected boolean _stemmed;
039    
040    @Override
041    public void configure(Configuration configuration) throws ConfigurationException
042    {
043        super.configure(configuration);
044        _stemmed = configuration.getChild("stemmed").getValueAsBoolean(false);
045    }
046    
047    @Override
048    public MetadataType getType()
049    {
050        return MetadataType.STRING;
051    }
052    
053    @Override
054    public boolean isMultiple()
055    {
056        return false;
057    }
058    
059    @Override
060    public boolean isDisplayable()
061    {
062        return false;
063    }
064    
065    @Override
066    public boolean isSortable()
067    {
068        return false;
069    }
070    
071    @Override
072    public Query getQuery(Object value, Operator operator, String language, Map<String, Object> contextualParameters)
073    {
074        return new FullTextQuery((String) value, language, _stemmed ? Operator.SEARCH_STEMMED : Operator.SEARCH);
075    }
076    
077//    @Override
078//    public String getField()
079//    {
080//        // No value to index, not sortable: the field won't be used.
081//        return null;
082//    }
083    
084    @Override
085    public SearchField getSearchField()
086    {
087        // No value to index, not sortable: the field won't be used.
088        return null;
089    }
090    
091    @Override
092    public Object getValue(Content content)
093    {
094        // No real "value" to return here.
095        // The values are indexed separately, while walking the content metadata tree.
096        return null;
097    }
098
099}