-->

露天Solr的SearchService.query()错误解析的Xpath(Alfresco So

2019-10-30 11:14发布

我想查询使用SearchService Alfresco的一些文件; 我的想法是:

1) 获取文件夹的noderef,我想在搜索文件

2)然后得到通过NodeService noderef的路径

3)最后通过SearchService查询太阳能找到特定的路径文件

这个问题引起了查询到Solr的时候,我得到以下异常:

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

如果我按类型厘米的前缀更换全前缀:等...查询效果很好。

是否有任何“露天路”要做到这一点,而不是转化用正则表达式的字符串? 还是我做错了什么?

我使用的代码是:

Path path3 = nodeService.getPath(folder); 

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

Answer 1:

据我所知,不支持使用完整的命名空间句法路径的查询。 看看这里: http://wiki.alfresco.com/wiki/Search#Path_Queries

你必须使用前缀版本。 但是,请不要使用正则表达式来获得的前缀。 有一个org.alfresco.service.namespace.NamespacePrefixResolver (豆NamespaceService)taht限定的方法Collection<String> getPrefixes(String namespaceURI)

您的虚拟代码来获得一个节点的QNamePath:

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() error parsing Xpath