Search in sources :

Example 1 with AdditionalNamespaceResolver

use of org.apache.jackrabbit.core.nodetype.xml.AdditionalNamespaceResolver in project jackrabbit by apache.

the class IndexingConfigurationImpl method init.

/**
     * {@inheritDoc}
     */
public void init(Element config, QueryHandlerContext context, NamespaceMappings nsMappings) throws Exception {
    configuration = config;
    ism = context.getItemStateManager();
    hmgr = new HierarchyManagerImpl(context.getRootId(), ism);
    NamespaceResolver nsResolver = new AdditionalNamespaceResolver(getNamespaces(config));
    resolver = new ParsingNameResolver(NameFactoryImpl.getInstance(), nsResolver);
    ntReg = context.getNodeTypeRegistry();
    ntReg.addListener(this);
    refreshIndexRules();
    List<AggregateRule> idxAggregates = new ArrayList<AggregateRule>();
    NodeList indexingConfigs = config.getChildNodes();
    for (int i = 0; i < indexingConfigs.getLength(); i++) {
        Node configNode = indexingConfigs.item(i);
        if (configNode.getNodeName().equals("aggregate")) {
            idxAggregates.add(new AggregateRuleImpl(configNode, resolver, ism, hmgr));
        } else if (configNode.getNodeName().equals("analyzers")) {
            NodeList childNodes = configNode.getChildNodes();
            for (int j = 0; j < childNodes.getLength(); j++) {
                Node analyzerNode = childNodes.item(j);
                if (analyzerNode.getNodeName().equals("analyzer")) {
                    Analyzer analyzer = JackrabbitAnalyzer.getAnalyzerInstance(analyzerNode.getAttributes().getNamedItem("class").getNodeValue());
                    NodeList propertyChildNodes = analyzerNode.getChildNodes();
                    for (int k = 0; k < propertyChildNodes.getLength(); k++) {
                        Node propertyNode = propertyChildNodes.item(k);
                        if (propertyNode.getNodeName().equals("property")) {
                            // get property name
                            Name propName = resolver.getQName(getTextContent(propertyNode));
                            String fieldName = nsMappings.translateName(propName);
                            // set analyzer for the fulltext property fieldname
                            int idx = fieldName.indexOf(':');
                            fieldName = fieldName.substring(0, idx + 1) + FieldNames.FULLTEXT_PREFIX + fieldName.substring(idx + 1);
                            Object prevAnalyzer = analyzers.put(fieldName, analyzer);
                            if (prevAnalyzer != null) {
                                log.warn("Property " + propName.getLocalName() + " has been configured for multiple analyzers. " + " Last configured analyzer is used");
                            }
                        }
                    }
                }
            }
        }
    }
    if (idxAggregates.isEmpty()) {
        aggregateRules = null;
    } else {
        aggregateRules = idxAggregates.toArray(new AggregateRule[idxAggregates.size()]);
    }
}
Also used : ParsingNameResolver(org.apache.jackrabbit.spi.commons.conversion.ParsingNameResolver) AdditionalNamespaceResolver(org.apache.jackrabbit.core.nodetype.xml.AdditionalNamespaceResolver) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Analyzer(org.apache.lucene.analysis.Analyzer) Name(org.apache.jackrabbit.spi.Name) NamespaceResolver(org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver) AdditionalNamespaceResolver(org.apache.jackrabbit.core.nodetype.xml.AdditionalNamespaceResolver) HierarchyManagerImpl(org.apache.jackrabbit.core.HierarchyManagerImpl)

Aggregations

ArrayList (java.util.ArrayList)1 HierarchyManagerImpl (org.apache.jackrabbit.core.HierarchyManagerImpl)1 AdditionalNamespaceResolver (org.apache.jackrabbit.core.nodetype.xml.AdditionalNamespaceResolver)1 Name (org.apache.jackrabbit.spi.Name)1 ParsingNameResolver (org.apache.jackrabbit.spi.commons.conversion.ParsingNameResolver)1 NamespaceResolver (org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1