001/* 002 * (C) Copyright 2006-2018 Nuxeo (http://nuxeo.com/) and others. 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 * 016 * Contributors: 017 * Florent Guillaume 018 */ 019package org.nuxeo.ecm.core.storage; 020 021import java.util.ArrayList; 022import java.util.HashSet; 023import java.util.List; 024import java.util.Objects; 025import java.util.Set; 026 027import org.nuxeo.common.xmap.annotation.XNode; 028import org.nuxeo.common.xmap.annotation.XNodeList; 029import org.nuxeo.common.xmap.annotation.XObject; 030 031/** 032 * Structure holding fulltext descriptor info for generic fulltext indexing. 033 * <p> 034 * Not directly a XObject, but used by various RepositoryDescriptors. 035 * 036 * @since 7.10-HF04, 8.1 037 */ 038public class FulltextDescriptor { 039 040 @XObject(value = "index") 041 public static class FulltextIndexDescriptor { 042 043 @XNode("@name") 044 public String name; 045 046 /** string or blob */ 047 @XNode("fieldType") 048 public String fieldType; 049 050 @XNodeList(value = "field", type = HashSet.class, componentType = String.class) 051 public Set<String> fields = new HashSet<>(0); 052 053 @XNodeList(value = "excludeField", type = HashSet.class, componentType = String.class) 054 public Set<String> excludeFields = new HashSet<>(0); 055 056 public FulltextIndexDescriptor() { 057 } 058 059 /** Copy constructor. */ 060 public FulltextIndexDescriptor(FulltextIndexDescriptor other) { 061 name = other.name; 062 fieldType = other.fieldType; 063 fields = new HashSet<>(other.fields); 064 excludeFields = new HashSet<>(other.excludeFields); 065 } 066 067 public static List<FulltextIndexDescriptor> copyList(List<FulltextIndexDescriptor> other) { 068 List<FulltextIndexDescriptor> copy = new ArrayList<>(other.size()); 069 for (FulltextIndexDescriptor fid : other) { 070 copy.add(new FulltextIndexDescriptor(fid)); 071 } 072 return copy; 073 } 074 075 public void merge(FulltextIndexDescriptor other) { 076 if (other.name != null) { 077 name = other.name; 078 } 079 if (other.fieldType != null) { 080 fieldType = other.fieldType; 081 } 082 fields.addAll(other.fields); 083 excludeFields.addAll(other.excludeFields); 084 } 085 } 086 087 public static final int FULLTEXT_FIELD_SIZE_LIMIT_DEFAULT = 128 * 1024; // 128 K 088 089 private Integer fulltextFieldSizeLimit; 090 091 public int getFulltextFieldSizeLimit() { 092 return fulltextFieldSizeLimit == null ? FULLTEXT_FIELD_SIZE_LIMIT_DEFAULT : fulltextFieldSizeLimit.intValue(); 093 } 094 095 public void setFulltextFieldSizeLimit(int fulltextFieldSizeLimit) { 096 this.fulltextFieldSizeLimit = Integer.valueOf(fulltextFieldSizeLimit); 097 } 098 099 /** False if the boolean is null or FALSE, true otherwise. */ 100 private static boolean defaultFalse(Boolean bool) { 101 return Boolean.TRUE.equals(bool); 102 } 103 104 private Boolean fulltextDisabled; 105 106 public boolean getFulltextDisabled() { 107 return defaultFalse(fulltextDisabled); 108 } 109 110 public void setFulltextDisabled(boolean disabled) { 111 fulltextDisabled = Boolean.valueOf(disabled); 112 } 113 114 private Boolean fulltextStoredInBlob; 115 116 /** @since 11.1 */ 117 public boolean getFulltextStoredInBlob() { 118 return defaultFalse(fulltextStoredInBlob); 119 } 120 121 /** @since 11.1 */ 122 public void setFulltextStoredInBlob(boolean storedInBlob) { 123 fulltextStoredInBlob = Boolean.valueOf(storedInBlob); 124 } 125 126 private Boolean fulltextSearchDisabled; 127 128 public boolean getFulltextSearchDisabled() { 129 if (getFulltextDisabled() || getFulltextStoredInBlob()) { 130 return true; 131 } 132 return defaultFalse(fulltextSearchDisabled); 133 } 134 135 public void setFulltextSearchDisabled(boolean disabled) { 136 fulltextSearchDisabled = Boolean.valueOf(disabled); 137 } 138 139 private List<FulltextIndexDescriptor> fulltextIndexes = new ArrayList<>(0); 140 141 public List<FulltextIndexDescriptor> getFulltextIndexes() { 142 return fulltextIndexes; 143 } 144 145 public void setFulltextIndexes(List<FulltextIndexDescriptor> fulltextIndexes) { 146 this.fulltextIndexes = fulltextIndexes; 147 } 148 149 private Set<String> fulltextExcludedTypes = new HashSet<>(0); 150 151 public Set<String> getFulltextExcludedTypes() { 152 return fulltextExcludedTypes; 153 } 154 155 public void setFulltextExcludedTypes(Set<String> fulltextExcludedTypes) { 156 this.fulltextExcludedTypes = fulltextExcludedTypes; 157 } 158 159 private Set<String> fulltextIncludedTypes = new HashSet<>(0); 160 161 public Set<String> getFulltextIncludedTypes() { 162 return fulltextIncludedTypes; 163 } 164 165 public void setFulltextIncludedTypes(Set<String> fulltextIncludedTypes) { 166 this.fulltextIncludedTypes = fulltextIncludedTypes; 167 } 168 169 public FulltextDescriptor() { 170 } 171 172 /** Copy constructor. */ 173 public FulltextDescriptor(FulltextDescriptor other) { 174 fulltextFieldSizeLimit = other.fulltextFieldSizeLimit; 175 fulltextDisabled = other.fulltextDisabled; 176 fulltextStoredInBlob = other.fulltextStoredInBlob; 177 fulltextSearchDisabled = other.fulltextSearchDisabled; 178 fulltextIndexes = FulltextIndexDescriptor.copyList(other.fulltextIndexes); 179 fulltextExcludedTypes = new HashSet<>(other.fulltextExcludedTypes); 180 fulltextIncludedTypes = new HashSet<>(other.fulltextIncludedTypes); 181 } 182 183 public void merge(FulltextDescriptor other) { 184 if (other.fulltextFieldSizeLimit != null) { 185 fulltextFieldSizeLimit = other.fulltextFieldSizeLimit; 186 } 187 if (other.fulltextDisabled != null) { 188 fulltextDisabled = other.fulltextDisabled; 189 } 190 if (other.fulltextStoredInBlob != null) { 191 fulltextStoredInBlob = other.fulltextStoredInBlob; 192 } 193 if (other.fulltextSearchDisabled != null) { 194 fulltextSearchDisabled = other.fulltextSearchDisabled; 195 } 196 for (FulltextIndexDescriptor oi : other.fulltextIndexes) { 197 boolean append = true; 198 for (FulltextIndexDescriptor i : fulltextIndexes) { 199 if (Objects.equals(i.name, oi.name)) { 200 i.merge(oi); 201 append = false; 202 break; 203 } 204 } 205 if (append) { 206 fulltextIndexes.add(oi); 207 } 208 } 209 fulltextExcludedTypes.addAll(other.fulltextExcludedTypes); 210 fulltextIncludedTypes.addAll(other.fulltextIncludedTypes); 211 } 212 213}