cancel
Showing results for 
Search instead for 
Did you mean: 

Failed to execute Xpath with xpathSearch

riogrande
Champ in-the-making
Champ in-the-making
Hi all,

I have made a very simple script :


var results = search.xpathSearch("//*[@af:status='In']");

logger.log("\n## Document with the status set to 'In' : \n")

for each (result in results){
   logger.log("# : " + result.properties["cm:title"] + "\n");
}

But I have this error :
12:07:01,625 ERROR [org.alfresco.web.ui.common.Utils] Failed to run Actions due to error: Failed to execute script 'workspace://SpacesStore/db92b6ec-901b-472f-8ac9-52c1552cedda': Failed to execute search: //*[@af:status='In']
org.alfresco.scripts.ScriptException: Failed to execute script 'workspace://SpacesStore/db92b6ec-901b-472f-8ac9-52c1552cedda': Failed to execute search: //*[@af:status='In']
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:156)
   at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:176)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:296)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:177)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:301)
   at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:229)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy181.executeScript(Unknown Source)
   at org.alfresco.repo.action.executer.ScriptActionExecuter.executeImpl(ScriptActionExecuter.java:157)
   at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:127)
   at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:592)
   at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionServiceImpl.java:529)
   at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServiceImpl.java:391)
   at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServiceImpl.java:379)
   at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServiceImpl.java:600)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:296)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:177)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:301)
   at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:229)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy22.executeAction(Unknown Source)
   at org.alfresco.web.bean.actions.RunActionWizard.finishImpl(RunActionWizard.java:101)
   at org.alfresco.web.bean.dialog.BaseDialogBean$1.execute(BaseDialogBean.java:121)
   at org.alfresco.web.bean.dialog.BaseDialogBean$1.execute(BaseDialogBean.java:118)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:320)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:227)
   at org.alfresco.web.bean.dialog.BaseDialogBean.finish(BaseDialogBean.java:127)
   at org.alfresco.web.bean.wizard.WizardManager.finish(WizardManager.java:580)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
   at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
   at javax.faces.component.UICommand.broadcast(UICommand.java:109)
   at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
   at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
   at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
   at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
   at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:81)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   at java.lang.Thread.run(Thread.java:619)
Caused by: org.alfresco.error.AlfrescoRuntimeException: Failed to execute search: //*[@af:status='In']
   at org.alfresco.repo.jscript.Search.query(Search.java:451)
   at org.alfresco.repo.jscript.Search.xpathSearch(Search.java:209)
   at org.alfresco.repo.jscript.Search.xpathSearch(Search.java:194)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:155)
   at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:243)
   at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:66)
   at org.mozilla.javascript.gen.c1._c0(AlfrescoScript:2)
   at org.mozilla.javascript.gen.c1.call(AlfrescoScript)
   at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
   at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
   at org.mozilla.javascript.gen.c1.call(AlfrescoScript)
   at org.mozilla.javascript.gen.c1.exec(AlfrescoScript)
   at org.mozilla.javascript.Context.evaluateString(Context.java:1196)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:390)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:152)
   … 81 more
Caused by: java.lang.UnsupportedOperationException
   at org.alfresco.repo.search.impl.lucene.LuceneXPathHandler.startPredicate(LuceneXPathHandler.java:455)
   at com.werken.saxpath.XPathReader.predicate(XPathReader.java:770)
   at com.werken.saxpath.XPathReader.predicates(XPathReader.java:759)
   at com.werken.saxpath.XPathReader.nameTest(XPathReader.java:725)
   at com.werken.saxpath.XPathReader.nodeTest(XPathReader.java:612)
   at com.werken.saxpath.XPathReader.step(XPathReader.java:553)
   at com.werken.saxpath.XPathReader.steps(XPathReader.java:454)
   at com.werken.saxpath.XPathReader.absoluteLocationPath(XPathReader.java:405)
   at com.werken.saxpath.XPathReader.locationPath(XPathReader.java:335)
   at com.werken.saxpath.XPathReader.pathExpr(XPathReader.java:177)
   at com.werken.saxpath.XPathReader.unionExpr(XPathReader.java:1001)
   at com.werken.saxpath.XPathReader.unaryExpr(XPathReader.java:989)
   at com.werken.saxpath.XPathReader.multiplicativeExpr(XPathReader.java:940)
   at com.werken.saxpath.XPathReader.additiveExpr(XPathReader.java:911)
   at com.werken.saxpath.XPathReader.relationalExpr(XPathReader.java:868)
   at com.werken.saxpath.XPathReader.equalityExpr(XPathReader.java:839)
   at com.werken.saxpath.XPathReader.andExpr(XPathReader.java:817)
   at com.werken.saxpath.XPathReader.orExpr(XPathReader.java:795)
   at com.werken.saxpath.XPathReader.expr(XPathReader.java:788)
   at com.werken.saxpath.XPathReader.parse(XPathReader.java:105)
   at org.alfresco.repo.search.impl.lucene.ADMLuceneSearcherImpl.query(ADMLuceneSearcherImpl.java:422)
   at org.alfresco.repo.search.impl.lucene.ADMLuceneSearcherImpl.query(ADMLuceneSearcherImpl.java:206)
   at org.alfresco.repo.search.SearcherComponent.query(SearcherComponent.java:68)
   at org.alfresco.repo.search.AbstractSearcherComponent.query(AbstractSearcherComponent.java:59)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:296)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:177)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
   at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:80)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:301)
   at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:229)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy20.query(Unknown Source)
   at org.alfresco.repo.jscript.Search.query(Search.java:434)
   … 99 more
