chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1370955 - in /chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src: main/java/org/apache/chemistry/opencmis/inmemory/types/ test/java/org/apache/chemistry/opencmis/inmemory/query/
Date Wed, 08 Aug 2012 20:42:53 GMT
Author: jens
Date: Wed Aug  8 20:42:53 2012
New Revision: 1370955

URL: http://svn.apache.org/viewvc?rev=1370955&view=rev
Log:
add support for alias name on SCORE() in select, set query name for SCORE() to SEARCH_SCORE,
add unit test for score()

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java?rev=1370955&r1=1370954&r2=1370955&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java
Wed Aug  8 20:42:53 2012
@@ -302,9 +302,15 @@ public class PropertyCreationHelper {
         // add functions:
         BindingsObjectFactory objFactory = new BindingsObjectFactoryImpl();
         for (Entry<String, String> funcEntry : requestedFuncs.entrySet()) {
-            PropertyDecimal pd = objFactory.createPropertyDecimalData(funcEntry.getValue(),
BigDecimal.valueOf(1.0));
-            // fixed dummy value
-            mappedProperties.put(funcEntry.getKey(), pd);
+        	String queryName;
+        	if (funcEntry.getValue().equals("SCORE")) {
+        		queryName = "SEARCH_SCORE";
+        		if (!funcEntry.getKey().equals("SCORE"))
+        			queryName = funcEntry.getKey();
+                PropertyDecimal pd = objFactory.createPropertyDecimalData(queryName, BigDecimal.valueOf(1.0));
+                // fixed dummy value
+                mappedProperties.put(funcEntry.getKey(), pd);
+        	}
         }
 
         Properties props = new PropertiesImpl(mappedProperties.values());

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java?rev=1370955&r1=1370954&r2=1370955&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java
Wed Aug  8 20:42:53 2012
@@ -29,6 +29,8 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.math.BigDecimal;
+
 import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.data.ObjectData;
 import org.apache.chemistry.opencmis.commons.data.ObjectList;
@@ -825,6 +827,16 @@ public class EvalQueryTest extends Abstr
         assertTrue(resultContains("delta", res));
     }
 
+    @Test
+    public void testContainsAndScore() {
+        String statement = "SELECT cmis:objectId,cmis:name,SCORE() FROM " + COMPLEX_TYPE
+ " WHERE CONTAINS('dog')";
+        ObjectList res = doQuery(statement);
+        assertEquals(2, res.getObjects().size());
+        assertTrue(resultContains("gamma", res));
+        assertTrue(resultContains("delta", res));
+        assertTrue(resultContains(1.0, "SEARCH_SCORE", res));
+    }
+
     private ObjectList doQuery(String queryString) {
         log.debug("\nExecuting query: " + queryString);
         ObjectList res = fDiscSvc.query(fRepositoryId, queryString, false, false,
@@ -857,6 +869,16 @@ public class EvalQueryTest extends Abstr
         return false;
     }
 
+    private static boolean resultContains(Double val, String propId, ObjectList results)
{
+        for (ObjectData od : results.getObjects()) {
+            BigDecimal bd = (BigDecimal) od.getProperties().getProperties().get(propId).getFirstValue();
+            if (val.equals(bd.doubleValue())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     private static boolean resultContains(String name, ObjectList results) {
         return resultContains(name, PropertyIds.NAME, results);
     }



Mime
View raw message