jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r677952 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/ main/resources/org/apache/jackrabbit/core/query/lucene/ test/java/org/apache/jackrabbit/core/query/ test/repository/workspaces/indexing-t...
Date Fri, 18 Jul 2008 16:02:00 GMT
Author: mreutegg
Date: Fri Jul 18 09:01:59 2008
New Revision: 677952

URL: http://svn.apache.org/viewvc?rev=677952&view=rev
Log:
JCR-1369: indexing-rules should allow wildcards for (global) property names

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/query/lucene/indexing-configuration-1.1.dtd
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractIndexingTest.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/IndexingRuleTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationEntityResolver.java
    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/IndexingAggregateTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
    jackrabbit/trunk/jackrabbit-core/src/test/repository/workspaces/indexing-test/indexing-configuration.xml

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationEntityResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationEntityResolver.java?rev=677952&r1=677951&r2=677952&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationEntityResolver.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationEntityResolver.java
Fri Jul 18 09:01:59 2008
@@ -22,6 +22,9 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collections;
 
 /**
  * <code>IndexingConfigurationEntityResolver</code> implements an entity
@@ -30,23 +33,29 @@
 public class IndexingConfigurationEntityResolver implements EntityResolver {
 
     /**
-     * The system id of the indexing configuration DTD.
+     * Maps system ids to DTD resource names.
      */
-    private static final String SYSTEM_ID =
-            "http://jackrabbit.apache.org/dtd/indexing-configuration-1.0.dtd";
+    private static final Map SYSTEM_IDS;
 
