jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r643414 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene: JQOM2LuceneQueryBuilder.java LuceneQueryBuilder.java Util.java
Date Tue, 01 Apr 2008 14:16:55 GMT
Author: mreutegg
Date: Tue Apr  1 07:16:43 2008
New Revision: 643414

URL: http://svn.apache.org/viewvc?rev=643414&view=rev
Log:
JCR-1104: JSR 283 support
- query (work in progress)

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java?rev=643414&r1=643413&r2=643414&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java
Tue Apr  1 07:16:43 2008
@@ -517,7 +517,7 @@
 
     public Object visit(PropertyExistenceImpl node, Object data) throws Exception {
         String propName = npResolver.getJCRName(node.getPropertyQName());
-        return createMatchAllQuery(propName);
+        return Util.createMatchAllQuery(propName, version);
     }
 
     public Object visit(PropertyValueImpl node, Object data) throws Exception {
@@ -774,22 +774,6 @@
             throw new InvalidQueryException(
                     "lower/upper-case not supported on operand "
                     + operand.getClass().getName());
-        }
-    }
-
-    /**
-     * Depending on the index format this method returns
-     * a query that matches all nodes that have a property named 'field'
-     *
-     * @param field
-     * @return Query that matches all nodes that have a property named 'field'
-     */
-    private Query createMatchAllQuery(String field) {
-        if (version.getVersion() >= IndexFormatVersion.V2.getVersion()) {
-            // new index format style
-            return new TermQuery(new Term(FieldNames.PROPERTIES_SET, field));
-        } else {
-            return new MatchAllQuery(field);
         }
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java?rev=643414&r1=643413&r2=643414&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
Tue Apr  1 07:16:43 2008
@@ -598,7 +598,7 @@
             }
 
             if (node.getIncludeDescendants()) {
-                Query refPropQuery = createMatchAllQuery(refProperty);
+                Query refPropQuery = Util.createMatchAllQuery(refProperty, indexFormatVersion);
                 context = new DescendantSelfAxisQuery(context, refPropQuery, false);
             }
 
@@ -806,7 +806,7 @@
                     // the like operation always has one string value.
                     // no coercing, see above
                     if (stringValues[0].equals("%")) {
-                        query = createMatchAllQuery(field);
+                        query = Util.createMatchAllQuery(field, indexFormatVersion);
                     } else {
                         query = new WildcardQuery(FieldNames.PROPERTIES, field, stringValues[0],
transform[0]);
                     }
@@ -827,7 +827,7 @@
                 case QueryConstants.OPERATION_NE_VALUE:      // !=
                     // match nodes with property 'field' that includes svp and mvp
                     BooleanQuery notQuery = new BooleanQuery();
-                    notQuery.add(createMatchAllQuery(field), Occur.SHOULD);
+                    notQuery.add(Util.createMatchAllQuery(field, indexFormatVersion), Occur.SHOULD);
                     // exclude all nodes where 'field' has the term in question
                     for (int i = 0; i < stringValues.length; i++) {
                         Term t = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field,
stringValues[i]));
@@ -853,7 +853,7 @@
                     // minus the nodes that have a multi-valued property 'field' and
                     //    all values are equal to term in question
                     notQuery = new BooleanQuery();
-                    notQuery.add(createMatchAllQuery(field), Occur.SHOULD);
+                    notQuery.add(Util.createMatchAllQuery(field, indexFormatVersion), Occur.SHOULD);
                     for (int i = 0; i < stringValues.length; i++) {
                         // exclude the nodes that have the term and are single valued
                         Term t = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field,
stringValues[i]));
@@ -876,7 +876,7 @@
                     query = notQuery;
                     break;
                 case QueryConstants.OPERATION_NULL:
-                    query = new NotQuery(createMatchAllQuery(field));
+                    query = new NotQuery(Util.createMatchAllQuery(field, indexFormatVersion));
                     break;
                 case QueryConstants.OPERATION_SIMILAR:
                     String uuid = "x";
@@ -891,10 +891,10 @@
                     query = new SimilarityQuery(uuid, analyzer);
                     break;
                 case QueryConstants.OPERATION_NOT_NULL:
-                    query = createMatchAllQuery(field);
+                    query = Util.createMatchAllQuery(field, indexFormatVersion);
                     break;
                 case QueryConstants.OPERATION_SPELLCHECK:
-                    query = createMatchAllQuery(field);
+                    query = Util.createMatchAllQuery(field, indexFormatVersion);
                     break;
                 default:
                     throw new IllegalArgumentException("Unknown relation operation: "
@@ -1104,21 +1104,5 @@
             log.debug("Using literal " + literal + " as is.");
         }
         return (String[]) values.toArray(new String[values.size()]);
-    }
-
-    /**
-     * Depending on the index format this method returns
-     * a query that matches all nodes that have a property named 'field'
-     *
-     * @param field
-     * @return Query that matches all nodes that have a property named 'field'
-     */
-    private Query createMatchAllQuery(String field) {
-        if (indexFormatVersion.getVersion() >= IndexFormatVersion.V2.getVersion()) {
-            // new index format style
-            return new TermQuery(new Term(FieldNames.PROPERTIES_SET, field));
-        } else {
-            return new MatchAllQuery(field);
-        }
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java?rev=643414&r1=643413&r2=643414&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
Tue Apr  1 07:16:43 2008
@@ -18,6 +18,9 @@
 
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.index.Term;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -74,5 +77,23 @@
             }
         }
         return true;
+    }
+
+    /**
+     * Depending on the index format this method returns a query that matches
+     * all nodes that have a property with a given <code>name</code>.
+     *
+     * @param name    the property name.
+     * @param version the index format version.
+     * @return Query that matches all nodes that have a property with the given
+     *         <code>name</code>.
+     */
+    public static Query createMatchAllQuery(String name, IndexFormatVersion version) {
+        if (version.getVersion() >= IndexFormatVersion.V2.getVersion()) {
+            // new index format style
+            return new TermQuery(new Term(FieldNames.PROPERTIES_SET, name));
+        } else {
+            return new MatchAllQuery(name);
+        }
     }
 }



Mime
View raw message