I tried //.[@af:status='In'] or .//.[@af:status='In'], event with standard property like cm:title it doesn't work.
When I use the "Alfresco Node Browser" this query works with the "selectnode" option but not with the "xpath" option I have the following error :
Search failed due to: java.lang.UnsupportedOperationException

The big question is : Is Xpath working in Alfresco  :?
12 REPLIES 12

mikeh
Star Contributor
Star Contributor
Hi

There are two xpath implementations in the Alfresco search service: an optimised one and one that uses Jaxen. Unfortunately the one you're calling is the optimized version, which doesn't support attribute queries. There's a comment on the wiki about it, but it's easy to miss.

Fortunately, in 3.2 we're added a parameterized query interface. See the query API here: http://wiki.alfresco.com/wiki/3.2_JavaScript_API#Search_API

Set the language to "jcr-xpath" and your query should work.

Thanks,
Mike

mikeh
Star Contributor
Star Contributor
Just to add… you can test your jcr-xpath style queries in the Node Browser by choosing the "selectnodes" type in the search dropdown.

Thanks,
Mike

riogrande
Champ in-the-making
Champ in-the-making
Yes very easy to miss it when I'm looking in the 3.0 API Smiley Wink

Ok so if I have understood, I can only use this query in Alfresco 3.2?
I'm working on Alfresco 3.0.0 (Stable 1526) so I can't use something like that (It's what you suggest right?)

search.query({query: "//.[@af:status='In']", language: jcr-xpath});


So, I have to use Lucene instead of xpath to do that? Or is it possible to "translate" my query in Jaxen to use the xpathSearch function (if it is possible how?).

mikeh
Star Contributor
Star Contributor
In 3.0, you'd have to either expose the selectNodes API by extending (or overriding, or directly editing) the org.alfresco.repo.jscript.Search class to make it available to JavaScript or - yes - use a Lucene query instead.

Thanks,
Mike

riogrande
Champ in-the-making
Champ in-the-making
Ok but the problem with lucene is the following:
The query is : @af\:status:"In"

Works fine with all status that I define, but not 'In'. So I sad to my self "ok you have just to change the "search-minimum" tag in the web-client-config-custom to 2 instead 3". But I have still no result with 'In'. Is there something like an (I don't know how to say that in English) "word ignore list"? Or did I miss again something?

mikeh
Star Contributor
Star Contributor
Yes, it won't work with any of the Lucene stop words, i.e. something like
"a", "an", "and", "are", "as", "at", "be", "but", "by",
"for", "if", "in", "into", "is", "it",
"no", "not", "of", "on", "or", "such",
"that", "the", "their", "then", "there", "these",
"they", "this", "to", "was", "will", "with"

Mike

riogrande
Champ in-the-making
Champ in-the-making
Ok anyway not really important for my script because I'm looking for another status, but for the advanced search it will be a problem. The easiest way for me is probably to change 'in' by something like 'available'.

So I finally manage to make the thing work (I was working on it since this morning, what a waste of time !)

search.luceneSearch("workspace://SpacesStore", "@af\\:status:\"Externalized\"");
Very important the \\ !

Anyway thanks for your answers MikeH it helps me to not became mad  :mrgreen:

riogrande
Champ in-the-making
Champ in-the-making
An other question in relation but for an other application. Is something like this suppose to work ?

var result = search.luceneSearch("workspace://SpacesStore/50755bba-4ba1-4b9e-88e9-3a64985474e1", "TYPE:\"cm:folder\" AND @cm\\:name:\"Marketing\"");

When I try this it works fine I got a result:
var result = search.luceneSearch("workspace://SpacesStore", "TYPE:\"cm:folder\" AND @cm\\:name:\"Marketing\"");

My structure is very simple
[img]http://www.digitalmindstudio.ch/~magicrio/alfresco/folder_structure.png[/img]
So instead of searching on company home in would like to search on the Archive folder, but it doesn't work.

mikeh
Star Contributor
Star Contributor
The first parameter in that form of the API is the store, not a nodeRef.

You need to add the PARENT search term to scope it to the Archive space. See http://wiki.alfresco.com/wiki/Search#Simple_Queries for details.

Thanks,
Mike