-
Notifications
You must be signed in to change notification settings - Fork 242
/
EntityDescriptor.java
235 lines (197 loc) · 7.22 KB
/
EntityDescriptor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.search.cfg;
import java.lang.annotation.ElementType;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;
import org.hibernate.search.exception.SearchException;
import org.hibernate.search.annotations.ClassBridge;
import org.hibernate.search.bridge.FieldBridge;
/**
* @author Emmanuel Bernard
*/
public class EntityDescriptor {
private Map<String, Object> indexed;
private final Map<PropertyKey, PropertyDescriptor> properties = new HashMap<PropertyKey, PropertyDescriptor>();
private Map<String, Object> boost;
private Map<String, Object> analyzerDiscriminator;
private final Set<Map<String, Object>> fullTextFilterDefs = new HashSet<Map<String, Object>>();
private Map<String, Object> providedId;
/**
* Configured class bridges. Each bridge is represented by a map with {@code @ClassBridge} annotation member values
* keyed by annotation member name.
*/
private final Set<Map<String, Object>> classBridges = new HashSet<Map<String, Object>>();
/**
* Class bridge instances and their configuration
*/
private final Map<FieldBridge, Map<String, Object>> classBridgeInstanceDefs = new IdentityHashMap<FieldBridge, Map<String,Object>>();
/**
* Class bridge instances and their configuration in form of a {@code ClassBridge} annotation
*/
private final Map<FieldBridge, ClassBridge> classBridgeConfigurations = new IdentityHashMap<FieldBridge, ClassBridge>();
private final Set<Map<String, Object>> spatials = new HashSet<Map<String, Object>>();
private Map<String, Object> dynamicBoost;
public Map<String, Object> getIndexed() {
return indexed;
}
public void setIndexed(Map<String, Object> indexed) {
this.indexed = indexed;
}
PropertyDescriptor getProperty(String name, ElementType type) {
PropertyKey propertyKey = new PropertyKey( name, type );
PropertyDescriptor descriptor = properties.get( propertyKey );
if ( descriptor == null ) {
descriptor = new PropertyDescriptor( name, type );
properties.put( propertyKey, descriptor );
}
return descriptor;
}
public PropertyDescriptor getPropertyDescriptor(String name, ElementType type) {
return properties.get( new PropertyKey( name, type ) );
}
/**
* This feature will be removed, with no replacement
* as caching fields is no longer effective.
* @return This will always return an empty Map.
* @deprecated This will be removed with no replacement.
*/
@Deprecated
public Map<String, Object> getCacheInMemory() {
return Collections.<String, Object>emptyMap();
}
/**
* This feature will be removed, with no replacement
* as caching fields is no longer effective.
* @param cacheInMemory this parameter will be ignored.
* @deprecated This will be removed with no replacement.
*/
@Deprecated
public void setCacheInMemory(Map<String, Object> cacheInMemory) {
//No-op: this feature is no longer available
}
/**
* @deprecated Index-time boosting will not be possible anymore starting from Lucene 7.
* You should use query-time boosting instead, for instance by calling
* {@link org.hibernate.search.query.dsl.FieldCustomization#boostedTo(float) boostedTo(float)}
* when building queries with the Hibernate Search query DSL.
*/
@Deprecated
public void setBoost(Map<String, Object> boost) {
this.boost = boost;
}
/**
* @deprecated Index-time boosting will not be possible anymore starting from Lucene 7.
* You should use query-time boosting instead, for instance by calling
* {@link org.hibernate.search.query.dsl.FieldCustomization#boostedTo(float) boostedTo(float)}
* when building queries with the Hibernate Search query DSL.
*/
@Deprecated
public Map<String, Object> getBoost() {
return boost;
}
public void setAnalyzerDiscriminator(Map<String, Object> analyzerDiscriminator) {
this.analyzerDiscriminator = analyzerDiscriminator;
}
public Map<String, Object> getAnalyzerDiscriminator() {
return analyzerDiscriminator;
}
public Set<Map<String, Object>> getFullTextFilterDefs() {
return fullTextFilterDefs;
}
public void addFulltextFilterDef(Map<String, Object> fullTextFilterDef) {
fullTextFilterDefs.add( fullTextFilterDef );
}
public void addClassBridgeDef(Map<String, Object> classBridge) {
classBridges.add( classBridge );
}
public void addClassBridgeInstanceDef(FieldBridge classBridge, Map<String, Object> properties) {
Map<String, Object> previous = classBridgeInstanceDefs.put( classBridge, properties );
if ( previous != null ) {
throw new SearchException( "The same field bridge instance must not be passed more than once." );
}
}
public Set<Map<String, Object>> getClassBridgeDefs() {
return classBridges;
}
public Map<FieldBridge, Map<String, Object>> getClassBridgeInstanceDefs() {
return classBridgeInstanceDefs;
}
public void addClassBridgeInstanceConfiguration(FieldBridge classBridge, ClassBridge configuration) {
classBridgeConfigurations.put( classBridge, configuration );
}
public Map<FieldBridge, ClassBridge> getClassBridgeConfigurations() {
return classBridgeConfigurations;
}
public void addSpatial(Map<String,Object> spatial) {
spatials.add( spatial );
}
public Set<Map<String, Object>> getSpatials() {
return spatials;
}
public void setProvidedId(Map<String, Object> providedId) {
this.providedId = providedId;
}
public Map<String, Object> getProvidedId() {
return this.providedId;
}
/**
* @deprecated Index-time boosting will not be possible anymore starting from Lucene 7.
* You should use query-time boosting instead, for instance by calling
* {@link org.hibernate.search.query.dsl.FieldCustomization#boostedTo(float) boostedTo(float)}
* when building queries with the Hibernate Search query DSL.
*/
@Deprecated
public void setDynamicBoost(Map<String, Object> dynamicEntityBoost) {
this.dynamicBoost = dynamicEntityBoost;
}
/**
* @deprecated Index-time boosting will not be possible anymore starting from Lucene 7.
* You should use query-time boosting instead, for instance by calling
* {@link org.hibernate.search.query.dsl.FieldCustomization#boostedTo(float) boostedTo(float)}
* when building queries with the Hibernate Search query DSL.
*/
@Deprecated
public Map<String, Object> getDynamicBoost() {
return this.dynamicBoost;
}
private static class PropertyKey {
private final String name;
private final ElementType type;
PropertyKey(String name, ElementType type) {
this.name = name;
this.type = type;
}
@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( o == null || getClass() != o.getClass() ) {
return false;
}
PropertyKey property = (PropertyKey) o;
if ( name != null ? !name.equals( property.name ) : property.name != null ) {
return false;
}
if ( type != property.type ) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + ( type != null ? type.hashCode() : 0 );
return result;
}
}
}