jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1371065 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/ test/java/org/apache/jackrabbit/core/query/
Date Thu, 09 Aug 2012 07:43:52 GMT
Author: alexparvulescu
Date: Thu Aug  9 07:43:52 2012
New Revision: 1371065

URL: http://svn.apache.org/viewvc?rev=1371065&view=rev
Log:
JCR-3407 CaseTermQuery #rewrite behavior changes

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/DescendantSelfAxisTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CaseTermQuery.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CaseTermQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CaseTermQuery.java?rev=1371065&r1=1371064&r2=1371065&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CaseTermQuery.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CaseTermQuery.java
Thu Aug  9 07:43:52 2012
@@ -47,6 +47,7 @@ abstract class CaseTermQuery extends Mul
     CaseTermQuery(Term term, int transform) {
         this.term = term;
         this.transform = transform;
+        setRewriteMethod(CONSTANT_SCORE_FILTER_REWRITE);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java?rev=1371065&r1=1371064&r2=1371065&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java
Thu Aug  9 07:43:52 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
+import org.apache.jackrabbit.core.query.lucene.WildcardTermEnum.TermValueFactory;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermEnum;
@@ -65,7 +66,7 @@ public class WildcardQuery extends Query
     /**
      * Creates a term value for a given string.
      */
-    private final WildcardTermEnum.TermValueFactory tvf;
+    private final TermValueFactory tvf;
 
     /**
      * The wildcard pattern.
@@ -144,23 +145,9 @@ public class WildcardQuery extends Query
      */
     @Override
     public Query rewrite(IndexReader reader) throws IOException {
-        Query stdWildcardQuery = new MultiTermQuery() {
-            protected FilteredTermEnum getEnum(IndexReader reader) throws IOException {
-                return new WildcardTermEnum(reader, field, tvf, pattern, transform);
-            }
-
-            /** Prints a user-readable version of this query. */
-            @Override
-            public String toString(String field) {
-                StringBuffer buffer = new StringBuffer();
-                buffer.append(field);
-                buffer.append(':');
-                buffer.append(ToStringUtils.boost(getBoost()));
-                return buffer.toString();
-            }
-        };
         try {
-            multiTermQuery = stdWildcardQuery.rewrite(reader);
+            multiTermQuery = new StdWildcardQuery(field, tvf, pattern,
+                    transform).rewrite(reader);
             return multiTermQuery;
         } catch (BooleanQuery.TooManyClauses e) {
             // MultiTermQuery not possible
@@ -198,6 +185,39 @@ public class WildcardQuery extends Query
         }
     }
 
+    private static class StdWildcardQuery extends MultiTermQuery {
+
+        private final String field;
+        private final TermValueFactory tvf;
+        private final String pattern;
+        private final int transform;
+
+        public StdWildcardQuery(String field, TermValueFactory tvf,
+                String pattern, int transform) {
+            this.field = field;
+            this.tvf = tvf;
+            this.pattern = pattern;
+            this.transform = transform;
+            setRewriteMethod(CONSTANT_SCORE_FILTER_REWRITE);
+        }
+
+        @Override
+        protected FilteredTermEnum getEnum(IndexReader reader)
+                throws IOException {
+            return new WildcardTermEnum(reader, field, tvf, pattern, transform);
+        }
+
+        /** Prints a user-readable version of this query. */
+        @Override
+        public String toString(String field) {
+            StringBuffer buffer = new StringBuffer();
+            buffer.append(field);
+            buffer.append(':');
+            buffer.append(ToStringUtils.boost(getBoost()));
+            return buffer.toString();
+        }
+    }
+
     /**
      * The <code>Weight</code> implementation for this <code>WildcardQuery</code>.
      */

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/DescendantSelfAxisTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/DescendantSelfAxisTest.java?rev=1371065&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/DescendantSelfAxisTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/DescendantSelfAxisTest.java
Thu Aug  9 07:43:52 2012
@@ -0,0 +1,32 @@
+/*
+ * 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.Node;
+import javax.jcr.RepositoryException;
+
+public class DescendantSelfAxisTest extends AbstractQueryTest {
+
+    /**
+     * JCR-3407 CaseTermQuery #rewrite behavior changes
+     */
+    public void testCaseTermQueryNPE() throws RepositoryException {
+        String xpathNPE = "//element(*,nt:unstructured)[fn:lower-case(@jcr:language)='en']//element(*,nt:unstructured)[@jcr:message]/(@jcr:key|@jcr:message)";
+        executeXPathQuery(xpathNPE, new Node[] {});
+    }
+}

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

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/DescendantSelfAxisTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

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=1371065&r1=1371064&r2=1371065&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
Thu Aug  9 07:43:52 2012
@@ -72,6 +72,7 @@ public class TestAll extends TestCase {
         suite.addTestSuite(LimitedAccessQueryTest.class);
         suite.addTestSuite(SQL2OffsetLimitTest.class);
         suite.addTestSuite(SQL2OrderByTest.class);
+        suite.addTestSuite(DescendantSelfAxisTest.class);
 
         return suite;
     }



Mime
View raw message