ALF-9079 RSOLR 019: Lucene to SOLR switchover administration

- Fix repo store to use xpath - avoids SOLR/index dependency during bootstrap and startup
- this change needs checking for performance impact

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29224 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrew Hind
2011-07-20 13:47:24 +00:00
parent b0e210241c
commit e5f7b3a6ee

View File

@@ -55,6 +55,7 @@ import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.util.ISO9075; import org.alfresco.util.ISO9075;
import org.alfresco.util.SearchLanguageConversion;
import org.springframework.extensions.webscripts.AbstractStore; import org.springframework.extensions.webscripts.AbstractStore;
import org.springframework.extensions.webscripts.ScriptContent; import org.springframework.extensions.webscripts.ScriptContent;
import org.springframework.extensions.webscripts.ScriptLoader; import org.springframework.extensions.webscripts.ScriptLoader;
@@ -331,14 +332,15 @@ public class RepoStore extends AbstractStore implements TenantDeployer
{ {
org.alfresco.service.cmr.repository.Path repoScriptPath = nodeService.getPath(scriptNodeRef); org.alfresco.service.cmr.repository.Path repoScriptPath = nodeService.getPath(scriptNodeRef);
String id = script.getDescription().getId().substring(scriptPath.length() + (scriptPath.length() > 0 ? 1 : 0)); String id = script.getDescription().getId().substring(scriptPath.length() + (scriptPath.length() > 0 ? 1 : 0));
String query = "+PATH:\"" + repoScriptPath.toPrefixString(namespaceService) + NodeRef repoStoreRootNodeRef = nodeService.getRootNode(repoStore);
"//*\" +QNAME:" + lucenifyNamePattern(id) + "*"; List<NodeRef> nodeRefs = searchService.selectNodes(
ResultSet resultSet = searchService.query(repoStore, SearchService.LANGUAGE_LUCENE, query); repoStoreRootNodeRef,
try repoScriptPath.toPrefixString(namespaceService)+"//*[like(@cm:name, '"+SearchLanguageConversion.convert(SearchLanguageConversion.DEF_LUCENE, SearchLanguageConversion.DEF_XPATH_LIKE, id+"*")+"', false)]",
{ new QueryParameterDefinition[] {},
documentPaths = new ArrayList<String>(resultSet.length()); namespaceService,
List<NodeRef> nodes = resultSet.getNodeRefs(); false,
for (NodeRef nodeRef : nodes) SearchService.LANGUAGE_XPATH);
for (NodeRef nodeRef : nodeRefs)
{ {
String name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); String name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
if (name.startsWith(id)) if (name.startsWith(id))
@@ -348,11 +350,30 @@ public class RepoStore extends AbstractStore implements TenantDeployer
documentPaths.add(documentPath); documentPaths.add(documentPath);
} }
} }
}
finally
{ // String query = "+PATH:\"" + repoScriptPath.toPrefixString(namespaceService) +
resultSet.close(); // "//*\" +QNAME:" + lucenifyNamePattern(id) + "*";
} // ResultSet resultSet = searchService.query(repoStore, SearchService.LANGUAGE_LUCENE, query);
// try
// {
// documentPaths = new ArrayList<String>(resultSet.length());
// List<NodeRef> nodes = resultSet.getNodeRefs();
// for (NodeRef nodeRef : nodes)
// {
// String name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
// if (name.startsWith(id))
// {
// String nodeDir = getPath(nodeRef);
// String documentPath = nodeDir.substring(baseDirLength);
// documentPaths.add(documentPath);
// }
// }
// }
// finally
// {
// resultSet.close();
// }
} }
return documentPaths != null ? documentPaths.toArray(new String[documentPaths.size()]) : new String[0]; return documentPaths != null ? documentPaths.toArray(new String[documentPaths.size()]) : new String[0];
@@ -376,12 +397,17 @@ public class RepoStore extends AbstractStore implements TenantDeployer
final Pattern pattern = Pattern.compile(matcher); final Pattern pattern = Pattern.compile(matcher);
String encPath = encodePathISO9075(path); String encPath = encodePathISO9075(path);
final StringBuilder query = new StringBuilder(128); // final StringBuilder query = new StringBuilder(128);
query.append("+PATH:\"").append(repoPath) // query.append("+PATH:\"").append(repoPath)
.append(encPath.length() != 0 ? ('/' + encPath) : "") // .append(encPath.length() != 0 ? ('/' + encPath) : "")
.append((includeSubPaths ? '/' : "")) // .append((includeSubPaths ? '/' : ""))
.append("/*\" +QNAME:") // .append("/*\" +QNAME:")
.append(lucenifyNamePattern(documentPattern)); // .append(lucenifyNamePattern(documentPattern));
final StringBuilder xpath = new StringBuilder(128);
xpath.append(repoPath);
xpath.append(encPath.length() != 0 ? ('/' + encPath) : "");
xpath.append((includeSubPaths ? '/' : ""));
xpath.append("/*[like(@cm:name, '"+SearchLanguageConversion.convert(SearchLanguageConversion.DEF_LUCENE, SearchLanguageConversion.DEF_XPATH_LIKE, documentPattern+"*")+"', false)]");
return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<String[]>() return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<String[]>()
{ {
@@ -394,12 +420,17 @@ public class RepoStore extends AbstractStore implements TenantDeployer
int baseDirLength = getBaseDir().length() +1; int baseDirLength = getBaseDir().length() +1;
List<String> documentPaths; List<String> documentPaths;
ResultSet resultSet = searchService.query(repoStore, SearchService.LANGUAGE_LUCENE, query.toString());
try NodeRef repoStoreRootNodeRef = nodeService.getRootNode(repoStore);
{ List<NodeRef> nodeRefs = searchService.selectNodes(
documentPaths = new ArrayList<String>(resultSet.length()); repoStoreRootNodeRef,
List<NodeRef> nodes = resultSet.getNodeRefs(); xpath.toString(),
for (NodeRef nodeRef : nodes) new QueryParameterDefinition[] {},
namespaceService,
false,
SearchService.LANGUAGE_XPATH);
documentPaths = new ArrayList<String>(nodeRefs.size());
for (NodeRef nodeRef : nodeRefs)
{ {
String name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); String name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
if (pattern.matcher(name).matches()) if (pattern.matcher(name).matches())
@@ -409,11 +440,26 @@ public class RepoStore extends AbstractStore implements TenantDeployer
documentPaths.add(documentPath); documentPaths.add(documentPath);
} }
} }
} // ResultSet resultSet = searchService.query(repoStore, SearchService.LANGUAGE_LUCENE, query.toString());
finally // try
{ // {
resultSet.close(); // documentPaths = new ArrayList<String>(resultSet.length());
} // List<NodeRef> nodes = resultSet.getNodeRefs();
// for (NodeRef nodeRef : nodes)
// {
// String name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
// if (pattern.matcher(name).matches())
// {
// String nodeDir = getPath(nodeRef);
// String documentPath = nodeDir.substring(baseDirLength);
// documentPaths.add(documentPath);
// }
// }
// }
// finally
// {
// resultSet.close();
// }
return documentPaths.toArray(new String[documentPaths.size()]); return documentPaths.toArray(new String[documentPaths.size()]);
} }
}, true, false); }, true, false);
@@ -518,23 +564,40 @@ public class RepoStore extends AbstractStore implements TenantDeployer
int baseDirLength = getBaseDir().length() +1; int baseDirLength = getBaseDir().length() +1;
List<String> documentPaths; List<String> documentPaths;
String query = "+PATH:\"" + repoPath +
"//*\" +TYPE:\"{http://www.alfresco.org/model/content/1.0}content\""; NodeRef repoStoreRootNodeRef = nodeService.getRootNode(repoStore);
ResultSet resultSet = searchService.query(repoStore, SearchService.LANGUAGE_LUCENE, query); List<NodeRef> nodeRefs = searchService.selectNodes(
try repoStoreRootNodeRef,
{ repoPath +
documentPaths = new ArrayList<String>(resultSet.length()); "//*[subtypeOf('{http://www.alfresco.org/model/content/1.0}content')]\"",
List<NodeRef> nodes = resultSet.getNodeRefs(); new QueryParameterDefinition[] {},
for (NodeRef nodeRef : nodes) namespaceService,
false,
SearchService.LANGUAGE_XPATH);
documentPaths = new ArrayList<String>(nodeRefs.size());
for (NodeRef nodeRef : nodeRefs)
{ {
String nodeDir = getPath(nodeRef); String nodeDir = getPath(nodeRef);
documentPaths.add(nodeDir.substring(baseDirLength)); documentPaths.add(nodeDir.substring(baseDirLength));
} }
}
finally // String query = "+PATH:\"" + repoPath +
{ // "//*\" +TYPE:\"{http://www.alfresco.org/model/content/1.0}content\"";
resultSet.close(); // ResultSet resultSet = searchService.query(repoStore, SearchService.LANGUAGE_LUCENE, query);
} // try
// {
// documentPaths = new ArrayList<String>(resultSet.length());
// List<NodeRef> nodes = resultSet.getNodeRefs();
// for (NodeRef nodeRef : nodes)
// {
// String nodeDir = getPath(nodeRef);
// documentPaths.add(nodeDir.substring(baseDirLength));
// }
// }
// finally
// {
// resultSet.close();
// }
return documentPaths.toArray(new String[documentPaths.size()]); return documentPaths.toArray(new String[documentPaths.size()]);
} }