jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r602853 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/WildcardTermEnum.java test/java/org/apache/jackrabbit/core/query/UpperLowerCaseQueryTest.java
Date Mon, 10 Dec 2007 10:42:30 GMT
Author: mreutegg
Date: Mon Dec 10 02:42:29 2007
New Revision: 602853

URL: http://svn.apache.org/viewvc?rev=602853&view=rev
Log:
JCR-1265: Lower-Case Search-Function works with Upper-Case Searchstring

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardTermEnum.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/UpperLowerCaseQueryTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardTermEnum.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardTermEnum.java?rev=602853&r1=602852&r2=602853&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardTermEnum.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardTermEnum.java
Mon Dec 10 02:42:29 2007
@@ -223,70 +223,82 @@
                 throw new IllegalArgumentException("transform");
             }
 
-            // create range scans
-            List rangeScans = new ArrayList(2);
-            try {
-                int idx = 0;
-                while (idx < pattern.length()
-                        && Character.isLetterOrDigit(pattern.charAt(idx))) {
-                    idx++;
-                }
-                String patternPrefix = pattern.substring(0, idx);
-                if (patternPrefix.length() == 0) {
-                    // scan full property range
-                    String prefix = FieldNames.createNamedValue(propName, "");
-                    String limit = FieldNames.createNamedValue(propName, "\uFFFF");
-                    rangeScans.add(new RangeScan(reader,
-                            new Term(field, prefix), new Term(field, limit)));
-                } else {
-                    // start with initial lower case
-                    StringBuffer lowerLimit = new StringBuffer(patternPrefix.toUpperCase());
-                    lowerLimit.setCharAt(0, Character.toLowerCase(lowerLimit.charAt(0)));
-                    String prefix = FieldNames.createNamedValue(propName, lowerLimit.toString());
-
-                    StringBuffer upperLimit = new StringBuffer(patternPrefix.toLowerCase());
-                    upperLimit.append('\uFFFF');
-                    String limit = FieldNames.createNamedValue(propName, upperLimit.toString());
-                    rangeScans.add(new RangeScan(reader,
-                            new Term(field, prefix), new Term(field, limit)));
-
-                    // second scan with upper case start
-                    prefix = FieldNames.createNamedValue(propName, patternPrefix.toUpperCase());
-                    upperLimit = new StringBuffer(patternPrefix.toLowerCase());
-                    upperLimit.setCharAt(0, Character.toUpperCase(upperLimit.charAt(0)));
-                    upperLimit.append('\uFFFF');
-                    limit = FieldNames.createNamedValue(propName, upperLimit.toString());
-                    rangeScans.add(new RangeScan(reader,
-                            new Term(field, prefix), new Term(field, limit)));
+            // check if pattern never matches
+            boolean neverMatches = false;
+            for (int i = 0; i < pattern.length() && !neverMatches; i++) {
+                if (transform == TRANSFORM_LOWER_CASE) {
+                    neverMatches = Character.isUpperCase(pattern.charAt(i));
+                } else if (transform == TRANSFORM_UPPER_CASE) {
+                    neverMatches = Character.isLowerCase(pattern.charAt(i));
                 }
+            }
+
+            if (!neverMatches) {
+                // create range scans
+                List rangeScans = new ArrayList(2);
+                try {
+                    int idx = 0;
+                    while (idx < pattern.length()
+                            && Character.isLetterOrDigit(pattern.charAt(idx))) {
+                        idx++;
+                    }
+                    String patternPrefix = pattern.substring(0, idx);
+                    if (patternPrefix.length() == 0) {
+                        // scan full property range
+                        String prefix = FieldNames.createNamedValue(propName, "");
+                        String limit = FieldNames.createNamedValue(propName, "\uFFFF");
+                        rangeScans.add(new RangeScan(reader,
+                                new Term(field, prefix), new Term(field, limit)));
+                    } else {
+                        // start with initial lower case
+                        StringBuffer lowerLimit = new StringBuffer(patternPrefix.toUpperCase());
+                        lowerLimit.setCharAt(0, Character.toLowerCase(lowerLimit.charAt(0)));
+                        String prefix = FieldNames.createNamedValue(propName, lowerLimit.toString());
+
+                        StringBuffer upperLimit = new StringBuffer(patternPrefix.toLowerCase());
+                        upperLimit.append('\uFFFF');
+                        String limit = FieldNames.createNamedValue(propName, upperLimit.toString());
+                        rangeScans.add(new RangeScan(reader,
+                                new Term(field, prefix), new Term(field, limit)));
+
+                        // second scan with upper case start
+                        prefix = FieldNames.createNamedValue(propName, patternPrefix.toUpperCase());
+                        upperLimit = new StringBuffer(patternPrefix.toLowerCase());
+                        upperLimit.setCharAt(0, Character.toUpperCase(upperLimit.charAt(0)));
+                        upperLimit.append('\uFFFF');
+                        limit = FieldNames.createNamedValue(propName, upperLimit.toString());
+                        rangeScans.add(new RangeScan(reader,
+                                new Term(field, prefix), new Term(field, limit)));
+                    }
 
-                String prefix = FieldNames.createNamedValue(propName, patternPrefix);
-                // initialize with prefix as dummy value
-                OffsetCharSequence input = new OffsetCharSequence(prefix.length(), prefix,
transform);
-                Matcher matcher = createRegexp(pattern.substring(idx)).matcher(input);
-
-                // do range scans with patter matcher
-                for (Iterator it = rangeScans.iterator(); it.hasNext(); ) {
-                    RangeScan scan = (RangeScan) it.next();
-                    do {
-                        Term t = scan.term();
-                        if (t != null) {
-                            input.setBase(t.text());
-                            if (matcher.reset().matches()) {
-                                orderedTerms.put(t, new Integer(scan.docFreq()));
+                    String prefix = FieldNames.createNamedValue(propName, patternPrefix);
+                    // initialize with prefix as dummy value
+                    OffsetCharSequence input = new OffsetCharSequence(prefix.length(), prefix,
transform);
+                    Matcher matcher = createRegexp(pattern.substring(idx)).matcher(input);
+
+                    // do range scans with patter matcher
+                    for (Iterator it = rangeScans.iterator(); it.hasNext(); ) {
+                        RangeScan scan = (RangeScan) it.next();
+                        do {
+                            Term t = scan.term();
+                            if (t != null) {
+                                input.setBase(t.text());
+                                if (matcher.reset().matches()) {
+                                    orderedTerms.put(t, new Integer(scan.docFreq()));
+                                }
                             }
-                        }
-                    } while (scan.next());
-                }
+                        } while (scan.next());
+                    }
 
-            } finally {
-                // close range scans
-                for (Iterator it = rangeScans.iterator(); it.hasNext(); ) {
-                    RangeScan scan = (RangeScan) it.next();
-                    try {
-                        scan.close();
-                    } catch (IOException e) {
-                        // ignore
+                } finally {
+                    // close range scans
+                    for (Iterator it = rangeScans.iterator(); it.hasNext(); ) {
+                        RangeScan scan = (RangeScan) it.next();
+                        try {
+                            scan.close();
+                        } catch (IOException e) {
+                            // ignore
+                        }
                     }
                 }
             }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/UpperLowerCaseQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/UpperLowerCaseQueryTest.java?rev=602853&r1=602852&r2=602853&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/UpperLowerCaseQueryTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/UpperLowerCaseQueryTest.java
Mon Dec 10 02:42:29 2007
@@ -177,6 +177,13 @@
         }
     }
 
+    public void testWrongCaseNeverMatches() throws RepositoryException {
+        Node n = testRootNode.addNode("node");
+        n.setProperty("foo", "Bar");
+        testRootNode.save();
+        executeXPathQuery(testPath + "/*[jcr:like(fn:lower-case(@foo), 'BA%')]", new Node[]{});
+    }
+
     //----------------------------< internal >----------------------------------
 
     private void check(String[] values, String operation, String queryTerm, boolean[] matches)



Mime
View raw message