cancel
Showing results for 
Search instead for 
Did you mean: 

Freemarker Lucene Search node context

rhofkens
Champ in-the-making
Champ in-the-making
Hello,

I'm building a template that lists all nodes of type cm:content in a space (and its subspaces).  The template looks like this

<#assign query = "TYPE:\"{http://www.alfresco.org/model/content/1.0}content\"" />
<#assign rowcount=0>
<table>
   <tr style='background-color: #C6D8EB'>
      <td></td>
      <td><b>Document name</b></td>
      <td><b>Document creation date</b></td>
      <td><b>Document creator</b></td>
      <td><b>Document modification date</b></td>
      <td><b>Document modifier</b></td>
   </tr>
   <#list space.childrenByLuceneSearch[query] as child>
     <#if rowcount % 2 = 0><tr><#else><tr style='background-color: #DEE5EC'></#if>
       <td><a href="/alfresco${child.url}" target="new"><img src="/alfresco${child.icon16}" border=0></td>
       <td><a href="/alfresco${child.url}" target="new">${child.properties.name}</a></td>
       <td>${child.properties.created?date}<td>
       <td>${child.properties.creator}<td>
       <td>${child.properties.modified?date}<td>
       <td>${child.properties.modifier}<td>      
    </tr>
    <#assign rowcount=rowcount+1>
   </#list>
</table>

The search results list however, includes nodes from the complete repo.  I would like limit the search scope to the current space (and subspaces), that's why I uses space.childrenByLuceneQuery.  Is this possible?

best regards,
Roeland.
4 REPLIES 4

kevinr
Star Contributor
Star Contributor
The method 'childrenByLuceneQuery' is badly named - it executes the full lucene query that you enter, it does not automatically constrain the results to the parent space that you execute against. The parent space is simply a hook point from which to call the method.

To search within a specific space using lucene you should constrain by encoded PATH, for example:

PATH:"/app:company_home/cm:myfolder//*" AND TEXT:alfresco

Thanks,

Kevin

rhofkens
Champ in-the-making
Champ in-the-making
Hi Kevin,

ok, I understand.  Is there an easy way to find the path of a node in FTL?  I've noticed that the name of a node does not necessarily map to the name used in the path, especially in a multilingual environment.

Examples:

(EN) Company Home –> path: company_home
(DE) Stammbereich des Unternehmens –> path: company_home

best regards,
Roeland

kevinr
Star Contributor
Star Contributor
Yes there is an API called 'qnamePath ' to get the encoded path for a node:
http://wiki.alfresco.com/wiki/Template_Guide#Extended_TemplateNode_Model_API

Thanks,

Kevin

kevinr
Star Contributor
Star Contributor
A more performant search would be to use the PARENT term in the Lucene search:

+PARENT:"<your noderef here>" +TEXT:alfresco