jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r126294 - in incubator/jackrabbit/trunk/src: grammar/sql java/org/apache/jackrabbit/core/search java/org/apache/jackrabbit/core/search/lucene java/org/apache/jackrabbit/core/search/sql java/org/apache/jackrabbit/core/search/xpath test/org/apache/jackrabbit/test/search
Date Mon, 24 Jan 2005 15:27:24 GMT
Author: mreutegg
Date: Mon Jan 24 07:27:23 2005
New Revision: 126294

URL: http://svn.apache.org/viewcvs?view=rev&rev=126294
Log:
Implemented support for value comparison and general comparison using multi valued properties.
Modified:
   incubator/jackrabbit/trunk/src/grammar/sql/JCRSQL.jjt
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/Constants.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/RelationQueryNode.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/FieldNames.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NodeIndexer.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/sql/JCRSQLQueryBuilder.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/sql/QueryFormat.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/QueryFormat.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/XPathQueryBuilder.java
   incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/SimpleQueryTest.java

Modified: incubator/jackrabbit/trunk/src/grammar/sql/JCRSQL.jjt
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/grammar/sql/JCRSQL.jjt?view=diff&rev=126294&p1=incubator/jackrabbit/trunk/src/grammar/sql/JCRSQL.jjt&r1=126293&p2=incubator/jackrabbit/trunk/src/grammar/sql/JCRSQL.jjt&r2=126294
==============================================================================
--- incubator/jackrabbit/trunk/src/grammar/sql/JCRSQL.jjt	(original)
+++ incubator/jackrabbit/trunk/src/grammar/sql/JCRSQL.jjt	Mon Jan 24 07:27:23 2005
@@ -299,36 +299,49 @@
   String escapeString;
 }
 {
-  identifier = Identifier() { jjtThis.setIdentifier(identifier); }
   (
     (
-      operationType = ComparisonOperation() { jjtThis.setOperationType(operationType); }
-      (Literal() | identifier = Identifier() { jjtThis.setIdentifier(identifier); } )
-    )
-  |
-    ((<NOT> { jjtThis.setNegate(true); })?
+      identifier = Identifier() { jjtThis.setIdentifier(identifier); }
       (
-        (<BETWEEN> { jjtThis.setOperationType(Constants.OPERATION_BETWEEN); } Literal()
<AND> Literal())
+        (
+          operationType = ComparisonOperation() { jjtThis.setOperationType(operationType);
}
+          (Literal() | identifier = Identifier() { jjtThis.setIdentifier(identifier); } )
+        )
       |
-        (<IN> { jjtThis.setOperationType(Constants.OPERATION_IN); } <LEFT_PAREN>
Literal() (<COMMA> Literal())* <RIGHT_PAREN>)
+        ((<NOT> { jjtThis.setNegate(true); })?
+          (
+            (<BETWEEN> { jjtThis.setOperationType(Constants.OPERATION_BETWEEN); } Literal()
<AND> Literal())
+          |
+            (
+              <LIKE> { jjtThis.setOperationType(Constants.OPERATION_LIKE); } value
= CharStringLiteral()
+              {
+                ASTLiteral s = new ASTLiteral(JJTLITERAL);
+                s.setType(Constants.TYPE_STRING);
+                s.setValue(value);
+                jjtree.pushNode(s);
+              }
+              (<ESCAPE> escapeString = CharStringLiteral() { jjtThis.setEscapeString(escapeString);
})?
+            )
+          )
+        )
       |
-        (
-          <LIKE> { jjtThis.setOperationType(Constants.OPERATION_LIKE); } value = CharStringLiteral()
+        (<IS> (<NOT> { jjtThis.setNegate(true); })? <NULL>
           {
-            ASTLiteral s = new ASTLiteral(JJTLITERAL);
-            s.setType(Constants.TYPE_STRING);
-            s.setValue(value);
-            jjtree.pushNode(s);
+            jjtThis.setOperationType(jjtThis.isNegate() ? Constants.OPERATION_NOT_NULL :
Constants.OPERATION_NULL);
           }
-          (<ESCAPE> escapeString = CharStringLiteral() { jjtThis.setEscapeString(escapeString);
})?
         )
       )
     )
   |
-    (<IS> (<NOT> { jjtThis.setNegate(true); })? <NULL>
-      {
-        jjtThis.setOperationType(jjtThis.isNegate() ? Constants.OPERATION_NOT_NULL : Constants.OPERATION_NULL);

-      }
+    (
+      Literal() (<NOT> { jjtThis.setNegate(true); })? <IN>
+      (
+        identifier = Identifier()
+        {
+          jjtThis.setIdentifier(identifier);
+          jjtThis.setOperationType(jjtThis.isNegate() ? Constants.OPERATION_NE_GENERAL :
Constants.OPERATION_EQ_GENERAL);
+        }
+      )
     )
   )
 }
@@ -340,12 +353,12 @@
 }
 {
   (
-      <EQ_OPERATOR> { operationType = Constants.OPERATION_EQ; }
-    | <NE_OPERATOR> { operationType = Constants.OPERATION_NE; }
-    | <LT_OPERATOR> { operationType = Constants.OPERATION_LT; }
-    | <GT_OPERATOR> { operationType = Constants.OPERATION_GT; }
-    | <LE_OPERATOR> { operationType = Constants.OPERATION_LE; }
-    | <GE_OPERATOR> { operationType = Constants.OPERATION_GE; }
+      <EQ_OPERATOR> { operationType = Constants.OPERATION_EQ_VALUE; }
+    | <NE_OPERATOR> { operationType = Constants.OPERATION_NE_VALUE; }
+    | <LT_OPERATOR> { operationType = Constants.OPERATION_LT_VALUE; }
+    | <GT_OPERATOR> { operationType = Constants.OPERATION_GT_VALUE; }
+    | <LE_OPERATOR> { operationType = Constants.OPERATION_LE_VALUE; }
+    | <GE_OPERATOR> { operationType = Constants.OPERATION_GE_VALUE; }
   )
   {
     return operationType;

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/Constants.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/Constants.java?view=diff&rev=126294&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/Constants.java&r1=126293&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/Constants.java&r2=126294
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/Constants.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/Constants.java	Mon
Jan 24 07:27:23 2005
@@ -47,58 +47,72 @@
      */
     public static int TYPE_TIMESTAMP = 5;
 
+    public static int OPERATIONS = 10;
+
+    /**
+     * equal operation: =
+     */
+    public static int OPERATION_EQ_VALUE = OPERATIONS + 1;
+
     /**
      * equal operation: =
+     * general comparison
+     */
+    public static int OPERATION_EQ_GENERAL = OPERATIONS + 2;
+
+    /**
+     * not equal operation: <>
      */
-    public static int OPERATION_EQ = 10;
+    public static int OPERATION_NE_VALUE = OPERATIONS + 3;
 
     /**
      * not equal operation: <>
+     * general comparision
      */
-    public static int OPERATION_NE = 11;
+    public static int OPERATION_NE_GENERAL = OPERATIONS + 4;
 
     /**
      * less than operation: <
      */
-    public static int OPERATION_LT = 12;
+    public static int OPERATION_LT_VALUE = OPERATIONS + 5;
 
     /**
      * greater than operation: >
      */
-    public static int OPERATION_GT = 13;
+    public static int OPERATION_GT_VALUE = OPERATIONS + 6;
 
     /**
      * greater or equal operation: >=
      */
-    public static int OPERATION_GE = 14;
+    public static int OPERATION_GE_VALUE = OPERATIONS + 7;
 
     /**
      * less than or equal operation: <=
      */
-    public static int OPERATION_LE = 15;
+    public static int OPERATION_LE_VALUE = OPERATIONS + 8;
 
     /**
      * like operation: identifier LIKE string_literal
      */
-    public static int OPERATION_LIKE = 16;
+    public static int OPERATION_LIKE = OPERATIONS + 9;
 
     /**
      * between operation: identifier [ NOT ] BETWEEN literal AND literal
      */
-    public static int OPERATION_BETWEEN = 17;
+    public static int OPERATION_BETWEEN = OPERATIONS + 10;
 
     /**
      * on operation: identifier [ NOT ] IN ( literal {, literal}* )
      */
-    public static int OPERATION_IN = 18;
+    public static int OPERATION_IN = OPERATIONS + 11;
 
     /**
      * is null operation: identifier IS NULL
      */
-    public static int OPERATION_NULL = 19;
+    public static int OPERATION_NULL = OPERATIONS + 12;
 
     /**
      * is not null operation: identifier IS NOT NULL
      */
-    public static int OPERATION_NOT_NULL = 20;
+    public static int OPERATION_NOT_NULL = OPERATIONS + 13;
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/RelationQueryNode.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/RelationQueryNode.java?view=diff&rev=126294&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/RelationQueryNode.java&r1=126293&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/RelationQueryNode.java&r2=126294
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/RelationQueryNode.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/RelationQueryNode.java
Mon Jan 24 07:27:23 2005
@@ -55,9 +55,8 @@
     private Date valueDate;
 
     /**
-     * The operation type of this relation. One of {@link #OPERATION_EQ},
-     * {@link #OPERATION_GE}, {@link #OPERATION_GT}, {@link #OPERATION_LE},
-     * {@link #OPERATION_LIKE}, {@link #OPERATION_LT}, {@link #OPERATION_NE}.
+     * The operation type of this relation. One of the operation values defined
+     * in {@link Constants}.
      */
     private int operation;
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/FieldNames.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/FieldNames.java?view=diff&rev=126294&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/FieldNames.java&r1=126293&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/FieldNames.java&r2=126294
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/FieldNames.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/FieldNames.java
Mon Jan 24 07:27:23 2005
@@ -45,4 +45,9 @@
      * tokenized.
      */
     public static final String LABEL = "_:LABEL";
+
+    /**
+     * Prefix for all field names that hold multi valued properties.
+     */
+    public static final String MVP_PREFIX = "MVP:";
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java?view=diff&rev=126294&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java&r1=126293&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java&r2=126294
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java
Mon Jan 24 07:27:23 2005
@@ -34,6 +34,7 @@
 import org.apache.lucene.search.TermQuery;
 
 import javax.jcr.RepositoryException;
+import javax.jcr.NamespaceException;
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeIterator;
@@ -392,41 +393,66 @@
 
         String field = "";
         String primaryTypeField = "";
+        String mvpField = "";
         try {
             field = node.getProperty().toJCRName(nsMappings);
             primaryTypeField = primaryType.toJCRName(nsMappings);
+            StringBuffer tmp = new StringBuffer();
+            tmp.append(nsMappings.getPrefix(node.getProperty().getNamespaceURI()));
+            tmp.append(':').append(FieldNames.MVP_PREFIX);
+            tmp.append(node.getProperty().getLocalName());
+            mvpField = tmp.toString();
+        } catch (NamespaceException e) {
+            // should never happen
+            exceptions.add(e);
         } catch (NoPrefixDeclaredException e) {
             // should never happen
             exceptions.add(e);
         }
 
         switch (node.getOperation()) {
-            case Constants.OPERATION_EQ:	// =
+            case Constants.OPERATION_EQ_VALUE:      // =
                 query = new TermQuery(new Term(field, stringValue));
                 break;
-            case Constants.OPERATION_GE:	// >=
+            case Constants.OPERATION_EQ_GENERAL:    // =
+                // search in single and multi valued properties
+                BooleanQuery or = new BooleanQuery();
+                or.add(new TermQuery(new Term(field, stringValue)), false, false);
+                or.add(new TermQuery(new Term(mvpField, stringValue)), false, false);
+                query = or;
+                break;
+            case Constants.OPERATION_GE_VALUE:      // >=
                 query = new RangeQuery(new Term(field, stringValue), null, true);
                 break;
-            case Constants.OPERATION_GT:	// >
+            case Constants.OPERATION_GT_VALUE:      // >
                 query = new RangeQuery(new Term(field, stringValue), null, false);
                 break;
-            case Constants.OPERATION_LE:	// <=
+            case Constants.OPERATION_LE_VALUE:      // <=
                 query = new RangeQuery(null, new Term(field, stringValue), true);
                 break;
-            case Constants.OPERATION_LIKE:	// LIKE
+            case Constants.OPERATION_LIKE:          // LIKE
                 if (stringValue.equals("%")) {
                     query = new MatchAllQuery(field);
                 } else {
                     query = new WildcardQuery(new Term(field, stringValue));
                 }
                 break;
-            case Constants.OPERATION_LT:	// <
+            case Constants.OPERATION_LT_VALUE:      // <
                 query = new RangeQuery(null, new Term(field, stringValue), false);
                 break;
-            case Constants.OPERATION_NE:	// !=
+            case Constants.OPERATION_NE_VALUE:      // !=
                 BooleanQuery notQuery = new BooleanQuery();
                 notQuery.add(new MatchAllQuery(field), false, false);
                 notQuery.add(new TermQuery(new Term(field, stringValue)), false, true);
+                query = notQuery;
+                break;
+            case Constants.OPERATION_NE_GENERAL:    // !=
+                // search in single and multi valued properties
+                notQuery = new BooleanQuery();
+                notQuery.add(new MatchAllQuery(field), false, false);
+                notQuery.add(new MatchAllQuery(mvpField), false, false);
+                notQuery.add(new TermQuery(new Term(field, stringValue)), false, true);
+                notQuery.add(new TermQuery(new Term(mvpField, stringValue)), false, true);
                 query = notQuery;
                 break;
             case Constants.OPERATION_NULL:

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NodeIndexer.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NodeIndexer.java?view=diff&rev=126294&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NodeIndexer.java&r1=126293&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NodeIndexer.java&r2=126294
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NodeIndexer.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NodeIndexer.java
Mon Jan 24 07:27:23 2005
@@ -136,8 +136,18 @@
             try {
                 PropertyState propState = (PropertyState) stateProvider.getItemState(id);
                 InternalValue[] values = propState.getValues();
-                for (int i = 0; i < values.length; i++) {
-                    addValue(doc, values[i], propState.getName());
+                if (propState.isMultiValued()) {
+                    // multi valued
+                    if (values.length == 1) {
+                        // also index as if single value property
+                        addValue(doc, values[0], propState.getName(), false);
+                    }
+                    for (int i = 0; i < values.length; i++) {
+                        addValue(doc, values[i], propState.getName(), true);
+                    }
+                } else {
+                    // single value
+                    addValue(doc, values[0], propState.getName(), false);
                 }
             } catch (NoSuchItemStateException e) {
                 throw new RepositoryException("Error while indexing node: " + node.getUUID(),
e);
@@ -154,11 +164,20 @@
      * @param doc   the document.
      * @param value the internal jackrabbit value.
      * @param name  the name of the property.
+     * @param multiValued if <code>true</code> the value is treated as a
+     *   multivalued.
      */
-    private void addValue(Document doc, InternalValue value, QName name) {
-        String fieldName = name.toString();
+    private void addValue(Document doc, InternalValue value, QName name, boolean multiValued)
{
+        String fieldName = name.getLocalName();
         try {
-            fieldName = mappings.getPrefix(name.getNamespaceURI()) + ":" + name.getLocalName();
+            StringBuffer tmp = new StringBuffer();
+            tmp.append(mappings.getPrefix(name.getNamespaceURI()));
+            tmp.append(':');
+            if (multiValued) {
+                tmp.append(FieldNames.MVP_PREFIX);
+            }
+            tmp.append(name.getLocalName());
+            fieldName = tmp.toString();
         } catch (NamespaceException e) {
             // will never happen
         }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/sql/JCRSQLQueryBuilder.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/sql/JCRSQLQueryBuilder.java?view=diff&rev=126294&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/sql/JCRSQLQueryBuilder.java&r1=126293&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/sql/JCRSQLQueryBuilder.java&r2=126294
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/sql/JCRSQLQueryBuilder.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/sql/JCRSQLQueryBuilder.java
Mon Jan 24 07:27:23 2005
@@ -32,7 +32,6 @@
 import org.apache.jackrabbit.core.NamespaceResolver;
 import org.apache.jackrabbit.core.QName;
 import org.apache.jackrabbit.core.NamespaceRegistryImpl;
-import org.apache.jackrabbit.core.NoPrefixDeclaredException;
 import org.apache.jackrabbit.core.IllegalNameException;
 import org.apache.jackrabbit.core.UnknownPrefixException;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
@@ -204,7 +203,16 @@
         QueryNode predicateNode = null;
 
         try {
-            QName identifier = ((ASTIdentifier) node.children[0]).getName();
+            final QName[] tmp = new QName[1];
+            node.childrenAccept(new DefaultParserVisitor() {
+                public Object visit(ASTIdentifier node, Object data) {
+                    // only assign first identifier
+                    tmp[0] = (tmp[0] == null) ? node.getName() : tmp[0];
+                    return data;
+                }
+            }, data);
+            QName identifier = tmp[0];
+
             if (identifier.equals(JCR_PATH)) {
                 if (node.children[1] instanceof ASTIdentifier) {
                     // simply ignore, this is a join of a mixin node type
@@ -218,26 +226,30 @@
             if (type == Constants.OPERATION_BETWEEN) {
                 AndQueryNode between = new AndQueryNode(parent);
                 RelationQueryNode rel = createRelationQueryNode(between,
-                        identifier, Constants.OPERATION_GE, (ASTLiteral) node.children[1]);
+                        identifier, Constants.OPERATION_GE_VALUE, (ASTLiteral) node.children[1]);
                 between.addOperand(rel);
                 rel = createRelationQueryNode(between,
-                        identifier, Constants.OPERATION_LE, (ASTLiteral) node.children[2]);
+                        identifier, Constants.OPERATION_LE_VALUE, (ASTLiteral) node.children[2]);
                 between.addOperand(rel);
                 predicateNode = between;
-            } else if (type == Constants.OPERATION_EQ) {
+            } else if (type == Constants.OPERATION_EQ_VALUE) {
                 if (node.children[1] instanceof ASTIdentifier) {
                     // simply ignore, this is a join of a mixin node type
                 } else {
                     predicateNode = createRelationQueryNode(parent,
                             identifier, type, (ASTLiteral) node.children[1]);
                 }
-            } else if (type == Constants.OPERATION_GE
-                    || type == Constants.OPERATION_GT
-                    || type == Constants.OPERATION_LE
-                    || type == Constants.OPERATION_LT
-                    || type == Constants.OPERATION_NE) {
+            } else if (type == Constants.OPERATION_GE_VALUE
+                    || type == Constants.OPERATION_GT_VALUE
+                    || type == Constants.OPERATION_LE_VALUE
+                    || type == Constants.OPERATION_LT_VALUE
+                    || type == Constants.OPERATION_NE_VALUE) {
                 predicateNode = createRelationQueryNode(parent,
                         identifier, type, (ASTLiteral) node.children[1]);
+            } else if (type == Constants.OPERATION_EQ_GENERAL
+                    || type == Constants.OPERATION_NE_GENERAL) {
+                predicateNode = createRelationQueryNode(parent,
+                        identifier, type, (ASTLiteral) node.children[0]);
             } else if (type == Constants.OPERATION_LIKE) {
                 ASTLiteral pattern = (ASTLiteral) node.children[1];
                 if (node.getEscapeString() != null) {
@@ -259,7 +271,7 @@
                 OrQueryNode in = new OrQueryNode(parent);
                 for (int i = 1; i < node.children.length; i++) {
                     RelationQueryNode rel = createRelationQueryNode(in,
-                            identifier, Constants.OPERATION_EQ, (ASTLiteral) node.children[i]);
+                            identifier, Constants.OPERATION_EQ_VALUE, (ASTLiteral) node.children[i]);
                     in.addOperand(rel);
                 }
                 predicateNode = in;

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/sql/QueryFormat.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/sql/QueryFormat.java?view=diff&rev=126294&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/sql/QueryFormat.java&r1=126293&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/sql/QueryFormat.java&r2=126294
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/sql/QueryFormat.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/sql/QueryFormat.java
Mon Jan 24 07:27:23 2005
@@ -310,44 +310,58 @@
     public Object visit(RelationQueryNode node, Object data) {
         StringBuffer sb = (StringBuffer) data;
         try {
-            appendName(node.getProperty(), resolver, sb);
+            if (node.getOperation() == OPERATION_EQ_VALUE) {
+                appendName(node.getProperty(), resolver, sb);
+                sb.append(" = ");
+                appendValue(node, sb);
+            } else if (node.getOperation() == OPERATION_EQ_GENERAL) {
+                appendValue(node, sb);
+                sb.append(" IN ");
+                appendName(node.getProperty(), resolver, sb);
+            } else if (node.getOperation() == OPERATION_GE_VALUE) {
+                appendName(node.getProperty(), resolver, sb);
+                sb.append(" >= ");
+                appendValue(node, sb);
+            } else if (node.getOperation() == OPERATION_GT_VALUE) {
+                appendName(node.getProperty(), resolver, sb);
+                sb.append(" > ");
+                appendValue(node, sb);
+            } else if (node.getOperation() == OPERATION_LE_VALUE) {
+                appendName(node.getProperty(), resolver, sb);
+                sb.append(" <= ");
+                appendValue(node, sb);
+            } else if (node.getOperation() == OPERATION_LIKE) {
+                appendName(node.getProperty(), resolver, sb);
+                sb.append(" LIKE ");
+                appendValue(node, sb);
+            } else if (node.getOperation() == OPERATION_LT_VALUE) {
+                appendName(node.getProperty(), resolver, sb);
+                sb.append(" < ");
+                appendValue(node, sb);
+            } else if (node.getOperation() == OPERATION_NE_VALUE) {
+                appendName(node.getProperty(), resolver, sb);
+                sb.append(" <> ");
+                appendValue(node, sb);
+            } else if (node.getOperation() == OPERATION_NE_GENERAL) {
+                appendValue(node, sb);
+                sb.append(" NOT IN ");
+                appendName(node.getProperty(), resolver, sb);
+            } else if (node.getOperation() == OPERATION_NULL) {
+                appendName(node.getProperty(), resolver, sb);
+                sb.append(" IS NULL");
+            } else if (node.getOperation() == OPERATION_NOT_NULL) {
+                appendName(node.getProperty(), resolver, sb);
+                sb.append(" IS NOT NULL");
+            } else {
+                exceptions.add(new InvalidQueryException("Invalid operation: " + node.getOperation()));
+            }
+
+            if (node.getOperation() == OPERATION_LIKE && node.getStringValue().indexOf('\\')
> -1) {
+                sb.append(" ESCAPE '\\'");
+            }
         } catch (NoPrefixDeclaredException e) {
             exceptions.add(e);
         }
-
-        if (node.getOperation() == OPERATION_EQ) {
-            sb.append(" = ");
-            appendValue(node, sb);
-        } else if (node.getOperation() == OPERATION_GE) {
-            sb.append(" >= ");
-            appendValue(node, sb);
-        } else if (node.getOperation() == OPERATION_GT) {
-            sb.append(" > ");
-            appendValue(node, sb);
-        } else if (node.getOperation() == OPERATION_LE) {
-            sb.append(" <= ");
-            appendValue(node, sb);
-        } else if (node.getOperation() == OPERATION_LIKE) {
-            sb.append(" LIKE ");
-            appendValue(node, sb);
-        } else if (node.getOperation() == OPERATION_LT) {
-            sb.append(" < ");
-            appendValue(node, sb);
-        } else if (node.getOperation() == OPERATION_NE) {
-            sb.append(" <> ");
-            appendValue(node, sb);
-        } else if (node.getOperation() == OPERATION_NULL) {
-            sb.append(" IS NULL");
-        } else if (node.getOperation() == OPERATION_NOT_NULL) {
-            sb.append(" IS NOT NULL");
-        } else {
-            exceptions.add(new InvalidQueryException("Invalid operation: " + node.getOperation()));
-        }
-
-        if (node.getOperation() == OPERATION_LIKE && node.getStringValue().indexOf('\\')
> -1) {
-            sb.append(" ESCAPE '\\'");
-        }
-
         return sb;
     }
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/QueryFormat.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/QueryFormat.java?view=diff&rev=126294&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/QueryFormat.java&r1=126293&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/QueryFormat.java&r2=126294
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/QueryFormat.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/QueryFormat.java
Mon Jan 24 07:27:23 2005
@@ -261,27 +261,33 @@
             //int propIdx = sb.length();
             String propName = "@" + ISO9075.encode(node.getProperty()).toJCRName(resolver);
 
-            if (node.getOperation() == OPERATION_EQ) {
+            if (node.getOperation() == OPERATION_EQ_VALUE) {
+                sb.append(propName).append(" eq ");
+                appendValue(node, sb);
+            } else if (node.getOperation() == OPERATION_EQ_GENERAL) {
                 sb.append(propName).append(" = ");
                 appendValue(node, sb);
-            } else if (node.getOperation() == OPERATION_GE) {
-                sb.append(propName).append(" >= ");
+            } else if (node.getOperation() == OPERATION_GE_VALUE) {
+                sb.append(propName).append(" ge ");
                 appendValue(node, sb);
-            } else if (node.getOperation() == OPERATION_GT) {
-                sb.append(propName).append(" > ");
+            } else if (node.getOperation() == OPERATION_GT_VALUE) {
+                sb.append(propName).append(" gt ");
                 appendValue(node, sb);
-            } else if (node.getOperation() == OPERATION_LE) {
-                sb.append(propName).append(" <= ");
+            } else if (node.getOperation() == OPERATION_LE_VALUE) {
+                sb.append(propName).append(" le ");
                 appendValue(node, sb);
             } else if (node.getOperation() == OPERATION_LIKE) {
                 sb.append(XPathQueryBuilder.JCRFN_LIKE.toJCRName(resolver));
                 sb.append("(").append(propName).append(", ");
                 appendValue(node, sb);
                 sb.append(")");
-            } else if (node.getOperation() == OPERATION_LT) {
-                sb.append(propName).append(" < ");
+            } else if (node.getOperation() == OPERATION_LT_VALUE) {
+                sb.append(propName).append(" lt ");
+                appendValue(node, sb);
+            } else if (node.getOperation() == OPERATION_NE_VALUE) {
+                sb.append(propName).append(" ne ");
                 appendValue(node, sb);
-            } else if (node.getOperation() == OPERATION_NE) {
+            } else if (node.getOperation() == OPERATION_NE_GENERAL) {
                 sb.append(propName).append(" != ");
                 appendValue(node, sb);
             } else if (node.getOperation() == OPERATION_NULL) {

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/XPathQueryBuilder.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/XPathQueryBuilder.java?view=diff&rev=126294&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/XPathQueryBuilder.java&r1=126293&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/XPathQueryBuilder.java&r2=126294
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/XPathQueryBuilder.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/XPathQueryBuilder.java
Mon Jan 24 07:27:23 2005
@@ -357,19 +357,24 @@
         }
         // get operation type
         String opType = node.getValue();
+        // todo distinguish value vs. general comparison
         int type = 0;
-        if (opType.equals(OP_EQ) || opType.equals(OP_SIGN_EQ)) {
-            type = RelationQueryNode.OPERATION_EQ;
+        if (opType.equals(OP_EQ)) {
+            type = RelationQueryNode.OPERATION_EQ_VALUE;
+        } else if (opType.equals(OP_SIGN_EQ)) {
+            type = RelationQueryNode.OPERATION_EQ_GENERAL;
         } else if (opType.equals(OP_GE) || opType.equals(OP_SIGN_GE)) {
-            type = RelationQueryNode.OPERATION_GE;
+            type = RelationQueryNode.OPERATION_GE_VALUE;
         } else if (opType.equals(OP_GT) || opType.equals(OP_SIGN_GT)) {
-            type = RelationQueryNode.OPERATION_GT;
+            type = RelationQueryNode.OPERATION_GT_VALUE;
         } else if (opType.equals(OP_LE) || opType.equals(OP_SIGN_LE)) {
-            type = RelationQueryNode.OPERATION_LE;
+            type = RelationQueryNode.OPERATION_LE_VALUE;
         } else if (opType.equals(OP_LT) || opType.equals(OP_SIGN_LT)) {
-            type = RelationQueryNode.OPERATION_LT;
-        } else if (opType.equals(OP_NE) || opType.equals(OP_SIGN_NE)) {
-            type = RelationQueryNode.OPERATION_NE;
+            type = RelationQueryNode.OPERATION_LT_VALUE;
+        } else if (opType.equals(OP_NE)) {
+            type = RelationQueryNode.OPERATION_NE_VALUE;
+        } else if (opType.equals(OP_SIGN_NE)) {
+            type = RelationQueryNode.OPERATION_NE_GENERAL;
         } else {
             exceptions.add(new InvalidQueryException("Unsupported ComparisonExpr type:" +
node.getValue()));
         }

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/SimpleQueryTest.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/SimpleQueryTest.java?view=diff&rev=126294&p1=incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/SimpleQueryTest.java&r1=126293&p2=incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/SimpleQueryTest.java&r2=126294
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/SimpleQueryTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/search/SimpleQueryTest.java
Mon Jan 24 07:27:23 2005
@@ -336,4 +336,51 @@
         checkResult(result, 1);
     }
 
+    public void testGeneralComparison() throws Exception {
+        Node foo = testRootNode.addNode("foo");
+        foo.setProperty("text", new String[]{"foo", "bar"}); // mvp
+        Node bar = testRootNode.addNode("bar");
+        bar.setProperty("text", new String[]{"foo"}); // mvp with one value
+        Node bla = testRootNode.addNode("bla");
+        bla.setProperty("text", "foo"); // svp
+        Node blu = testRootNode.addNode("blu");
+        blu.setProperty("text", "bar"); // svp
+
+        testRootNode.save();
+
+        String sql = "SELECT * FROM nt:unstructured WHERE 'foo' IN text " +
+                "and jcr:path LIKE '/" + testRoot + "/%'";
+        Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, "sql");
+        QueryResult result = q.execute();
+        checkResult(result, 3); // foo, bar, bla
+
+        String xpath = "/" + testRoot + "/*[@jcr:primaryType='nt:unstructured' and @text
= 'foo']";
+        q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH_DOCUMENT_VIEW);
+        result = q.execute();
+        checkResult(result, 3); // foo, bar, bla
+
+        sql = "SELECT * FROM nt:unstructured WHERE text = 'foo' " +
+                "and jcr:path LIKE '/" + testRoot + "/%'";
+        q = superuser.getWorkspace().getQueryManager().createQuery(sql, "sql");
+        result = q.execute();
+        checkResult(result, 2); // bar, bla
+
+        xpath = "/" + testRoot + "/*[@jcr:primaryType='nt:unstructured' and @text eq 'foo']";
+        q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH_DOCUMENT_VIEW);
+        result = q.execute();
+        checkResult(result, 2); // bar, bla
+
+        sql = "SELECT * FROM nt:unstructured WHERE 'bar' NOT IN text " +
+                "and jcr:path LIKE '/" + testRoot + "/%'";
+        q = superuser.getWorkspace().getQueryManager().createQuery(sql, "sql");
+        result = q.execute();
+        checkResult(result, 2); // bar, bla
+
+        xpath = "/" + testRoot + "/*[@jcr:primaryType='nt:unstructured' and @text != 'bar']";
+        q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH_DOCUMENT_VIEW);
+        result = q.execute();
+        checkResult(result, 2); // bar, bla
+
+    }
+
 }

Mime
View raw message