cancel
Showing results for 
Search instead for 
Did you mean: 

lucene problem using webscript

kayan
Champ in-the-making
Champ in-the-making
Hi,
Here is my sample javascript:

var fileName="data";
var folderName="789";   
var queryString = "@\\{http\\://www.alfresco.org/model/content/1.0\\}name:*'+fileName+'*" ;   
var srchQuery="PATH:\"/app:company_home/cm:TestData/cm:"+folderName+"}//*\" AND "+queryString+"\"";
logger.log(">>> Lucene search query= "+srchQuery);   
var nodes = search.luceneSearch(srchQuery);

The script is running perfectly in all the cases except when i entered a numeric folder name.  When I entered a numeric folder name it threw following stack trace

-<response>
−
   <status>
500

<name>Internal Error</name>
−
   <description>
An error inside the HTTP server which prevented it from fulfilling the request.
</description>
</status>
−
   <message>
Failed to execute script 'file:C:/Alfresco2.2.0/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/wstest/searchFolder.get.js': Failed to execute script 'file:C:/Alfresco2.2.0/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/wstest/searchFolder.get.js': Wrapped org.alfresco.error.AlfrescoRuntimeException: Failed to execute search: PATH:"/app:company_home/cm:TestData/cm:789}//*" AND @\{http\://www.alfresco.org/model/content/1.0\}name:*data*" (AlfrescoScript#9)
</message>
−
   <exception>
org.alfresco.service.cmr.repository.ScriptException - Failed to execute script 'file:C:/Alfresco2.2.0/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/wstest/searchFolder.get.js': Failed to execute script 'file:C:/Alfresco2.2.0/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/wstest/searchFolder.get.js': Wrapped org.alfresco.error.AlfrescoRuntimeException: Failed to execute search: PATH:"/app:company_home/cm:TestData/cm:789}//*" AND @\{http\://www.alfresco.org/model/content/1.0\}name:*data*" (AlfrescoScript#9)
</exception>
−
   <callstack>

      org.alfresco.repo.search.impl.lucene.ParseException: Failed to parse XPath…
Unexpected '789'
         org.alfresco.repo.search.impl.lucene.LuceneQueryParser.getFieldQuery(LuceneQueryParser.java:581)
         org.alfresco.repo.search.impl.lucene.LuceneQueryParser.getFieldQuery(LuceneQueryParser.java:173)
         org.alfresco.repo.search.impl.lucene.QueryParser.Term(QueryParser.java:1009)
         org.alfresco.repo.search.impl.lucene.QueryParser.Clause(QueryParser.java:758)
         org.alfresco.repo.search.impl.lucene.QueryParser.Query(QueryParser.java:701)
         org.alfresco.repo.search.impl.lucene.QueryParser.parse(QueryParser.java:139)
         org.alfresco.repo.search.impl.lucene.LuceneQueryParser.parse(LuceneQueryParser.java:125)
         org.alfresco.repo.search.impl.lucene.ADMLuceneSearcherImpl.query(ADMLuceneSearcherImpl.java:233)
         org.alfresco.repo.search.impl.lucene.ADMLuceneSearcherImpl.query(ADMLuceneSearcherImpl.java:190)
         org.alfresco.repo.search.SearcherComponent.query(SearcherComponent.java:68)
         org.alfresco.repo.search.AbstractSearcherComponent.query(AbstractSearcherComponent.java:59)
         sun.reflect.GeneratedMethodAccessor453.invoke(Unknown Source)
         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         java.lang.reflect.Method.invoke(Method.java:585)
         org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
         org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
         org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
         net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:80)
         org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
         org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
         org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
         org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:245)
         org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
         org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
         org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
         org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
         org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
         $Proxy16.query(Unknown Source)
         org.alfresco.repo.jscript.Search.query(Search.java:246)
         org.alfresco.repo.jscript.Search.luceneSearch(Search.java:151)
         sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         java.lang.reflect.Method.invoke(Method.java:585)
         org.mozilla.javascript.MemberBox.invoke(MemberBox.java:155)
         org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:243)
         org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:66)
         org.mozilla.javascript.gen.c16._c0(AlfrescoScript:9)
         org.mozilla.javascript.gen.c16.call(AlfrescoScript)
         org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
         org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
         org.mozilla.javascript.gen.c16.call(AlfrescoScript)
         org.mozilla.javascript.gen.c16.exec(AlfrescoScript)
         org.mozilla.javascript.Context.evaluateString(Context.java:1196)
         org.alfresco.repo.jscript.RhinoScriptProcessor.
