本文介绍了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.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//*'

如果我将完整前缀替换为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:\"/{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);


推荐答案

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

afaik PATH-Queries using full namespace syntax is not supported. Take a look here: http://wiki.alfresco.com/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错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 05:58