jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1393642 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java
Date Wed, 03 Oct 2012 18:12:01 GMT
Author: alexparvulescu
Date: Wed Oct  3 18:12:01 2012
New Revision: 1393642

URL: http://svn.apache.org/viewvc?rev=1393642&view=rev
Log:
OAK-358 QueryEngine Lucene Index support for reference search

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java?rev=1393642&r1=1393641&r2=1393642&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java
Wed Oct  3 18:12:01 2012
@@ -53,6 +53,7 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.MultiFields;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.search.BooleanQuery;
@@ -98,7 +99,7 @@ public class LuceneIndex implements Quer
 
     @Override
     public String getPlan(Filter filter, NodeState root) {
-        return getQuery(filter, root).toString();
+        return getQuery(filter, root, null).toString();
     }
 
     @Override
@@ -124,7 +125,7 @@ public class LuceneIndex implements Quer
                     IndexSearcher searcher = new IndexSearcher(reader);
                     Collection<String> paths = new ArrayList<String>();
 
-                    Query query = getQuery(filter, root);
+                    Query query = getQuery(filter, root, reader);
                     if (query != null) {
                         TopDocs docs = searcher
                                 .search(query, Integer.MAX_VALUE);
@@ -153,7 +154,7 @@ public class LuceneIndex implements Quer
         }
     }
 
-    private static Query getQuery(Filter filter, NodeState root) {
+    private static Query getQuery(Filter filter, NodeState root, IndexReader reader) {
         List<Query> qs = new ArrayList<Query>();
 
         try {
@@ -233,7 +234,11 @@ public class LuceneIndex implements Quer
                 if (JCR_PATH.equals(name)) {
                     qs.add(new TermQuery(newPathTerm(first)));
                 } else {
-                    qs.add(new TermQuery(new Term(name, first)));
+                    if ("*".equals(name)) {
+                        addReferenceConstraint(first, qs, reader);
+                    } else {
+                        qs.add(new TermQuery(new Term(name, first)));
+                    }
                 }
                 continue;
             }
@@ -256,6 +261,23 @@ public class LuceneIndex implements Quer
         return bq;
     }
 
+    private static void addReferenceConstraint(String uuid, List<Query> qs,
+            IndexReader reader) {
+        if (reader == null) {
+            // getPlan call
+            qs.add(new TermQuery(new Term("*", uuid)));
+            return;
+        }
+
+        // reference query
+        BooleanQuery bq = new BooleanQuery();
+        Collection<String> fields = MultiFields.getIndexedFields(reader);
+        for (String f : fields) {
+            bq.add(new TermQuery(new Term(f, uuid)), Occur.SHOULD);
+        }
+        qs.add(bq);
+    }
+
     private static void addNodeTypeConstraints(
             List<Query> qs, String name, NodeState root)
             throws RepositoryException {



Mime
View raw message