jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1482722 - in /jackrabbit/oak/trunk/oak-lucene: pom.xml src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryJcrTest.java
Date Wed, 15 May 2013 08:35:32 GMT
Author: alexparvulescu
Date: Wed May 15 08:35:31 2013
New Revision: 1482722

URL: http://svn.apache.org/r1482722
Log:
OAK-819 Lucene fulltext on node not working properly - WIP

Modified:
    jackrabbit/oak/trunk/oak-lucene/pom.xml
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java
    jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryJcrTest.java

Modified: jackrabbit/oak/trunk/oak-lucene/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/pom.xml?rev=1482722&r1=1482721&r2=1482722&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-lucene/pom.xml Wed May 15 08:35:31 2013
@@ -36,7 +36,12 @@
     <tika.version>1.3</tika.version>
     <lucene.version>4.2.0</lucene.version>
     <known.issues>
-      org.apache.jackrabbit.core.query.FulltextQueryTest <!-- OAK-819 -->
+      org.apache.jackrabbit.core.query.FulltextQueryTest#testFulltextExcludeSQL      <!--
OAK-819 -->
+      org.apache.jackrabbit.core.query.FulltextQueryTest#testFulltextOrSQL           <!--
OAK-819 -->
+      org.apache.jackrabbit.core.query.FulltextQueryTest#testFulltextIntercapSQL     <!--
OAK-819 -->
+      org.apache.jackrabbit.core.query.FulltextQueryTest#testContainsPropScopeSQL    <!--
OAK-819 -->
+      org.apache.jackrabbit.core.query.FulltextQueryTest#testContainsPropScopeXPath  <!--
OAK-819 -->
+      org.apache.jackrabbit.core.query.FulltextQueryTest#testMultiByte               <!--
OAK-819 -->
       org.apache.jackrabbit.core.query.JoinTest#testJoinWithOR4 <!-- OAK-819 -->
       org.apache.jackrabbit.core.query.JoinTest#testJoinWithOR5 <!-- OAK-819 -->
     </known.issues>

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java?rev=1482722&r1=1482721&r2=1482722&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java
Wed May 15 08:35:31 2013
@@ -35,6 +35,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Iterator;
 import java.util.List;
 
 import org.apache.jackrabbit.oak.api.Type;
@@ -55,7 +56,7 @@ import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.MatchAllDocsQuery;
-import org.apache.lucene.search.MultiPhraseQuery;
+import org.apache.lucene.search.PhraseQuery;
 import org.apache.lucene.search.PrefixQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.ScoreDoc;
@@ -353,38 +354,41 @@ public class LuceneIndex implements Full
                 .iterator().next().toLowerCase());
         if (tokens.size() == 1) {
             String token = tokens.get(0);
-            Query q = null;
             if (token.contains(" ")) {
-                // q = new WildcardQuery(newFulltextTerm(token));
-                // PhraseQuery pq = new PhraseQuery();
-                // pq.add(newFulltextTerm(token));
-                // q = pq;
+                PhraseQuery pq = new PhraseQuery();
+                for (String t : token.split(" ")) {
+                    pq.add(newFulltextTerm(t));
+                }
+                qs.add(pq);
             } else {
-                q = new WildcardQuery(newFulltextTerm(token
-                        + WildcardQuery.WILDCARD_STRING));
-            }
-            if (q != null) {
-                qs.add(q);
+                if (!token.endsWith("*")) {
+                    token = token + "*";
+                }
+                qs.add(new WildcardQuery(newFulltextTerm(token)));
             }
             return;
         }
 
         BooleanQuery q = new BooleanQuery();
-        for (String token : tokens) {
-            q.add(new TermQuery(newFulltextTerm(token)), MUST);
-            // if (token.contains(" ")) {
-            // // q = new WildcardQuery(newFulltextTerm(token));
-            // // PhraseQuery pq = new PhraseQuery();
-            // // pq.add(newFulltextTerm(token));
-            // // q = pq;
-            // } else {
-            // q = new WildcardQuery(newFulltextTerm(token
-            // + WildcardQuery.WILDCARD_STRING));
-            // }
+        Iterator<String> iterator = tokens.iterator();
+        while (iterator.hasNext()) {
+            String token = iterator.next();
+            q.add(tokenToQuery(token), MUST);
         }
         qs.add(q);
     }
 
