001/* 002 * Copyright 2024 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.schema; 017 018import java.util.Map; 019 020import org.apache.solr.client.solrj.request.schema.SchemaRequest; 021 022/** 023 * Represents a dynamic field definition in a solr schema. 024 */ 025public class DynamicFieldDefinition extends FieldDefinition 026{ 027 /** 028 * Build a dynamic field definition, indexed and stored. 029 * @param name The field name, can contain a star character to represent a dynamic field (i.e. *_type). 030 * @param type The field type. 031 * @param multiValued <code>true</code> if the field is multi-valued. 032 * @param docValues <code>true</code> if the field is stored as docValues. 033 */ 034 public DynamicFieldDefinition(String name, String type, boolean multiValued, boolean docValues) 035 { 036 super(name, type, multiValued, docValues); 037 } 038 039 /** 040 * Build a dynamic field definition. 041 * @param name The field name, can contain a star character to represent a dynamic field (i.e. *_type). 042 * @param type The field type. 043 * @param multiValued <code>true</code> if the field is multi-valued. 044 * @param docValues <code>true</code> if the field is stored as docValues. 045 * @param indexed <code>true</code> if the field is indexed. 046 * @param stored <code>true</code> if the field is stored. 047 */ 048 public DynamicFieldDefinition(String name, String type, boolean multiValued, boolean docValues, boolean indexed, boolean stored) 049 { 050 super(name, type, multiValued, docValues, indexed, stored); 051 } 052 053 /** 054 * Build a dynamic field definition from a map of attributes. 055 * @param attributes the Map of attributes. 056 */ 057 public DynamicFieldDefinition(Map<String, Object> attributes) 058 { 059 super(attributes); 060 } 061 062 @Override 063 public SchemaRequest.Update getSchemaUpdate() 064 { 065 return new SchemaRequest.AddDynamicField(_getAttributes()); 066 } 067 068 @Override 069 public boolean exists(SchemaFields schemaFields) 070 { 071 return schemaFields.hasDynamicField(getName()); 072 } 073}