SimplePropertyDefinition.java
4.05 KB
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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.resource.PersistenceException
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
*/
package com.adobe.cq.dam.index.builder;
import com.adobe.cq.dam.index.builder.api.PropertyDefinition;
import java.util.HashMap;
import java.util.Map;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
public class SimplePropertyDefinition
implements PropertyDefinition {
String nodeName;
String property;
String propertyType;
boolean propertyIndex;
float boost = 1.0f;
boolean nodeScopeIndex;
boolean analyzed;
boolean useInSuggest;
boolean useInSpellcheck;
public SimplePropertyDefinition(String property, String nodeName) {
this.setNodeName(nodeName);
this.setProperty(property);
this.setPropertyIndex(true);
}
public SimplePropertyDefinition(String property, String nodeName, float boost) {
this(property, nodeName);
this.setBoost(boost);
}
public SimplePropertyDefinition(String property, String nodeName, String propertyType) {
this(property, nodeName);
this.setPropertyType(propertyType);
}
public SimplePropertyDefinition(String property, String nodeName, float boost, boolean analyzed) {
this(property, nodeName, boost);
this.setAnalyzed(analyzed);
}
public SimplePropertyDefinition(String property, String nodeName, float boost, boolean analyzed, boolean useInSuggest) {
this(property, nodeName, boost);
this.setAnalyzed(analyzed);
this.setUseInSuggest(useInSuggest);
}
public SimplePropertyDefinition(String property, String nodeName, float boost, boolean analyzed, boolean useInSuggest, boolean useInSpellcheck) {
this(property, nodeName, boost);
this.setAnalyzed(analyzed);
this.setUseInSuggest(useInSuggest);
this.setUseInSpellcheck(useInSpellcheck);
}
public void setNodeName(String nodeName) {
this.nodeName = nodeName;
}
public void setProperty(String prop) {
this.property = prop;
}
public void setPropertyType(String type) {
this.propertyType = type;
}
private void setPropertyIndex(boolean propertyIndex) {
this.propertyIndex = propertyIndex;
}
public void setBoost(float boost) {
this.boost = boost;
this.nodeScopeIndex = true;
}
public void setAnalyzed(boolean analyzed) {
this.analyzed = analyzed;
}
public void setUseInSuggest(boolean useInSuggest) {
this.useInSuggest = useInSuggest;
}
public void setUseInSpellcheck(boolean useInSpellcheck) {
this.useInSpellcheck = useInSpellcheck;
}
@Override
public void build(Resource resource) throws PersistenceException {
ResourceResolver resolver = resource.getResourceResolver();
if (resolver.getResource(resource, this.nodeName) != null) {
resolver.delete(resolver.getResource(resource, this.nodeName));
}
HashMap<String, Object> propsMap = new HashMap<String, Object>();
propsMap.put("name", this.property);
propsMap.put("propertyIndex", this.propertyIndex);
if (this.analyzed) {
propsMap.put("analyzed", true);
}
if (this.useInSuggest) {
propsMap.put("useInSuggest", true);
propsMap.put("nodeScopeIndex", true);
}
if (this.useInSpellcheck) {
propsMap.put("useInSpellcheck", true);
propsMap.put("nodeScopeIndex", true);
}
if (this.boost != 1.0f) {
propsMap.put("boost", Float.valueOf(this.boost));
propsMap.put("nodeScopeIndex", this.nodeScopeIndex);
}
if (this.propertyType != null && !this.propertyType.isEmpty()) {
propsMap.put("type", this.propertyType);
}
resolver.create(resource, this.nodeName, propsMap);
}
}