final static String CMIS_TARGET_TITLE = CMIS_TARGET_PREFIX + "." + CMIS_NUXEO_TITLE;\r
final static String CMIS_TARGET_NAME = CMIS_TARGET_PREFIX + "." + CMIS_NUXEO_NAME;\r
final static String CMIS_TARGET_UPDATED_AT = CMIS_TARGET_PREFIX + "." + CMIS_CS_UPDATED_AT;\r
+ \r
+ final static String TENANT_USES_STARTING_WILDCARD_FOR_PARTIAL_TERM = "ptStartingWildcard";\r
\r
public void execQuery(String queryString);\r
\r
public String createWhereClauseForPartialMatch(String dataSourceName,\r
String repositoryName,\r
String field,\r
+ boolean startingWildcard,\r
String partialTerm);\r
\r
/**\r
<tenant:tenantBinding id="2" name="lifesci.collectionspace.org" displayName="Life Sciences/Natural History Demo Tenant" version="0.1">
<tenant:repositoryDomain name="default-domain" storageName="lifesci_domain" repositoryName="lifesci_domain" repositoryClient="nuxeo-java" />
+ <!--
+ If you have term completion performance problems and are willing to
+ live with not defaulting to an initial wildcard, uncomment this
+ section. Note that in term completion, you can always specify
+ something like "*atrick" (without quotes) to force the wildcard
+ at the beginning.
+ Performance may be an issue for very large authorities, especially if
+ many of them share common substrings.
+ <tenant:properties>
+ <types:item xmlns:types="http://collectionspace.org/services/config/types"
+ merge:matcher="skip" merge:action="insert" >
+ <types:key>ptStartingWildcard</types:key>
+ <types:value>false</types:value>
+ </types:item>
+ </tenant:properties>
+ -->
<tenant:serviceBindings merge:matcher="id" id="CollectionObjects">
<service:DocHandlerParams xmlns:service="http://collectionspace.org/services/config/service">
package org.collectionspace.services.common.query;\r
\r
import org.collectionspace.services.client.IQueryManager;\r
+import org.collectionspace.services.common.ServiceMain;\r
+import org.collectionspace.services.common.api.Tools;\r
+import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;\r
+import org.collectionspace.services.common.config.TenantBindingUtils;\r
import org.collectionspace.services.common.context.ServiceContext;\r
import org.collectionspace.services.common.query.nuxeo.QueryManagerNuxeoImpl;\r
+import org.collectionspace.services.config.tenant.TenantBindingType;\r
\r
public class QueryManager {\r
static private final IQueryManager queryManager = new QueryManagerNuxeoImpl();\r
String field,\r
String partialTerm) throws Exception {\r
String repositoryName = ctx.getRepositoryName();\r
+ // Otherwise, generate that list and cache it for re-use.\r
+ TenantBindingConfigReaderImpl tReader =\r
+ ServiceMain.getInstance().getTenantBindingConfigReader();\r
+ TenantBindingType tenantBinding = tReader.getTenantBinding(ctx.getTenantId());\r
+ String ptStartingWildcardValue = TenantBindingUtils.getPropertyValue(tenantBinding,\r
+ IQueryManager.TENANT_USES_STARTING_WILDCARD_FOR_PARTIAL_TERM);\r
+ boolean ptStartingWildcard = (ptStartingWildcardValue==null) \r
+ || Boolean.parseBoolean(ptStartingWildcardValue);\r
+\r
return queryManager.createWhereClauseForPartialMatch(queryManager.getDatasourceName(),\r
- repositoryName, field, partialTerm);\r
+ repositoryName, field, ptStartingWildcard, partialTerm);\r
}\r
\r
/**\r
public String createWhereClauseForPartialMatch(String dataSourceName,\r
String repositoryName,\r
String field,\r
+ boolean startingWildcard,\r
String partialTerm) {\r
String trimmed = (partialTerm == null) ? "" : partialTerm.trim();\r
if (trimmed.isEmpty()) {\r
throw new RuntimeException("No partialTerm specified.");\r
}\r
+ if(trimmed.charAt(0) == '*') {\r
+ if(trimmed.length() == 1) { // only a star is not enough\r
+ throw new RuntimeException("No partialTerm specified.");\r
+ }\r
+ trimmed = trimmed.substring(1);\r
+ startingWildcard = true; // force a starting wildcard match\r
+ }\r
if (field == null || field.isEmpty()) {\r
throw new RuntimeException("No match field specified.");\r
}\r
- String ptClause = field + getLikeForm(dataSourceName, repositoryName) + "'%"\r
- + unescapedSingleQuote.matcher(trimmed).replaceAll("\\\\'")\r
- + "%'";\r
- return ptClause;\r
+ \r
+ StringBuilder ptClause = new StringBuilder(trimmed.length()+field.length()+20);\r
+ ptClause.append(field);\r
+ ptClause.append(getLikeForm(dataSourceName, repositoryName));\r
+ ptClause.append(startingWildcard?"'%":"'");\r
+ ptClause.append(unescapedSingleQuote.matcher(trimmed).replaceAll("\\\\'"));\r
+ ptClause.append("%'");\r
+ return ptClause.toString();\r
}\r
\r
/**\r