You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2010/01/11 21:06:27 UTC
svn commit: r898042 - in /jackrabbit/trunk/jackrabbit-core/src:
main/java/org/apache/jackrabbit/core/query/lucene/
test/java/org/apache/jackrabbit/core/query/lucene/
test/resources/org/apache/jackrabbit/core/query/lucene/
Author: mreutegg
Date: Mon Jan 11 20:06:26 2010
New Revision: 898042
URL: http://svn.apache.org/viewvc?rev=898042&view=rev
Log:
JCR-2458: Allow basic regexp in namespace prefix of index-rule
Added:
jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java (with props)
jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/
jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config1.xml (with props)
jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config2.xml (with props)
jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config3.xml (with props)
Modified:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java
jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/TestAll.java
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java?rev=898042&r1=898041&r2=898042&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java Mon Jan 11 20:06:26 2010
@@ -16,51 +16,52 @@
*/
package org.apache.jackrabbit.core.query.lucene;
-import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException;
-import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
-import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
-import org.apache.jackrabbit.spi.commons.conversion.ParsingNameResolver;
-import org.apache.jackrabbit.core.state.ItemStateManager;
-import org.apache.jackrabbit.core.state.NodeState;
-import org.apache.jackrabbit.core.state.ItemStateException;
-import org.apache.jackrabbit.core.state.PropertyState;
-import org.apache.jackrabbit.core.state.ChildNodeEntry;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Properties;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.collections.iterators.AbstractIteratorDecorator;
import org.apache.jackrabbit.core.HierarchyManager;
-import org.apache.jackrabbit.core.id.PropertyId;
import org.apache.jackrabbit.core.HierarchyManagerImpl;
-import org.apache.jackrabbit.core.nodetype.xml.AdditionalNamespaceResolver;
+import org.apache.jackrabbit.core.id.PropertyId;
import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.nodetype.xml.AdditionalNamespaceResolver;
import org.apache.jackrabbit.core.query.QueryHandlerContext;
+import org.apache.jackrabbit.core.state.ChildNodeEntry;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.ItemStateManager;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.state.PropertyState;
import org.apache.jackrabbit.core.value.InternalValue;
-import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
-import org.apache.jackrabbit.spi.commons.name.Pattern;
-import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.PathFactory;
import org.apache.jackrabbit.spi.Path;
-import org.apache.jackrabbit.util.ISO9075;
+import org.apache.jackrabbit.spi.PathFactory;
+import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException;
+import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
+import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
+import org.apache.jackrabbit.spi.commons.conversion.ParsingNameResolver;
+import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
+import org.apache.jackrabbit.spi.commons.name.Pattern;
import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
+import org.apache.jackrabbit.util.ISO9075;
import org.apache.lucene.analysis.Analyzer;
-import org.apache.commons.collections.iterators.AbstractIteratorDecorator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.w3c.dom.Attr;
import org.w3c.dom.CharacterData;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.NamespaceException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Iterator;
-import java.util.Collections;
-import java.util.NoSuchElementException;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Properties;
/**
* <code>IndexingConfigurationImpl</code> implements a concrete indexing
@@ -565,8 +566,15 @@
String localPattern = pattern;
int idx = pattern.indexOf(':');
if (idx != -1) {
- // use a dummy local name to get namespace uri
- uri = resolver.getQName(pattern.substring(0, idx) + ":a").getNamespaceURI();
+ String prefix = pattern.substring(0, idx);
+ if (prefix.equals(".*")) {
+ // match all namespaces
+ uri = prefix;
+ } else {
+ // match only single namespace
+ // use a dummy local name to get namespace uri
+ uri = resolver.getQName(prefix + ":a").getNamespaceURI();
+ }
localPattern = pattern.substring(idx + 1);
}
this.pattern = Pattern.name(uri, localPattern);
Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java?rev=898042&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java Mon Jan 11 20:06:26 2010
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.query.lucene;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.jcr.Node;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.jackrabbit.core.id.NodeId;
+import org.apache.jackrabbit.core.query.AbstractQueryTest;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+/**
+ * <code>IndexingConfigurationImplTest</code>...
+ */
+public class IndexingConfigurationImplTest extends AbstractQueryTest {
+
+ private static final Name FOO = NameFactoryImpl.getInstance().create("", "foo");
+
+ private NodeState nState;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ Node n = testRootNode.addNode(nodeName1, ntUnstructured);
+ n.addMixin(mixReferenceable);
+ superuser.save();
+ nState = (NodeState) getSearchIndex().getContext().getItemStateManager().getItemState(
+ new NodeId(n.getIdentifier()));
+ }
+
+ public void testMatchAllNoPrefix() throws Exception {
+ IndexingConfiguration config = createConfig("config1");
+ assertFalse(config.isIndexed(nState, NameConstants.JCR_DATA));
+ assertTrue(config.isIndexed(nState, FOO));
+ }
+
+ public void testRegexpInPrefix() throws Exception {
+ IndexingConfiguration config = createConfig("config2");
+ assertTrue(config.isIndexed(nState, NameConstants.JCR_DATA));
+ assertTrue(config.isIndexed(nState, FOO));
+ }
+
+ public void testMatchAllJCRPrefix() throws Exception {
+ IndexingConfiguration config = createConfig("config3");
+ assertTrue(config.isIndexed(nState, NameConstants.JCR_DATA));
+ assertFalse(config.isIndexed(nState, FOO));
+ }
+
+
+ //----------------------------< internal >----------------------------------
+
+ protected IndexingConfiguration createConfig(String name) throws Exception {
+ IndexingConfiguration config = new IndexingConfigurationImpl();
+ config.init(loadConfig(name), getSearchIndex().getContext(),
+ getSearchIndex().getNamespaceMappings());
+ return config;
+ }
+
+ protected Element loadConfig(String name)
+ throws ParserConfigurationException, IOException, SAXException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ builder.setEntityResolver(new IndexingConfigurationEntityResolver());
+ InputStream in = getClass().getResourceAsStream("indexing_" + name + ".xml");
+ return builder.parse(in).getDocumentElement();
+ }
+}
Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/TestAll.java?rev=898042&r1=898041&r2=898042&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/TestAll.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/TestAll.java Mon Jan 11 20:06:26 2010
@@ -41,6 +41,7 @@
suite.addTestSuite(IndexingAggregateTest.class);
suite.addTestSuite(IndexMigrationTest.class);
suite.addTestSuite(ChainedTermEnumTest.class);
+ suite.addTestSuite(IndexingConfigurationImplTest.class);
return suite;
}
Added: jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config1.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config1.xml?rev=898042&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config1.xml (added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config1.xml Mon Jan 11 20:06:26 2010
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!DOCTYPE configuration SYSTEM "http://jackrabbit.apache.org/dtd/indexing-configuration-1.2.dtd">
+<configuration xmlns:jcr="http://www.jcp.org/jcr/1.0"
+ xmlns:nt="http://www.jcp.org/jcr/nt/1.0">
+
+ <index-rule nodeType="nt:unstructured">
+ <property isRegexp="true">.*</property>
+ </index-rule>
+
+</configuration>
\ No newline at end of file
Propchange: jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config1.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config2.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config2.xml?rev=898042&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config2.xml (added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config2.xml Mon Jan 11 20:06:26 2010
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!DOCTYPE configuration SYSTEM "http://jackrabbit.apache.org/dtd/indexing-configuration-1.2.dtd">
+<configuration xmlns:jcr="http://www.jcp.org/jcr/1.0"
+ xmlns:nt="http://www.jcp.org/jcr/nt/1.0">
+
+ <index-rule nodeType="nt:unstructured">
+ <property isRegexp="true">.*:.*</property>
+ </index-rule>
+
+</configuration>
\ No newline at end of file
Propchange: jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config2.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config3.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config3.xml?rev=898042&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config3.xml (added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config3.xml Mon Jan 11 20:06:26 2010
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!DOCTYPE configuration SYSTEM "http://jackrabbit.apache.org/dtd/indexing-configuration-1.2.dtd">
+<configuration xmlns:jcr="http://www.jcp.org/jcr/1.0"
+ xmlns:nt="http://www.jcp.org/jcr/nt/1.0">
+
+ <index-rule nodeType="nt:unstructured">
+ <property isRegexp="true">jcr:.*</property>
+ </index-rule>
+
+</configuration>
\ No newline at end of file
Propchange: jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config3.xml
------------------------------------------------------------------------------
svn:eol-style = native