Alfresco 5.2迁移至7.3.1后自定义元数据搜索异常排查
已将Alfresco Community 5.2(zip版本)迁移至Community 7.3.1(Docker版本),使用Java 17且完成数据库迁移。自定义searchService方法无法通过自定义元数据找到迁移前的旧文档,但可通过标准Alfresco元数据(如cm:created)搜索;Share界面搜索正常,迁移后的新文档也能正常搜索,因此判断SOLR无问题。AMP构建无报错。
搜索方法代码
public List<Map<String, Object>> searchDocuments(String idaipatient, String medecin, String typologie, String nomService, String documentDateRangeStart, String documentDateRangeEnd, String integrationDateRangeStart, String integrationDateRangeEnd, String origine) { ResultSet rs = null; List<Map<String, Object>> finalResult = new ArrayList<Map<String, Object>>(); try { Map<String, Object> results = new HashMap<String, Object>(); Map<String, Object> resultObject = new HashMap<String, Object>(); String query = "TYPE:\"os:documed" + "\" " + "AND @os\\:idPatient:\"" + idaipatient + "\" " + "AND @os\\:medName:\"" + medecin + "\" " + "AND @os\\:typologie:\"" + typologie + "\" " + "AND @os\\:nomService:\"" + nomService + "\" " + "AND @cm\\:created:[\"" + integrationDateRangeStart + "\" TO \"" + integrationDateRangeEnd + "\"] " + "AND @os\\:docDate:[\"" + documentDateRangeStart + "\" TO \"" + documentDateRangeEnd + "\"] " + "AND @os\\:origine:\"" + origine + "\" "; logger.debug("Query : " + query); StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"); rs = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, query); if (rs.length() == 0) { logger.debug("Aucun résultat pour la recherche " + query); // initialisation Json retour resultObject.put("properties", initProperties()); results.put("item", resultObject); results.put("nodeRef", ""); finalResult.add(results); } else { logger.debug(rs.length() + " document(s) trouvé(s) pour la recherche " + query); /* Récupération et mise en forme des résultats */ for (NodeRef item : rs.getNodeRefs()) { results = new HashMap<String, Object>(); resultObject = new HashMap<String, Object>(); resultObject.put("properties", getProperties(item)); results.put("item", resultObject); results.put("nodeRef", item.getId()); finalResult.add(results); } } } catch (Exception e) { logger.debug("Erreur Recherche documents: {}", ExceptionUtils.getStackTrace(e)); finalResult = new ArrayList<Map<String, Object>>(); } finally { rs.close(); } return finalResult; }
pom.xml配置片段
<!-- Alfresco Maven Plugin version to use --> <alfresco.sdk.version>4.5.0</alfresco.sdk.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <!-- Properties used in dependency declarations, you don't need to change these --> <alfresco.groupId>org.alfresco</alfresco.groupId> <alfresco.bomDependencyArtifactId>acs-community-packaging</alfresco.bomDependencyArtifactId> <alfresco.platform.version>7.3.0</alfresco.platform.version> <alfresco.platform.docker.user>alfresco</alfresco.platform.docker.user> <alfresco.share.version>17.137</alfresco.share.version> <alfresco.share.docker.version>7.3.0</alfresco.share.version> <!-- Docker images --> <docker.acs.image>alfresco/alfresco-content-repository-community</docker.acs.image> <docker.share.image>alfresco/alfresco-share</docker.share.image>
针对该问题,可从以下几个方向排查修复:
切换查询语言至AFTS
Alfresco 7.x中Lucene查询语言已废弃,官方推荐使用AFTS(Alfresco Full Text Search)。Share界面默认使用AFTS所以能正常搜索,而旧文档的自定义元数据在Lucene索引中的存储格式与7.x索引不兼容。
修改查询语言并调整语法:rs = searchService.query(storeRef, SearchService.LANGUAGE_FTS_ALFRESCO, query);对应的AFTS查询示例:
TYPE:"os:documed" AND os:idPatient:"{idaipatient}" AND os:medName:"{medecin}" AND os:typologie:"{typologie}" AND os:nomService:"{nomService}" AND cm:created:[{integrationDateRangeStart} TO {integrationDateRangeEnd}] AND os:docDate:[{documentDateRangeStart} TO {documentDateRangeEnd}] AND os:origine:"{origine}"注意去掉属性前的
@和转义符\,AFTS无需这些处理。校验自定义模型命名空间
确认迁移后os前缀对应的自定义模型命名空间URI与5.2版本完全一致,若命名空间变更,旧文档的元数据属性会无法被识别。可通过Node Browser查看旧文档属性,确认自定义属性是否存在且前缀正确。触发旧文档重新索引
尽管Share搜索正常,但自定义代码使用的索引视图可能存在差异。可通过Admin Console执行"Reindex All Content",或批量更新旧文档的某个临时属性(添加后删除),触发索引更新。检查属性索引配置
确认自定义模型中相关元数据的index配置为启用状态,示例:<property name="os:idPatient"> <type>d:text</type> <index enabled="true"> <tokenised>true</tokenised> </index> </property>若5.2版本的配置与7.3.1不一致,可能导致索引失效。
替换参数拼接为参数化查询
直接拼接参数到查询字符串存在注入风险,也可能因特殊字符导致查询失效,建议使用参数化查询:Map<String, Object> params = new HashMap<>(); params.put("idaipatient", idaipatient); params.put("medecin", medecin); // 其他参数... rs = searchService.query(storeRef, SearchService.LANGUAGE_FTS_ALFRESCO, query, params);
内容的提问来源于stack exchange,提问作者anakin59490

