use of org.exist.storage.IndexSpec in project exist by eXist-db.
the class LuceneMatchListener method reset.
protected void reset(final DBBroker broker, final NodeProxy proxy) {
this.broker = broker;
this.match = proxy.getMatches();
setNextInChain(null);
final IndexSpec indexConf = proxy.getOwnerDocument().getCollection().getIndexConfiguration(broker);
if (indexConf != null) {
config = (LuceneConfig) indexConf.getCustomIndexSpec(LuceneIndex.ID);
} else {
config = LuceneConfig.DEFAULT_CONFIG;
}
getTerms();
nodesWithMatch = new TreeMap<>();
/* Check if an index is defined on an ancestor of the current node.
* If yes, scan the ancestor to get the offset of the first character
* in the current node. For example, if the indexed node is <a>abc<b>de</b></a>
* and we query for //a[text:ngram-contains(., 'de')]/b, proxy will be a <b> node, but
* the offsets of the matches are relative to the start of <a>.
*/
NodeSet ancestors = null;
Match nextMatch = this.match;
while (nextMatch != null) {
if (proxy.getNodeId().isDescendantOf(nextMatch.getNodeId())) {
if (ancestors == null) {
ancestors = new NewArrayNodeSet();
}
ancestors.add(new NodeProxy(proxy.getOwnerDocument(), nextMatch.getNodeId()));
}
nextMatch = nextMatch.getNextMatch();
}
if (ancestors != null && !ancestors.isEmpty()) {
for (final NodeProxy p : ancestors) {
scanMatches(p);
}
}
}
use of org.exist.storage.IndexSpec in project exist by eXist-db.
the class NGramIndexWorker method getDefinedIndexes.
/**
* Check index configurations for all collection in the given DocumentSet and return
* a list of QNames, which have indexes defined on them.
*
* @param broker the database broker
* @param docs documents
*/
private List<QName> getDefinedIndexes(final DBBroker broker, final DocumentSet docs) {
final List<QName> indexes = new ArrayList<>(20);
for (final Iterator<Collection> i = docs.getCollectionIterator(); i.hasNext(); ) {
final Collection collection = i.next();
final IndexSpec idxConf = collection.getIndexConfiguration(broker);
if (idxConf != null) {
final Map<?, ?> config = (Map<?, ?>) idxConf.getCustomIndexSpec(NGramIndex.ID);
if (config != null) {
for (final Object name : config.keySet()) {
indexes.add((QName) name);
}
}
}
}
return indexes;
}
use of org.exist.storage.IndexSpec in project exist by eXist-db.
the class NGramIndexWorker method getReindexRoot.
@Override
public <T extends IStoredNode> IStoredNode getReindexRoot(final IStoredNode<T> node, final NodePath path, final boolean insert, final boolean includeSelf) {
if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
return null;
}
final IndexSpec indexConf = node.getOwnerDocument().getCollection().getIndexConfiguration(broker);
if (indexConf != null) {
final Map<?, ?> config = (Map<?, ?>) indexConf.getCustomIndexSpec(NGramIndex.ID);
if (config == null) {
return null;
}
boolean reindexRequired = false;
final int len = node.getNodeType() == Node.ELEMENT_NODE && !includeSelf ? path.length() - 1 : path.length();
for (int i = 0; i < len; i++) {
final QName qn = path.getComponent(i);
if (config.get(qn) != null) {
reindexRequired = true;
break;
}
}
if (reindexRequired) {
IStoredNode topMost = null;
IStoredNode<T> currentNode = node;
while (currentNode != null) {
if (config.get(currentNode.getQName()) != null) {
topMost = currentNode;
}
if (currentNode.getOwnerDocument().getCollection().isTempCollection() && currentNode.getNodeId().getTreeLevel() == 2) {
break;
}
// currentNode = (StoredNode) currentNode.getParentNode();
currentNode = currentNode.getParentStoredNode();
}
return topMost;
}
}
return null;
}
use of org.exist.storage.IndexSpec in project exist by eXist-db.
the class FieldLookup method getType.
public int getType(Sequence contextSequence, String field) {
if (contextSequence == null) {
return Type.ITEM;
}
for (final Iterator<Collection> i = contextSequence.getCollectionIterator(); i.hasNext(); ) {
final Collection collection = i.next();
if (collection.getURI().startsWith(XmldbURI.SYSTEM_COLLECTION_URI)) {
continue;
}
IndexSpec idxConf = collection.getIndexConfiguration(context.getBroker());
if (idxConf != null) {
RangeIndexConfig config = (RangeIndexConfig) idxConf.getCustomIndexSpec(RangeIndex.ID);
if (config != null) {
int type = config.getType(field);
if (type != Type.ITEM) {
return type;
}
}
}
}
return Type.ITEM;
}
use of org.exist.storage.IndexSpec in project exist by eXist-db.
the class OptimizeFieldPragma method getConfigurations.
private List<RangeIndexConfig> getConfigurations(Sequence contextSequence) {
List<RangeIndexConfig> configs = new ArrayList<>();
for (final Iterator<Collection> i = contextSequence.getCollectionIterator(); i.hasNext(); ) {
final Collection collection = i.next();
if (collection.getURI().startsWith(XmldbURI.SYSTEM_COLLECTION_URI)) {
continue;
}
IndexSpec idxConf = collection.getIndexConfiguration(context.getBroker());
if (idxConf != null) {
final RangeIndexConfig config = (RangeIndexConfig) idxConf.getCustomIndexSpec(RangeIndex.ID);
if (config != null) {
configs.add(config);
}
}
}
return configs;
}
Aggregations