executeScriptImpl(RhinoScriptProcessor.java:527)
         org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:112)
         org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:243)
         sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         java.lang.reflect.Method.invoke(Method.java:585)
         org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
         org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
         org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
         org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
         org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
         org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
         org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
         org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:245)
         org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
         org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
         org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
         org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
         org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
         $Proxy47.executeScript(Unknown Source)
         org.alfresco.web.scripts.ScriptProcessor.executeScript(ScriptProcessor.java:108)
         org.alfresco.web.scripts.AbstractWebScript.executeScript(AbstractWebScript.java:622)
         org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:117)
         org.alfresco.web.scripts.WebScriptRuntime.wrappedExecute(WebScriptRuntime.java:364)
         org.alfresco.web.scripts.WebScriptRuntime$1.execute(WebScriptRuntime.java:330)
         org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:241)
         org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:171)
         org.alfresco.web.scripts.WebScriptRuntime.transactionedExecute(WebScriptRuntime.java:341)
         org.alfresco.web.scripts.WebScriptRuntime.authenticatedExecute(WebScriptRuntime.java:284)
         org.alfresco.web.scripts.WebScriptRuntime.executeScript(WebScriptRuntime.java:150)
         org.alfresco.web.scripts.WebScriptServlet.service(WebScriptServlet.java:109)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
         org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
         org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
         org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
         org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
         org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
         org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
         org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
         org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
         org.apache.coyote.http11.Http11BaseProtocol$Http11Connec
tionHandler.processConnection(Http11BaseProtocol.java:665)
         org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
         org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
         org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
         java.lang.Thread.run(Thread.java:595)
      org.alfresco.repo.search.SearcherException: Failed to parse query: PATH:"/app:company_home/cm:TestData/cm:789}//*" AND @\{http\://www.alfresco.org/model/content/1.0\}name:*data*"
      org.alfresco.repo.search.impl.lucene.ADMLuceneSearcherImpl.query(ADMLuceneSearcherImpl.java:305)
      org.alfresco.error.AlfrescoRuntimeException: Failed to execute search: PATH:"/app:company_home/cm:TestData/cm:789}//*" AND @\{http\://www.alfresco.org/model/content/1.0\}name:*data*"
      org.alfresco.repo.jscript.Search.query(Search.java:262)
      org.mozilla.javascript.WrappedException: Wrapped org.alfresco.error.AlfrescoRuntimeException: Failed to execute search: PATH:"/app:company_home/cm:TestData/cm:789}//*" AND @\{http\://www.alfresco.org/model/content/1.0\}name:*data*" (AlfrescoScript#9)
      org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1757)
      org.alfresco.error.AlfrescoRuntimeException: Wrapped org.alfresco.error.AlfrescoRuntimeException: Failed to execute search: PATH:"/app:company_home/cm:TestData/cm:789}//*" AND @\{http\://www.alfresco.org/model/content/1.0\}name:*data*" (AlfrescoScript#9)
      org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:535)
      org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'file:C:/Alfresco2.2.0/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/wstest/searchFolder.get.js': Wrapped org.alfresco.error.AlfrescoRuntimeException: Failed to execute search: PATH:"/app:company_home/cm:TestData/cm:789}//*" AND @\{http\://www.alfresco.org/model/content/1.0\}name:*data*" (AlfrescoScript#9)
      org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:116)
      org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'file:C:/Alfresco2.2.0/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/wstest/searchFolder.get.js': Failed to execute script 'file:C:/Alfresco2.2.0/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/wstest/searchFolder.get.js': Wrapped org.alfresco.error.AlfrescoRuntimeException: Failed to execute search: PATH:"/app:company_home/cm:TestData/cm:789}//*" AND @\{http\://www.alfresco.org/model/content/1.0\}name:*data*" (AlfrescoScript#9)
      org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:247)
 
</callstack>
<server>Alfresco Enterprise Network v2.2.0 (159) schema 89</server>
<time>19-May-2008 21:04:35</time>
</response>


Can anybody put some light onto this?


Thanks
kayan
6 REPLIES 6

pmonks
Star Contributor
Star Contributor
Paths are stored in ISO9075 format, so you need to ISO9075 encode them before searching.  For most alphanumeric strings, this won't change the value at all, but there are corner cases (including strings that start with numeric characters) that will be modified by ISO9075 encoding.

There's a utility class (http://dev.alfresco.com/resource/docs/java/repository/org/alfresco/util/ISO9075.html) that provides utility functions for encoding/decoding to/from ISO9075.

Cheers,
Peter

kayan
Champ in-the-making
Champ in-the-making
Hi Peter,

Thanks a lot for your quick solution.  It worked on my end.


Thanks
Kayan

_sax
Champ in-the-making
Champ in-the-making
I found the same discussion at https://issues.alfresco.com/jira/browse/AWC-1862 but I'm uncertain how I could use the encoding function. Is it usable in a Freemarker template or a javascript inside a Freemarker template?
I tried <#assign Folder=ISO9075.encode(space.properties.name)> or is it
<#assign Folder=${space.properties.name}.encode?ISO9075> ? Thank you!

_sax
Champ in-the-making
Champ in-the-making
Result = ISO9075Encode(MyPath);
in a javascript would do it.

johanpi
Champ in-the-making
Champ in-the-making
Should it not be
var Result = search.ISO9075Encode(mypath);

I get an error without the search part

_sax
Champ in-the-making
Champ in-the-making
You're perfectly right.
One note: Alfresco 3 is needed for this encoding conversion, 2.x throws an error due to the lack of the corresponding function.