Search in sources :

Example 1 with IndexSpec

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 &lt;a>abc&lt;b>de&lt;/b></a>
        * and we query for //a[text:ngram-contains(., 'de')]/b, proxy will be a &lt;b> node, but
        * the offsets of the matches are relative to the start of &lt;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);
        }
    }
}
Also used : NodeSet(org.exist.dom.persistent.NodeSet) NewArrayNodeSet(org.exist.dom.persistent.NewArrayNodeSet) NewArrayNodeSet(org.exist.dom.persistent.NewArrayNodeSet) IndexSpec(org.exist.storage.IndexSpec) NodeProxy(org.exist.dom.persistent.NodeProxy) Match(org.exist.dom.persistent.Match)

Example 2 with IndexSpec

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;
}
Also used : IndexSpec(org.exist.storage.IndexSpec) QName(org.exist.dom.QName) Collection(org.exist.collections.Collection)

Example 3 with IndexSpec

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;
}
Also used : IndexSpec(org.exist.storage.IndexSpec) QName(org.exist.dom.QName) IStoredNode(org.exist.dom.persistent.IStoredNode)

Example 4 with IndexSpec

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;
}
Also used : IndexSpec(org.exist.storage.IndexSpec) Collection(org.exist.collections.Collection) RangeIndexConfig(org.exist.indexing.range.RangeIndexConfig)

Example 5 with IndexSpec

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;
}
Also used : IndexSpec(org.exist.storage.IndexSpec) Collection(org.exist.collections.Collection)

Aggregations

IndexSpec (org.exist.storage.IndexSpec)16 Collection (org.exist.collections.Collection)7 QName (org.exist.dom.QName)4 RangeIndexConfig (org.exist.indexing.range.RangeIndexConfig)2 Element (org.w3c.dom.Element)2 NamedNodeMap (org.w3c.dom.NamedNodeMap)2 NodeList (org.w3c.dom.NodeList)2 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 IStoredNode (org.exist.dom.persistent.IStoredNode)1 Match (org.exist.dom.persistent.Match)1 NewArrayNodeSet (org.exist.dom.persistent.NewArrayNodeSet)1 NodeProxy (org.exist.dom.persistent.NodeProxy)1 NodeSet (org.exist.dom.persistent.NodeSet)1 RangeIndexConfigElement (org.exist.indexing.range.RangeIndexConfigElement)1 NodePath (org.exist.storage.NodePath)1 DatabaseConfigurationException (org.exist.util.DatabaseConfigurationException)1 Node (org.w3c.dom.Node)1