Alfresco Solr SearchService.query()解析Xpath错误

编程入门 行业动态 更新时间:2024-10-24 16:27:31
本文介绍了Alfresco Solr SearchService.query()解析Xpath错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用SearchService在Alfresco中查询一些文件;我的想法是:

I'm trying to query for some files in Alfresco using SearchService; my idea is:

1)获取文件夹的noderef 我要在其中搜索文件的地方

1) get folder's noderef where I want to search in for files

2)然后通过NodeService获取noderef的路径

3)最后通过SearchService查询Solar 以查找该特定路径中的文件

3) finally query Solar via SearchService to find files in that specific path

查询Solr时出现问题,我得到以下异常:

The problem raises when querying to Solr, I get the following exception:

ERROR [solr.core.SolrCore] [http-bio-8443-exec-1] org.apache.solrmon.SolrException: org.apache.lucene.queryParser.ParseException: **Cannot parse** 'PATH:"/{http\://www.alfresco/model/application/1.0}company_home/{http\://www.alfresco/model/application/1.0}user_homes/{http\://www.alfresco/model/content/1.0}abeecher/{http\://www.alfresco/model/content/1.0}nominas//*"': **Failed to parse XPath**... Unexpected '{www.alfresco/model/application/1.0}company_home/{www.alfresco/model/application/1.0}user_homes/{www.alfresco/model/content/1.0}abeecher/{www.alfresco/model/content/1.0}nominas//*'

如果我将完整前缀替换为cm:等类型的前缀,则查询效果很好。

If I replace the full prefixes by prefixes of type cm: etc... the query works well.

是否有 Alfresco Way来执行此操作,而不是使用正则表达式来转换字符串?还是我做错了什么?

我正在使用的代码是:

Path path3 = nodeService.getPath(folder); SearchParameters sp = new SearchParameters(); sp.addStore(Repository.getStoreRef()); sp.setLanguage(SearchService.LANGUAGE_LUCENE); sp.setQuery("PATH:\"/{www.alfresco/model/application/1.0}company_home/{www.alfresco/model/application/1.0}user_homes/{www.alfresco/model/content/1.0}abeecher/{www.alfresco/model/content/1.0}nominas//*\""); //sp.setQuery(path3); //sp.setQuery(path3.toString()); ResultSet results = null; results = searchService.query(sp);

推荐答案

afaik PATH查询不支持使用完整命名空间语法。在这里看看: wiki.alfresco/wiki/Search#Path_Queries

afaik PATH-Queries using full namespace syntax is not supported. Take a look here: wiki.alfresco/wiki/Search#Path_Queries

您必须使用前缀版本。但是,请不要使用正则表达式来获取前缀。有一个 org.alfresco.service.namespace.NamespacePrefixResolver (bean NamespaceService)定义了方法 Collection< String>。 getPrefixes(String namespaceURI)。

You'll have to use the prefix version. But, please don't use a regex to get the prefix. There is an org.alfresco.service.namespace.NamespacePrefixResolver (bean NamespaceService) taht defines a method Collection<String> getPrefixes(String namespaceURI).

您的虚拟代码以获取节点的QNamePath:

your dummy code to get the QNamePath of a node:

Path path = nodeService.getPath(folder); final Map<String, String> cache = new HashMap<String, String>(); final StringBuilder buf = new StringBuilder(128); for (final Path.Element e : path) { if (e instanceof Path.ChildAssocElement) { final QName qname = ((Path.ChildAssocElement)e).getRef().getQName(); if (qname != null) { String prefix = cache.get(qname.getNamespaceURI()); if (prefix == null) { // first request for this namespace prefix, get and cache result Collection<String> prefixes = ns.getPrefixes(qname.getNamespaceURI()); prefix = prefixes.size() != 0 ? prefixes.iterator().next() : ""; cache.put(qname.getNamespaceURI(), prefix); } buf.append('/').append(prefix).append(':').append(ISO9075.encode(qname.getLocalName())); } } else { buf.append('/').append(e.toString()); } } String searchPath = buf.toString();

更多推荐

Alfresco Solr SearchService.query()解析Xpath错误

本文发布于:2023-11-28 15:40:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642998.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   Solr   Alfresco   SearchService   Xpath

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!