+    private static Query tokenToQuery(String token) {
+        if (token.contains(" ")) {
+            PhraseQuery pq = new PhraseQuery();
+            for (String t : token.split(" ")) {
+                pq.add(newFulltextTerm(t));
+            }
+            return pq;
+        }
+        return new TermQuery(newFulltextTerm(token));
+    }
+
     /**
      * 
      * inspired from lucene's WildcardQuery#toAutomaton
@@ -398,6 +402,7 @@ public class LuceneIndex implements Full
             int length = Character.charCount(c);
             switch (c) {
             case ' ':
+            case '&':
                 if (quote) {
                     token.append(' ');
                 } else if (token.length() > 0) {
@@ -406,6 +411,7 @@ public class LuceneIndex implements Full
                 }
                 break;
             case '"':
+            case '\'':
                 if (quote) {
                     quote = false;
                     if (token.length() > 0) {

Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryJcrTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryJcrTest.java?rev=1482722&r1=1482721&r2=1482722&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryJcrTest.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryJcrTest.java
Wed May 15 08:35:31 2013
@@ -26,6 +26,7 @@ import org.apache.jackrabbit.core.query.
 import org.apache.jackrabbit.core.query.LimitAndOffsetTest;
 import org.apache.jackrabbit.core.query.MixinTest;
 import org.apache.jackrabbit.core.query.OrderByTest;
+import org.apache.jackrabbit.core.query.ParentNodeTest;
 import org.apache.jackrabbit.core.query.PathQueryNodeTest;
 import org.apache.jackrabbit.core.query.SQL2NodeLocalNameTest;
 import org.apache.jackrabbit.core.query.SQL2OffsetLimitTest;
@@ -39,24 +40,24 @@ public class QueryJcrTest extends TestCa
     public static Test suite() {
         TestSuite suite = new ConcurrentTestSuite(
                 "Jackrabbit query tests using a Lucene based index");
-         suite.addTestSuite(FulltextQueryTest.class);
-         suite.addTestSuite(SQLTest.class);
-         suite.addTestSuite(JoinTest.class);
-         suite.addTestSuite(SkipDeletedNodesTest.class);
-         suite.addTestSuite(PathQueryNodeTest.class);
-         suite.addTestSuite(FulltextSQL2QueryTest.class);
-         suite.addTestSuite(SQL2NodeLocalNameTest.class);
-         suite.addTestSuite(MixinTest.class);
-         suite.addTestSuite(SQL2OuterJoinTest.class);
-         suite.addTestSuite(SQL2OffsetLimitTest.class);
-         suite.addTestSuite(LimitAndOffsetTest.class);
+        suite.addTestSuite(FulltextQueryTest.class);
+        suite.addTestSuite(SQLTest.class);
+        suite.addTestSuite(JoinTest.class);
+        suite.addTestSuite(SkipDeletedNodesTest.class);
+        suite.addTestSuite(PathQueryNodeTest.class);
+        suite.addTestSuite(FulltextSQL2QueryTest.class);
+        suite.addTestSuite(SQL2NodeLocalNameTest.class);
+        suite.addTestSuite(MixinTest.class);
+        suite.addTestSuite(SQL2OuterJoinTest.class);
+        suite.addTestSuite(SQL2OffsetLimitTest.class);
+        suite.addTestSuite(LimitAndOffsetTest.class);
         suite.addTestSuite(OrderByTest.class);
+        suite.addTestSuite(ParentNodeTest.class);
 
         // FAILURES
         //
         // suite.addTestSuite(SQL2OrderByTest.class); // order by score is not stable
         // suite.addTestSuite(QueryResultTest.class); // OAK-484
-        // suite.addTestSuite(ParentNodeTest.class); // OAK-309
         // suite.addTestSuite(ExcerptTest.class); // OAK-318
         // suite.addTestSuite(SimilarQueryTest.class); // OAK-319
         // suite.addTestSuite(DerefTest.class); // OAK-321



Mime
View raw message