Skip to content

Commit

Permalink
Allow more elaborate XPath expressions in the Lucene index spec in co…
Browse files Browse the repository at this point in the history
…llection.xconf (original PR #2169)
  • Loading branch information
sten1ee authored and dizzzz committed Jan 8, 2019
1 parent 33665e0 commit 893e726
Show file tree
Hide file tree
Showing 13 changed files with 531 additions and 67 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ bin/startup.sh or bin/startup.bat
If these scripts don't work for you, try to call Java manually:

java -jar start.jar jetty

Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected LuceneIndexConfig getWildcardConfig(NodePath path) {
public Analyzer getAnalyzer(QName qname) {
LuceneIndexConfig idxConf = paths.get(qname);
while (idxConf != null) {
if (!idxConf.isNamed() && idxConf.getNodePath().match(qname))
if (!idxConf.isNamed() && idxConf.getNodePathPattern().match(qname))
break;
idxConf = idxConf.getNext();
}
Expand Down Expand Up @@ -274,12 +274,12 @@ protected void parseConfig(NodeList configNodes, Map<String, String> namespaces)
if (config.getName() != null) {
namedIndexes.put(config.getName(), config);
} // register index either by QName or path
if (config.getNodePath().hasWildcard()) {
if (config.getNodePathPattern().hasWildcard()) {
wildcardPaths.add(config);
} else {
LuceneIndexConfig idxConf = paths.get(config.getNodePath().getLastComponent());
LuceneIndexConfig idxConf = paths.get(config.getNodePathPattern().getLastComponent());
if (idxConf == null) {
paths.put(config.getNodePath().getLastComponent(), config);
paths.put(config.getNodePathPattern().getLastComponent(), config);
} else {
idxConf.add(config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ public class LuceneIndexConfig {

private String name = null;

private NodePath path = null;
private NodePathPattern path = null;

private boolean isQNameIndex = false;

private Map<QName, String> specialNodes = null;

private LuceneIndexConfig nextConfig = null;

private FieldType type = null;

// This is for the @attr match boosting
// and the intention is to do a proper predicate check instead in the future. /ljo
private MultiMap matchAttrs;
Expand All @@ -78,13 +78,13 @@ public LuceneIndexConfig(Element config, Map<String, String> namespaces, Analyze
Map<String, FieldType> fieldTypes) throws DatabaseConfigurationException {
if (config.hasAttribute(QNAME_ATTR)) {
QName qname = parseQName(config, namespaces);
path = new NodePath(qname);
path = new NodePathPattern(qname);
isQNameIndex = true;
} else {
String matchPath = config.getAttribute(MATCH_ATTR);

try {
path = new NodePath(namespaces, matchPath);
path = new NodePathPattern(namespaces, matchPath);
if (path.length() == 0)
throw new DatabaseConfigurationException("Lucene module: Invalid match path in collection config: " +
matchPath);
Expand All @@ -96,10 +96,10 @@ public LuceneIndexConfig(Element config, Map<String, String> namespaces, Analyze
String name = config.getAttribute(FIELD_ATTR);
if (name != null && name.length() > 0)
setName(name);

String fieldType = config.getAttribute(TYPE_ATTR);
if (fieldType != null && fieldType.length() > 0)
type = fieldTypes.get(fieldType);
type = fieldTypes.get(fieldType);
if (type == null)
type = new FieldType(config, analyzers);

Expand Down Expand Up @@ -200,7 +200,7 @@ public QName getQName() {
return path.getLastComponent();
}

public NodePath getNodePath() {
public NodePathPattern getNodePathPattern() {
return path;
}

Expand Down Expand Up @@ -252,22 +252,22 @@ public void setName(String name) {
public String getName() {
return name;
}

public void add(LuceneIndexConfig config) {
if (nextConfig == null)
nextConfig = config;
else
nextConfig.add(config);
}

public LuceneIndexConfig getNext() {
return nextConfig;
}

private boolean isAttributeNode() {
return path.getLastComponent().getNameType() == ElementValue.ATTRIBUTE;
}

/**
* @return true if this index can be queried by name
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,20 @@ public <T extends IStoredNode> IStoredNode getReindexRoot(IStoredNode<T> node, N
return null;
}

NodePath p = new NodePath(path);
NodePath2 p = new NodePath2((NodePath2)path);
boolean reindexRequired = false;

if (node.getNodeType() == Node.ELEMENT_NODE && !includeSelf)
p.removeLastComponent();
p.removeLastNode();
for (int i = 0; i < p.length(); i++) {
if (config.matches(p)) {
reindexRequired = true;
break;
}
p.removeLastComponent();
p.removeLastNode();
}
if (reindexRequired) {
p = new NodePath(path);
p = new NodePath2((NodePath2)path);
IStoredNode topMost = null;
IStoredNode currentNode = node;
if (currentNode.getNodeType() != Node.ELEMENT_NODE)
Expand All @@ -283,7 +283,7 @@ public <T extends IStoredNode> IStoredNode getReindexRoot(IStoredNode<T> node, N
if (config.matches(p))
topMost = currentNode;
currentNode = currentNode.getParentStoredNode();
p.removeLastComponent();
p.removeLastNode();
}
return topMost;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.exist.storage.DBBroker;
import org.exist.storage.IndexSpec;
import org.exist.storage.NodePath;
import org.exist.storage.NodePath2;
import org.exist.util.serializer.AttrList;
import org.xml.sax.SAXException;

Expand Down Expand Up @@ -313,19 +314,19 @@ private void scanMatches(final NodeProxy p) {
}

private NodePath getPath(final NodeProxy proxy) {
final NodePath path = new NodePath();
final NodePath2 path = new NodePath2();
final IStoredNode<?> node = (IStoredNode<?>) proxy.getNode();
walkAncestor(node, path);
return path;
}

private void walkAncestor(final IStoredNode node, final NodePath path) {
private void walkAncestor(final IStoredNode node, final NodePath2 path) {
if (node == null) {
return;
}
final IStoredNode parent = node.getParentStoredNode();
walkAncestor(parent, path);
path.addComponent(node.getQName());
path.addNode(node);
}

/**
Expand Down
Loading

0 comments on commit 893e726

Please sign in to comment.