Skip to content

Commit 1f036cf

Browse files
committed
[feature] Possible future optimisation to reduce searches against the Lucene Index where there is no suitable Index configuration for the named element/attribute
1 parent 54a97b8 commit 1f036cf

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.exist.dom.QName;
5656
import org.exist.indexing.lucene.analyzers.NoDiacriticsStandardAnalyzer;
5757
import org.exist.storage.NodePath;
58+
import org.exist.storage.NodePath2;
5859
import org.exist.util.DatabaseConfigurationException;
5960
import org.w3c.dom.Element;
6061
import org.w3c.dom.Node;
@@ -127,6 +128,31 @@ public LuceneConfig(LuceneConfig other) {
127128
this.analyzers = other.analyzers;
128129
this.facetsConfig = other.facetsConfig;
129130
}
131+
132+
/**
133+
* Determines probabilistically if there might be a configured index
134+
* for the QName. False positive matches are possible,
135+
* but false negatives are not.
136+
*
137+
* @param qname the element/attribute to look for an index configuration for.
138+
*
139+
* @return true indicates that there might be a config, false indicates
140+
* that there definitely is not a config.
141+
*/
142+
public boolean hasConfig(final QName qname) {
143+
if (paths.containsKey(qname)) {
144+
return true;
145+
} else {
146+
final NodePath2 path = new NodePath2();
147+
path.addComponent(qname);
148+
for (final LuceneIndexConfig config : wildcardPaths) {
149+
if (config.match(path)) {
150+
return true;
151+
}
152+
}
153+
}
154+
return false;
155+
}
130156

131157
public boolean matches(final NodePath path) {
132158
LuceneIndexConfig idxConf = paths.get(path.getLastComponent());

extensions/indexes/lucene/src/test/xquery/lucene/facets.xql

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,4 +950,28 @@ function facet:query-no-default-index-bracketed-element-count-and-facets() {
950950
let $result := doc("/db/lucenetest/multi-lang.xml")//(div)[ft:query(., "english:*", map { "leading-wildcard": "yes" })]
951951
return
952952
count($result) || " " || ft:facets($result, "language")?en
953-
};
953+
};
954+
955+
declare
956+
%test:assertEquals(1)
957+
function facet:query-no-default-index-bracketed-element-one-nonexistent-element-count() {
958+
let $result := doc("/db/lucenetest/multi-lang.xml")//(div|other)[ft:query(., "english:*", map { "leading-wildcard": "yes" })]
959+
return
960+
count($result)
961+
};
962+
963+
declare
964+
%test:assertEquals(1)
965+
function facet:query-no-default-index-bracketed-element-one-nonexistent-element-facets() {
966+
let $result := doc("/db/lucenetest/multi-lang.xml")//(div|other)[ft:query(., "english:*", map { "leading-wildcard": "yes" })]
967+
return
968+
ft:facets($result, "language")?en
969+
};
970+
971+
declare
972+
%test:assertEquals("1 1")
973+
function facet:query-no-default-index-bracketed-element-one-nonexistent-element-count-and-facets() {
974+
let $result := doc("/db/lucenetest/multi-lang.xml")//(div|other)[ft:query(., "english:*", map { "leading-wildcard": "yes" })]
975+
return
976+
count($result) || " " || ft:facets($result, "language")?en
977+
};

0 commit comments

Comments
 (0)