-    /**
-     * The name of the DTD resource.
-     */
-    private static final String RESOURCE_NAME = "indexing-configuration-1.0.dtd";
+    static {
+        Map systemIds = new HashMap();
+        systemIds.put(
+                "http://jackrabbit.apache.org/dtd/indexing-configuration-1.0.dtd",
+                "indexing-configuration-1.0.dtd");
+        systemIds.put(
+                "http://jackrabbit.apache.org/dtd/indexing-configuration-1.1.dtd",
+                "indexing-configuration-1.1.dtd");
+        SYSTEM_IDS = Collections.unmodifiableMap(systemIds);
+    }
 
     /**
      * {@inheritDoc}
      */
     public InputSource resolveEntity(String publicId, String systemId)
             throws SAXException, IOException {
-        if (SYSTEM_ID.equals(systemId)) {
-            InputStream in = getClass().getResourceAsStream(RESOURCE_NAME);
+        String resourceName = (String) SYSTEM_IDS.get(systemId);
+        if (resourceName != null) {
+            InputStream in = getClass().getResourceAsStream(resourceName);
             if (in != null) {
                 return new InputSource(in);
             }

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=677952&r1=677951&r2=677952&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
Fri Jul 18 09:01:59 2008
@@ -32,7 +32,11 @@
 import org.apache.jackrabbit.core.query.QueryHandlerContext;
 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.commons.namespace.NamespaceResolver;
 import org.apache.lucene.analysis.Analyzer;
@@ -69,6 +73,11 @@
     private static final Logger log = LoggerFactory.getLogger(IndexingConfigurationImpl.class);
 
     /**
+     * The path factory instance.
+     */
+    private static final PathFactory PATH_FACTORY = PathFactoryImpl.getInstance();
+
+    /**
      * A namespace resolver for parsing QNames in the configuration.
      */
     private NameResolver resolver;
@@ -155,7 +164,7 @@
                                         // set analyzer for the fulltext property fieldname
                                         int idx = fieldName.indexOf(':');
                                         fieldName = fieldName.substring(0, idx + 1)
-                                                    + FieldNames.FULLTEXT_PREFIX + fieldName.substring(idx
+ 1);;
+                                                    + FieldNames.FULLTEXT_PREFIX + fieldName.substring(idx
+ 1);
                                         Object prevAnalyzer = analyzers.put(fieldName, analyzer);
                                         if (prevAnalyzer != null) {
                                             log.warn("Property " + propName.getLocalName()
@@ -343,15 +352,18 @@
      * Creates property configurations defined in the <code>config</code>.
      *
      * @param config the fulltext indexing configuration.
-     * @return the property configurations defined in the <code>config</code>.
+     * @param propConfigs will be filled with exact <code>Name</code> to
+     *                    <code>PropertyConfig</code> mappings.
+     * @param namePatterns will be filled with <code>NamePattern</code>s.
      * @throws IllegalNameException   if the node type name contains illegal
      *                                characters.
      * @throws NamespaceException if the node type contains an unknown
      *                                prefix.
      */
-    private Map getPropertyConfigs(Node config)
+    private void createPropertyConfigs(Node config,
+                                       Map propConfigs,
+                                       List namePatterns)
             throws IllegalNameException, NamespaceException {
-        Map configs = new HashMap();
         NodeList childNodes = config.getChildNodes();
         for (int i = 0; i < childNodes.getLength(); i++) {
             Node n = childNodes.item(i);
@@ -376,13 +388,25 @@
                             nsIndex.getNodeValue()).booleanValue();
                 }
 
-                // get property name
-                Name propName = resolver.getQName(getTextContent(n));
-
-                configs.put(propName, new PropertyConfig(boost, nodeScopeIndex));
+                // get isRegexp flag
+                boolean isRegexp = false;
+                Node regexp = attributes.getNamedItem("isRegexp");
+                if (regexp != null) {
+                    isRegexp = Boolean.valueOf(
+                            regexp.getNodeValue()).booleanValue();
+                }
+
+                PropertyConfig pc = new PropertyConfig(boost, nodeScopeIndex);
+
+                if (isRegexp) {
+                    namePatterns.add(new NamePattern(
+                            getTextContent(n), pc, resolver));
+                } else {
+                    Name propName = resolver.getQName(getTextContent(n));
+                    propConfigs.put(propName, pc);
+                }
             }
         }
-        return configs;
     }
 
     /**
@@ -484,6 +508,66 @@
         return content.toString();
     }
 
+    /**
+     * A property name pattern.
+     */
+    private static final class NamePattern {
+
+        /**
+         * The pattern to match.
+         */
+        private final Pattern pattern;
+
+        /**
+         * The associated configuration.
+         */
+        private final PropertyConfig config;
+
+        /**
+         * Creates a new name pattern.
+         *
+         * @param pattern the pattern as read from the configuration file.
+         * @param config the associated configuration.
+         * @param resolver a namespace resolver for parsing name from the
+         *                 configuration.
+         * @throws IllegalNameException if the prefix of the name pattern is
+         *                              illegal.
+         * @throws NamespaceException if the prefix of the name pattern cannot
+         *                            be resolved.
+         */
+        private NamePattern(String pattern,
+                            PropertyConfig config,
+                            NameResolver resolver)
+                throws IllegalNameException, NamespaceException {
+            String uri = Name.NS_DEFAULT_URI;
+            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();
+                localPattern = pattern.substring(idx + 1);
+            }
+            this.pattern = Pattern.name(uri, localPattern);
+            this.config = config;
+        }
+
+        /**
+         * @param path the path to match.
+         * @return <code>true</code> if <code>path</code> matches
this name
+         *         pattern; <code>false</code> otherwise.
+         */
+        boolean matches(Path path) {
+            return pattern.match(path).isFullMatch();
+        }
+
+        /**
+         * @return the property configuration for this name pattern.
+         */
+        PropertyConfig getConfig() {
+            return config;
+        }
+    }
+
     private class IndexingRule {
 
         /**
@@ -494,7 +578,12 @@
         /**
          * Map of {@link PropertyConfig}. Key=Name of property.
          */
-        private final Map propConfigs;
+        private final Map propConfigs = new HashMap();
+
+        /**
+         * List of {@link NamePattern}s.
+         */
+        private final List namePatterns = new ArrayList();
 
         /**
          * An expression based on a relative path.
@@ -516,9 +605,9 @@
         IndexingRule(Node config)
                 throws MalformedPathException, IllegalNameException, NamespaceException {
             this.nodeTypeName = getNodeTypeName(config);
-            this.propConfigs = getPropertyConfigs(config);
             this.condition = getCondition(config);
             this.boost = getNodeBoost(config);
+            createPropertyConfigs(config, propConfigs, namePatterns);
         }
 
         /**
@@ -546,7 +635,7 @@
          *         <code>false</code> otherwise.
          */
         public boolean isIndexed(Name propertyName) {
-            return propConfigs.containsKey(propertyName);
+            return getConfig(propertyName) != null;
         }
 
         /**
@@ -558,7 +647,7 @@
          * @return the boost value for the property.
          */
         public float getBoost(Name propertyName) {
-            PropertyConfig config = (PropertyConfig) propConfigs.get(propertyName);
+            PropertyConfig config = getConfig(propertyName);
             if (config != null) {
                 return config.boost;
             } else {
@@ -568,7 +657,7 @@
 
         /**
          * Returns <code>true</code> if the property with the given name should
-         * be included in the node scope fulltext index. If there is not
+         * be included in the node scope fulltext index. If there is no
          * configuration entry for that propery <code>false</code> is returned.
          *
          * @param propertyName the name of a property.
@@ -576,7 +665,7 @@
          *         node scope fulltext index.
          */
         public boolean isIncludedInNodeScopeIndex(Name propertyName) {
-            PropertyConfig config = (PropertyConfig) propConfigs.get(propertyName);
+            PropertyConfig config = getConfig(propertyName);
             if (config != null) {
                 return config.nodeScopeIndex;
             } else {
@@ -606,6 +695,29 @@
         //-------------------------< internal >---------------------------------
 
         /**
+         * @param propertyName name of a property.
+         * @return the property configuration or <code>null</code> if this
+         *         indexing rule does not contain a configuration for the given
+         *         property.
+         */
+        private PropertyConfig getConfig(Name propertyName) {
+            PropertyConfig config = (PropertyConfig) propConfigs.get(propertyName);
+            if (config != null) {
+                return config;
+            } else if (namePatterns.size() > 0) {
+                Path path = PATH_FACTORY.create(propertyName);
+                // check patterns
+                for (Iterator it = namePatterns.iterator(); it.hasNext(); ) {
+                    NamePattern np = (NamePattern) it.next();
+                    if (np.matches(path)) {
+                        return np.getConfig();
+                    }
+                }
+            }
+            return null;
+        }
+
+        /**
          * Reads the node type of the root node of the indexing rule.
          *
          * @param config the configuration.
@@ -713,7 +825,7 @@
                         NodeState.ChildNodeEntry cne =
                                 (NodeState.ChildNodeEntry) super.next();
                         try {
-                            return (NodeState) ism.getItemState(cne.getId());
+                            return ism.getItemState(cne.getId());
                         } catch (ItemStateException e) {
                             NoSuchElementException nsee = new NoSuchElementException("No
node with id " + cne.getId() + " found in child axis");
                             nsee.initCause(e);

Added: jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/query/lucene/indexing-configuration-1.1.dtd
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/query/lucene/indexing-configuration-1.1.dtd?rev=677952&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/query/lucene/indexing-configuration-1.1.dtd
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/query/lucene/indexing-configuration-1.1.dtd
Fri Jul 18 09:01:59 2008
@@ -0,0 +1,81 @@
+<!--
+   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.
+-->
+<!--
+    The configuration element configures the indexing behaviour of the lucene
+    backed query handler in Jackrabbit. It allows you to define indexing
+    aggregates and configure which properties of a node are indexed.
+    This element must contain all the namespace declarations that are used
+    throughout this configuration.
+-->
+<!ELEMENT configuration (aggregate*,index-rule*)>
+
+<!--
+    Each aggregate element defines an indexing aggregate based on the name of a
+    primary node type.
+-->
+<!ELEMENT aggregate (include*)>
+<!ATTLIST aggregate primaryType CDATA #REQUIRED>
+
+<!--
+    An include element contains a relative path pattern using either an exact
+    node name or *. Nodes that match the path pattern against the root of an
+    indexing aggregate are included in the aggregated node index. An include
+    element may optionally specify a primary node type name that needs to match
+    for the included node.
+-->
+<!ELEMENT include (#PCDATA)>
+<!ATTLIST include primaryType CDATA #IMPLIED>
+
+<!--
+    An index-rule element defines which properties of a node should be indexed.
+    When a node is indexed the list of index-rules is check for a matching
+    node type and whether the condition is true. If a match is found the
+    property is looked up.
+    The index-rule element also contains a boost value for the entire node
+    being indexed. A value higher than 1.0 will boost the score value for a node
+    that matched this index-rule.
+-->
+<!ELEMENT index-rule (property*)>
+<!ATTLIST index-rule nodeType CDATA #REQUIRED
+                     condition CDATA #IMPLIED
+                     boost CDATA "1.0">
+
+<!--
+    A property element defines the boost value for a matching property and a
+    flag that indicates whether the value of a string property should also be
+    included in the node scope fulltext index. Both boost and nodeScopeIndex
+    attributes only affect string properties and are ignored if the property
+    is not of type string. If isRegexp is set to true the name of the property
+    is interpreted as a regular expression to match properties on a node. Please
+    note that you may only use a regular expression for the local part of a
+    property name.
+-->
+<!ELEMENT property (#PCDATA)>
+<!ATTLIST property boost CDATA "1.0"
+                   nodeScopeIndex CDATA "true"
+                   isRegexp CDATA "false">
+
+<!--
+    An analyzer element with property elements in it defines which analyzer is to
+    be used for indexing and parsing the full text of this property. If the analyzer
+    class can not be found, the default analyzer is used. The node scope is always
+    indexed with the default analyzer, so might return different results for search
+    queries in some rare cases.
+-->
+<!ELEMENT analyzers (analyzer*)>
+<!ELEMENT analyzer (property*)>
+<!ATTLIST analyzer class CDATA #REQUIRED>

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/query/lucene/indexing-configuration-1.1.dtd
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractIndexingTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractIndexingTest.java?rev=677952&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractIndexingTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractIndexingTest.java
Fri Jul 18 09:01:59 2008
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+import javax.jcr.Session;
+import javax.jcr.Node;
+
+/**
+ * <code>AbstractIndexingTest</code> is a base class for all indexing
+ * configuration tests.
+ */
+public class AbstractIndexingTest extends AbstractQueryTest {
+
+    protected Session session;
+
+    protected Node testRootNode;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        session = helper.getSuperuserSession("indexing-test");
+        testRootNode = cleanUpTestRoot(session);
+        // overwrite query manager
+        qm = session.getWorkspace().getQueryManager();
+    }
+
+    protected void tearDown() throws Exception {
+        cleanUpTestRoot(session);
+        session = null;
+        testRootNode = null;
+        super.tearDown();
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractIndexingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/IndexingAggregateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/IndexingAggregateTest.java?rev=677952&r1=677951&r2=677952&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/IndexingAggregateTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/IndexingAggregateTest.java
Fri Jul 18 09:01:59 2008
@@ -18,7 +18,6 @@
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Node;
-import javax.jcr.Session;
 import java.io.ByteArrayOutputStream;
 import java.io.Writer;
 import java.io.OutputStreamWriter;
@@ -30,26 +29,7 @@
  * <code>IndexingAggregateTest</code> checks if the nt:file nt:resource
  * aggregate defined in workspace indexing-test works properly.
  */
-public class IndexingAggregateTest extends AbstractQueryTest {
-
-    private Session session;
-
-    private Node testRootNode;
-
-    protected void setUp() throws Exception {
-        super.setUp();
-        session = helper.getSuperuserSession("indexing-test");
-        testRootNode = cleanUpTestRoot(session);
-        // overwrite query manager
-        qm = session.getWorkspace().getQueryManager();
-    }
-
-    protected void tearDown() throws Exception {
-        cleanUpTestRoot(session);
-        session = null;
-        testRootNode = null;
-        super.tearDown();
-    }
+public class IndexingAggregateTest extends AbstractIndexingTest {
 
     public void testNtFileAggregate() throws RepositoryException, IOException {
         String sqlBase = "SELECT * FROM nt:file"

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/IndexingRuleTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/IndexingRuleTest.java?rev=677952&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/IndexingRuleTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/IndexingRuleTest.java
Fri Jul 18 09:01:59 2008
@@ -0,0 +1,85 @@
+/*
+ * 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;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+/**
+ * <code>IndexingRuleTest</code> performs indexing rule tests.
+ */
+public class IndexingRuleTest extends AbstractIndexingTest {
+
+    private static final String NT_UNSTRUCTURED = "nt:unstructured";
+
+    private static final String TEXT = "the quick brown fox jumps over the lazy dog";
+
+    public void testRegexp() throws RepositoryException {
+        Node node1 = testRootNode.addNode(nodeName1, NT_UNSTRUCTURED);
+        node1.setProperty("rule", "regexp");
+        node1.setProperty("Text", "foo");
+        Node node2 = testRootNode.addNode(nodeName2, NT_UNSTRUCTURED);
+        node2.setProperty("rule", "regexp");
+        node2.setProperty("OtherText", "foo");
+        Node node3 = testRootNode.addNode(nodeName3, NT_UNSTRUCTURED);
+        node3.setProperty("rule", "regexp");
+        node3.setProperty("Textle", "foo");
+        testRootNode.save();
+        String stmt = "/jcr:root" + testRootNode.getPath() +
+                "/*[jcr:contains(., 'foo')]";
+        checkResult(executeQuery(stmt), new Node[]{node1, node2});
+    }
+
+    public void testBoost() throws RepositoryException {
+        Node node1 = testRootNode.addNode(nodeName1, NT_UNSTRUCTURED);
+        node1.setProperty("rule", "boost1");
+        node1.setProperty("text", TEXT);
+        Node node2 = testRootNode.addNode(nodeName2, NT_UNSTRUCTURED);
+        node2.setProperty("rule", "boost2");
+        node2.setProperty("text", TEXT);
+        Node node3 = testRootNode.addNode(nodeName3, NT_UNSTRUCTURED);
+        node3.setProperty("rule", "boost3");
+        node3.setProperty("text", TEXT);
+        testRootNode.save();
+        String stmt = "/jcr:root" + testRootNode.getPath() +
+                "/*[jcr:contains(@text, 'quick')] order by @jcr:score descending";
+        List names = new ArrayList();
+        for (NodeIterator it = executeQuery(stmt).getNodes(); it.hasNext(); ) {
+            names.add(it.nextNode().getName());
+        }
+        assertEquals("Wrong sequence or number of results.",
+                Arrays.asList(new String[]{nodeName3, nodeName2, nodeName1}),
+                names);
+    }
+
+    public void testNodeScopeIndex() throws RepositoryException {
+        Node node1 = testRootNode.addNode(nodeName1, NT_UNSTRUCTURED);
+        node1.setProperty("rule", "nsiTrue");
+        node1.setProperty("text", TEXT);
+        Node node2 = testRootNode.addNode(nodeName2, NT_UNSTRUCTURED);
+        node2.setProperty("rule", "nsiFalse");
+        node2.setProperty("text", TEXT);
+        testRootNode.save();
+        String stmt = "/jcr:root" + testRootNode.getPath() +
+                "/*[jcr:contains(., 'quick')]";
+        checkResult(executeQuery(stmt), new Node[]{node1});
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/IndexingRuleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java?rev=677952&r1=677951&r2=677952&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
Fri Jul 18 09:01:59 2008
@@ -57,6 +57,7 @@
         suite.addTestSuite(ExcerptTest.class);
         suite.addTestSuite(IndexingAggregateTest.class);
         suite.addTestSuite(IndexFormatVersionTest.class);
+        suite.addTestSuite(IndexingRuleTest.class);
 
         return suite;
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/repository/workspaces/indexing-test/indexing-configuration.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/repository/workspaces/indexing-test/indexing-configuration.xml?rev=677952&r1=677951&r2=677952&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/repository/workspaces/indexing-test/indexing-configuration.xml
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/repository/workspaces/indexing-test/indexing-configuration.xml
Fri Jul 18 09:01:59 2008
@@ -1,11 +1,40 @@
 <?xml version="1.0"?>
-<!DOCTYPE configuration SYSTEM "http://jackrabbit.apache.org/dtd/indexing-configuration-1.0.dtd">
+<!DOCTYPE configuration SYSTEM "http://jackrabbit.apache.org/dtd/indexing-configuration-1.1.dtd">
 <configuration xmlns:jcr="http://www.jcp.org/jcr/1.0"
                xmlns:nt="http://www.jcp.org/jcr/nt/1.0">
 
-  <aggregate primaryType="nt:file">
-    <include>jcr:content</include>
-    <include>jcr:content/*</include>
-  </aggregate>
+    <index-rule nodeType="nt:unstructured" condition="@rule='boost1'">
+        <!-- default boost: 1.0 -->
+        <property>text</property>
+    </index-rule>
+
+    <index-rule nodeType="nt:unstructured" condition="@rule='boost2'">
+        <!-- boost: 2.0 -->
+        <property boost="2.0">text</property>
+    </index-rule>
+
+    <index-rule nodeType="nt:unstructured" condition="@rule='boost3'">
+        <!-- boost: 3.0 -->
+        <property boost="3.0">text</property>
+    </index-rule>
+
+    <index-rule nodeType="nt:unstructured" condition="@rule='nsiTrue'">
+        <!-- default value for nodeScopeIndex is true -->
+        <property>text</property>
+    </index-rule>
+
+    <index-rule nodeType="nt:unstructured" condition="@rule='nsiFalse'">
+        <!-- do not include text in node scope index -->
+        <property nodeScopeIndex="false">text</property>
+    </index-rule>
+
+    <index-rule nodeType="nt:unstructured" condition="@rule='regexp'">
+        <property isRegexp="true">.*Text</property>
+    </index-rule>
+
+    <aggregate primaryType="nt:file">
+        <include>jcr:content</include>
+        <include>jcr:content/*</include>
+    </aggregate>
 
 </configuration>
\ No newline at end of file



Mime
View raw message