You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2014/11/27 12:30:34 UTC

svn commit: r1642098 - in /jackrabbit/oak/branches/1.0: ./ oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/

Author: chetanm
Date: Thu Nov 27 11:30:33 2014
New Revision: 1642098

URL: http://svn.apache.org/r1642098
Log:
OAK-2277 - Field for analyzed field should use different name

Merging revisions 1640864

Modified:
    jackrabbit/oak/branches/1.0/   (props changed)
    jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/FieldNames.java
    jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java
    jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java

Propchange: jackrabbit/oak/branches/1.0/
------------------------------------------------------------------------------
  Merged /jackrabbit/oak/trunk:r1640864

Modified: jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/FieldNames.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/FieldNames.java?rev=1642098&r1=1642097&r2=1642098&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/FieldNames.java (original)
+++ jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/FieldNames.java Thu Nov 27 11:30:33 2014
@@ -43,6 +43,11 @@ public final class FieldNames {
     public static final String FULLTEXT = ":fulltext";
 
     /**
+     * Prefix for all field names that are fulltext indexed by property name.
+     */
+    public static final String FULLTEXT_PREFIX = ":full";
+
+    /**
      * Used to select only the PATH field from the lucene documents
      */
     public static final Set<String> PATH_SELECTOR = new HashSet<String>(
@@ -60,4 +65,7 @@ public final class FieldNames {
         return ":dv" + name;
     }
 
+    public static String createAnalyzedFieldName(String pname) {
+        return FULLTEXT_PREFIX + pname;
+    }
 }

Modified: jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java?rev=1642098&r1=1642097&r2=1642098&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java (original)
+++ jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java Thu Nov 27 11:30:33 2014
@@ -349,7 +349,8 @@ public class LuceneIndexEditor implement
                     //as term field use the same name. For compatibility this should be done
                     //for newer index versions only
                     if (pd.analyzed) {
-                        fields.add(newPropertyField(pname, value, !pd.skipTokenization(pname), pd.stored));
+                        String analyzedPropName = constructAnalyzedPropertyName(pname);
+                        fields.add(newPropertyField(analyzedPropName, value, !pd.skipTokenization(pname), pd.stored));
                         //TODO Property field uses OakType which has omitNorms set hence
                         //cannot be boosted
                     }
@@ -366,6 +367,13 @@ public class LuceneIndexEditor implement
         }
     }
 
+    private String constructAnalyzedPropertyName(String pname) {
+        if (context.getDefinition().getVersion().isAtLeast(IndexFormatVersion.V2)){
+            return FieldNames.createAnalyzedFieldName(pname);
+        }
+        return pname;
+    }
+
     private boolean addTypedFields(List<Field> fields, PropertyState property, String pname) throws CommitFailedException {
         int tag = property.getType().tag();
         boolean fieldAdded = false;

Modified: jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java?rev=1642098&r1=1642097&r2=1642098&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java (original)
+++ jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java Thu Nov 27 11:30:33 2014
@@ -103,7 +103,6 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.commons.PathUtils.denotesRoot;
 import static org.apache.jackrabbit.oak.commons.PathUtils.getAncestorPath;
 import static org.apache.jackrabbit.oak.commons.PathUtils.getDepth;
-import static org.apache.jackrabbit.oak.commons.PathUtils.getName;
 import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.FieldNames.PATH;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.VERSION;
@@ -494,16 +493,17 @@ public class LucenePropertyIndex impleme
         List<Query> qs = new ArrayList<Query>();
         Filter filter = plan.getFilter();
         FullTextExpression ft = filter.getFullTextConstraint();
+        PlanResult planResult = pr(plan);
+        IndexDefinition defn = planResult.indexDefinition;
         if (ft == null) {
             // there might be no full-text constraint
             // when using the LowCostLuceneIndexProvider
             // which is used for testing
         } else {
-            qs.add(getFullTextQuery(ft, analyzer, reader));
+            qs.add(getFullTextQuery(defn, ft, analyzer, reader));
         }
 
-        PlanResult planResult = pr(plan);
-        IndexDefinition defn = planResult.indexDefinition;
+
         //Check if native function is supported
         PropertyRestriction pr = null;
         if (defn.hasFunctionDefined()) {
@@ -856,7 +856,8 @@ public class LucenePropertyIndex impleme
         }
     }
 
-    static Query getFullTextQuery(FullTextExpression ft, final Analyzer analyzer, final IndexReader reader) {
+    static Query getFullTextQuery(final IndexDefinition defn, FullTextExpression ft,
+                                  final Analyzer analyzer, final IndexReader reader) {
         // a reference to the query, so it can be set in the visitor
         // (a "non-local return")
         final AtomicReference<Query> result = new AtomicReference<Query>();
@@ -866,7 +867,7 @@ public class LucenePropertyIndex impleme
             public boolean visit(FullTextOr or) {
                 BooleanQuery q = new BooleanQuery();
                 for (FullTextExpression e : or.list) {
-                    Query x = getFullTextQuery(e, analyzer, reader);
+                    Query x = getFullTextQuery(defn, e, analyzer, reader);
                     q.add(x, SHOULD);
                 }
                 result.set(q);
@@ -877,7 +878,7 @@ public class LucenePropertyIndex impleme
             public boolean visit(FullTextAnd and) {
                 BooleanQuery q = new BooleanQuery();
                 for (FullTextExpression e : and.list) {
-                    Query x = getFullTextQuery(e, analyzer, reader);
+                    Query x = getFullTextQuery(defn, e, analyzer, reader);
                     // Lucene can't deal with "must(must_not(x))"
                     if (x instanceof BooleanQuery) {
                         BooleanQuery bq = (BooleanQuery) x;
@@ -895,8 +896,8 @@ public class LucenePropertyIndex impleme
             @Override
             public boolean visit(FullTextTerm term) {
                 String p = term.getPropertyName();
-                if (p != null && p.indexOf('/') >= 0) {
-                    p = getName(p);
+                if (p != null) {
+                    p = FieldNames.createAnalyzedFieldName(p);
                 }
                 Query q = tokenToQuery(term.getText(), p, analyzer, reader);
                 if (q == null) {