001/* 002 * Copyright 2022 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.data.type.indexing.impl; 017 018import java.util.Optional; 019 020import org.apache.solr.common.SolrInputDocument; 021 022import org.ametys.cms.data.Reference; 023import org.ametys.cms.data.type.AbstractReferenceElementType; 024import org.ametys.cms.data.type.indexing.IndexableElementTypeHelper; 025import org.ametys.cms.data.type.indexing.SortableIndexableElementType; 026import org.ametys.runtime.model.type.DataContext; 027 028/** 029 * Class for reference type of elements that can be indexed 030 */ 031public class ReferenceIndexableElementType extends AbstractReferenceElementType implements SortableIndexableElementType<Reference> 032{ 033 public void indexSingleValue(SolrInputDocument document, SolrInputDocument rootObjectDocument, String fieldName, Reference value, DataContext context) 034 { 035 String valueToIndex = getSingleValueToIndex(value); 036 IndexableElementTypeHelper.indexStringValue(document, rootObjectDocument, fieldName, valueToIndex, context, getLogger()); 037 } 038 039 @SuppressWarnings("unchecked") 040 public <X> X getSingleValueToIndex(Reference value) 041 { 042 return (X) value.getValue(); 043 } 044 045 public String getSortFieldSuffix() 046 { 047 return "_s_sort"; 048 } 049 050 public String getSchemaType() 051 { 052 return "string"; 053 } 054 055 public String getIndexingFieldSuffix(DataContext context) 056 { 057 return IndexableElementTypeHelper.getStringIndexingFieldSuffix(context); 058 } 059 060 public Optional<String> getWildcardFieldSuffix(DataContext context) 061 { 062 return Optional.of(IndexableElementTypeHelper.getStringWildcardFieldSuffix(context)); 063 } 064 065 public Optional<String> getTextFieldSuffix(DataContext context) 066 { 067 return Optional.of(IndexableElementTypeHelper.getStringTextFieldSuffix(context)); 068 } 069 070 public boolean isFacetable(DataContext context) 071 { 072 return IndexableElementTypeHelper.isStringDataFacetable(context); 073 } 074}