jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1141717 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/JackrabbitQueryParser.java test/java/org/apache/jackrabbit/core/query/FulltextQueryTest.java
Date Thu, 30 Jun 2011 21:07:21 GMT
Author: mreutegg
Date: Thu Jun 30 21:07:20 2011
New Revision: 1141717

URL: http://svn.apache.org/viewvc?rev=1141717&view=rev
Log:
JCR-3009: Prefix fulltext queries with Japanese or Chinese characters fail to match

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

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JackrabbitQueryParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JackrabbitQueryParser.java?rev=1141717&r1=1141716&r2=1141717&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JackrabbitQueryParser.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JackrabbitQueryParser.java
Thu Jun 30 21:07:20 2011
@@ -16,10 +16,19 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
+import java.io.IOException;
+import java.io.StringReader;
 import java.util.List;
 import java.util.ArrayList;
 
+import javax.xml.stream.events.EndDocument;
+
 import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.Token;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.Tokenizer;
+import org.apache.lucene.analysis.standard.StandardTokenizer;
+import org.apache.lucene.analysis.tokenattributes.TypeAttribute;
 import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.queryParser.ParseException;
 import org.apache.lucene.search.Query;
@@ -149,7 +158,33 @@ public class JackrabbitQueryParser exten
      */
     protected Query getPrefixQuery(String field, String termStr)
             throws ParseException {
-        return getWildcardQuery(field, termStr + "*");
+        // only create a prefix query when the term is a single word / token
+        Analyzer a = getAnalyzer();
+        TokenStream ts = a.tokenStream(field, new StringReader(termStr));
+        int count = 0;
+        boolean isCJ = false;
+        try {
+            TypeAttribute t = ts.addAttribute(TypeAttribute.class);
+            ts.reset();
+            while (ts.incrementToken()) {
+                count++;
+                isCJ = StandardTokenizer.TOKEN_TYPES[StandardTokenizer.CJ].equals(t.type());
+            }
+            ts.end();
+        } catch (IOException e) {
+            throw new ParseException(e.getMessage());
+        } finally {
+            try {
+                ts.close();
+            } catch (IOException e) {
+                // ignore
+            }
+        }
+        if (count > 1 && isCJ) {
+            return getFieldQuery(field, termStr);
+        } else {
+            return getWildcardQuery(field, termStr + "*");
+        }
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/FulltextQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/FulltextQueryTest.java?rev=1141717&r1=1141716&r2=1141717&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/FulltextQueryTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/FulltextQueryTest.java
Thu Jun 30 21:07:20 2011
@@ -263,6 +263,12 @@ public class FulltextQueryTest extends A
 
     }
 
+    public void testMultiByte() throws RepositoryException {
+        String content = "some text with multi byte \u7530\u4e2d characters.";
+
+        executeContainsQuery("\u7530\u4e2d*", content, true);
+    }
+
     public void testPredefinedEntityReference() throws RepositoryException {
         String content = "Max&Moritz";
 



Mime
View raw message