Skip to content

Commit 6a2445a

Browse files
authored
Merge pull request #5816 from line-o/fix/LuceneFieldConfig
[fix] AbstractFieldConfig recognizes expressions again
2 parents c9f8725 + 88abadf commit 6a2445a

File tree

5 files changed

+153
-134
lines changed

5 files changed

+153
-134
lines changed

extensions/indexes/lucene/src/main/java/org/exist/indexing/lucene/AbstractFieldConfig.java

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
/**
4949
* Abstract configuration corresponding to either a field or facet element nested inside
50-
* a index definition 'text' element. Adds the possibility to create index content based
50+
* an index definition 'text' element. Adds the possibility to create index content based
5151
* on an arbitrary XQuery expression.
5252
*
5353
* @author Wolfgang Meier
@@ -58,50 +58,52 @@ public abstract class AbstractFieldConfig {
5858

5959
protected static final Logger LOG = LogManager.getLogger(AbstractFieldConfig.class);
6060

61-
protected Optional<String> expression = Optional.empty();
61+
protected final Optional<String> expression;
6262
protected boolean isValid = true;
6363
private CompiledXQuery compiled = null;
6464

65-
public AbstractFieldConfig(LuceneConfig config, Element configElement, Map<String, String> namespaces) {
65+
public AbstractFieldConfig(final LuceneConfig config, final Element configElement, final Map<String, String> namespaces) {
6666
final String xpath = configElement.getAttribute(XPATH_ATTR);
6767
if (xpath.isEmpty()) {
68-
69-
final StringBuilder sb = new StringBuilder();
70-
namespaces.forEach((prefix, uri) -> {
71-
if (!"xml".equals(prefix)) {
72-
sb.append("declare namespace ").append(prefix);
73-
sb.append("=\"").append(uri).append("\";\n");
74-
}
75-
});
76-
config.getImports().ifPresent(moduleImports -> moduleImports.forEach((moduleImport -> {
77-
sb.append("import module namespace ");
78-
sb.append(moduleImport.prefix);
79-
sb.append("=\"");
80-
sb.append(moduleImport.uri);
81-
sb.append("\" at \"");
82-
sb.append(resolveURI(configElement.getBaseURI(), moduleImport.at));
83-
sb.append("\";\n");
84-
})));
85-
sb.append(xpath);
86-
87-
this.expression = Optional.of(sb.toString());
68+
expression = Optional.empty();
69+
return;
8870
}
71+
72+
final StringBuilder sb = new StringBuilder();
73+
namespaces.forEach((prefix, uri) -> {
74+
if (!"xml".equals(prefix)) {
75+
sb.append("declare namespace ").append(prefix);
76+
sb.append("=\"").append(uri).append("\";\n");
77+
}
78+
});
79+
config.getImports().ifPresent(moduleImports -> moduleImports.forEach((moduleImport -> {
80+
sb.append("import module namespace ");
81+
sb.append(moduleImport.prefix);
82+
sb.append("=\"");
83+
sb.append(moduleImport.uri);
84+
sb.append("\" at \"");
85+
sb.append(resolveURI(configElement.getBaseURI(), moduleImport.at));
86+
sb.append("\";\n");
87+
})));
88+
sb.append(xpath);
89+
90+
expression = Optional.of(sb.toString());
8991
}
9092

9193
@Nullable
9294
public Analyzer getAnalyzer() {
9395
return null;
9496
}
9597

96-
protected abstract void processResult(Sequence result, Document luceneDoc) throws XPathException;
98+
protected abstract void processResult(final Sequence result, final Document luceneDoc) throws XPathException;
9799

98100
protected abstract void processText(CharSequence text, Document luceneDoc);
99101

100102
protected abstract void build(DBBroker broker, DocumentImpl document, NodeId nodeId, Document luceneDoc, CharSequence text);
101103

102104
protected void doBuild(DBBroker broker, DocumentImpl document, NodeId nodeId, Document luceneDoc, CharSequence text)
103105
throws PermissionDeniedException, XPathException {
104-
if (!expression.isPresent()) {
106+
if (expression.isEmpty()) {
105107
processText(text, luceneDoc);
106108
return;
107109
}
@@ -129,13 +131,13 @@ protected void doBuild(DBBroker broker, DocumentImpl document, NodeId nodeId, Do
129131
}
130132
}
131133

132-
private void compile(DBBroker broker) {
134+
private void compile(final DBBroker broker) {
133135
if (compiled == null && isValid) {
134136
expression.ifPresent((code) -> compiled = compile(broker, code));
135137
}
136138
}
137139

138-
protected CompiledXQuery compile(DBBroker broker, String code) {
140+
protected CompiledXQuery compile(final DBBroker broker, final String code) {
139141
final XQuery xquery = broker.getBrokerPool().getXQueryService();
140142
final XQueryContext context = new XQueryContext(broker.getBrokerPool());
141143
try {
@@ -147,7 +149,7 @@ protected CompiledXQuery compile(DBBroker broker, String code) {
147149
}
148150
}
149151

150-
private String resolveURI(String baseURI, String location) {
152+
private String resolveURI(final String baseURI, final String location) {
151153
try {
152154
final URI uri = new URI(location);
153155
if (!uri.isAbsolute() && baseURI != null && baseURI.startsWith(CollectionConfigurationManager.CONFIG_COLLECTION)) {

0 commit comments

Comments
 (0)