Author: ssmiweve
Date: 2008-11-20 20:42:53 +0100 (Thu, 20 Nov 2008)
New Revision: 6966

Modified:
   
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/InfixQueryBuilder.java
Log:
Only write out the groupOpen, groupClose, and infix when both first and second 
clause exists


Modified: 
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/InfixQueryBuilder.java
===================================================================
--- 
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/InfixQueryBuilder.java
     2008-11-20 18:47:04 UTC (rev 6965)
+++ 
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/InfixQueryBuilder.java
     2008-11-20 19:42:53 UTC (rev 6966)
@@ -126,27 +126,32 @@
     protected void visitImpl(final AndClause clause) {
 
         if (!isEmptyLeaf(clause)) {
-            if(getConfig().getAndGrouped()){ 
appendToQueryRepresentation(getConfig().getAndGroupOpen()); }
+
+            final boolean unary = isEmptyLeaf(clause.getFirstClause()) || 
isEmptyLeaf(clause.getSecondClause());
+
+            if(getConfig().getAndGrouped() && !unary){ 
appendToQueryRepresentation(getConfig().getAndGroupOpen()); }
             clause.getFirstClause().accept(this);
-            if(!getConfig().getSupportsNot() || 
!isNextLeafInsideNotClause(clause.getSecondClause())){
+            if((!getConfig().getSupportsNot() || 
!isNextLeafInsideNotClause(clause.getSecondClause())) && !unary){
                 appendToQueryRepresentation(' ' + getConfig().getAndInfix() + 
' ');
             }
             clause.getSecondClause().accept(this);
-            if(getConfig().getAndGrouped()){ 
appendToQueryRepresentation(getConfig().getAndGroupClose()); }
-
+            if(getConfig().getAndGrouped() && !unary){ 
appendToQueryRepresentation(getConfig().getAndGroupClose()); }
         }
     }
 
     protected void visitImpl(final OrClause clause) {
 
         if (!isEmptyLeaf(clause)) {
-            if(getConfig().getOrGrouped()){ 
appendToQueryRepresentation(getConfig().getOrGroupOpen()); }
+
+            final boolean unary = isEmptyLeaf(clause.getFirstClause()) || 
isEmptyLeaf(clause.getSecondClause());
+
+            if(getConfig().getOrGrouped() && !unary){ 
appendToQueryRepresentation(getConfig().getOrGroupOpen()); }
             clause.getFirstClause().accept(this);
-            if(!getConfig().getSupportsNot() || 
!isNextLeafInsideNotClause(clause.getSecondClause())){
+            if((!getConfig().getSupportsNot() || 
!isNextLeafInsideNotClause(clause.getSecondClause())) && !unary){
                 appendToQueryRepresentation(' ' + getConfig().getOrInfix() + ' 
');
             }
             clause.getSecondClause().accept(this);
-            if(getConfig().getOrGrouped()){ 
appendToQueryRepresentation(getConfig().getOrGroupClose()); }
+            if(getConfig().getOrGrouped() && !unary){ 
appendToQueryRepresentation(getConfig().getOrGroupClose()); }
 
         }
     }
@@ -154,13 +159,16 @@
     protected void visitImpl(final DefaultOperatorClause clause) {
 
         if (!isEmptyLeaf(clause)) {
-            if(getConfig().getDefaultGrouped()){ 
appendToQueryRepresentation(getConfig().getDefaultGroupOpen()); }
+
+            final boolean unary = isEmptyLeaf(clause.getFirstClause()) || 
isEmptyLeaf(clause.getSecondClause());
+
+            if(getConfig().getDefaultGrouped() && !unary){ 
appendToQueryRepresentation(getConfig().getDefaultGroupOpen()); }
             clause.getFirstClause().accept(this);
-            if(!getConfig().getSupportsNot() || 
!isNextLeafInsideNotClause(clause.getSecondClause())){
+            if((!getConfig().getSupportsNot() || 
!isNextLeafInsideNotClause(clause.getSecondClause())) && !unary){
                 appendToQueryRepresentation(' ' + 
getConfig().getDefaultInfix() + ' ');
             }
             clause.getSecondClause().accept(this);
-            if(getConfig().getDefaultGrouped()){ 
appendToQueryRepresentation(getConfig().getDefaultGroupOpen()); }
+            if(getConfig().getDefaultGrouped() && !unary){ 
appendToQueryRepresentation(getConfig().getDefaultGroupOpen()); }
         }
     }
 

_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits

Reply via email to