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.Collection; 019import java.util.List; 020import java.util.Map; 021 022import org.apache.avalon.framework.configuration.Configuration; 023import org.apache.avalon.framework.configuration.ConfigurationException; 024 025import org.ametys.cms.repository.Content; 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; 030import org.ametys.cms.search.solr.schema.SchemaDefinition; 031import org.ametys.runtime.model.type.ModelItemTypeConstants; 032 033/** 034 * {@link SystemProperty} which represents the full textual content of a Content. 035 */ 036public class FulltextSystemProperty extends AbstractIndexableSystemProperty<String, String, Content> 037{ 038 /** True for a stemmed full-text search, false otherwise. */ 039 protected boolean _stemmed; 040 041 @Override 042 public void configure(Configuration configuration) throws ConfigurationException 043 { 044 super.configure(configuration); 045 _stemmed = configuration.getChild("stemmed").getValueAsBoolean(false); 046 } 047 048 @Override 049 public boolean isDisplayable() 050 { 051 return false; 052 } 053 054 @Override 055 public Query getQuery(Object value, Operator operator, String language, Map<String, Object> contextualParameters) 056 { 057 return new FullTextQuery((String) value, language, _stemmed ? Operator.SEARCH_STEMMED : Operator.SEARCH); 058 } 059 060 @Override 061 public Object getValue(Content content) 062 { 063 // No real "value" to return here. 064 // The values are indexed separately, while walking the content attribute tree. 065 return null; 066 } 067 068 @Override 069 protected String getTypeId() 070 { 071 return ModelItemTypeConstants.STRING_TYPE_ID; 072 } 073 074 @Override 075 public String getSolrFieldName() 076 { 077 // No specific value to index: the field won't be used. 078 return null; 079 } 080 081 @Override 082 public String getSolrSortFieldName() 083 { 084 // Not sortable 085 return null; 086 } 087 088 @Override 089 public String getSolrFacetFieldName() 090 { 091 // Not facetable 092 return null; 093 } 094 095 @Override 096 public Collection<SchemaDefinition> getSchemaDefinitions() 097 { 098 // No specific schema definition 099 return List.of(); 100 } 101}