cancel
Showing results for 
Search instead for 
Did you mean: 

better performing template queries? (for better recent docs)

stk137
Champ in-the-making
Champ in-the-making
So I am trying to create a better recent docs template.
One that has the last 15 most recently modified docs displayed in descendending order by date.  I also separate out forum posts from other content so I can display them differently.  Part of my current template is below.

The problem seems to be that this performs terribly (when there's more than handful of docs).  How can I make it perform much better?
AFAIK using lucene with search parameters is not an option in a template.  So am I stuck having to do the sorting and limiting in template script?
When you do something like this, it's not pulling back the content in the search results that I am sorting, is it?  Only meta-data right?

BTW (if it's not already requested) I'd like to be able to use lucene with search params in scripting and templating.

thx

        <#– recent docs –>
        <h2 style="margin-bottom:0.2em;">Most Recently Modified Docs</h2>
        <table cellpadding=2>
   
           <tr>
              <td></td>
              <td><b>Name</b></td>
              <td><b>Location</b></td>
              <td><b>Date</b></td>
           </tr>
           <#list space.childrenByXPath[".//*[subtypeOf('cm:content') and not(subtypeOf('fm:post'))]"]?sort_by(['properties','cm:modified'])?reverse as child>
              <#if child_index = 15><#break></#if>
                 <tr>
                    <td><a href="/alfresco${child.url}" target="new"><img src="/alfresco${child.icon16}" border=0></a></td>
                    <td><a href="/alfresco${child.url}" target="new">${child.properties.name}</a></td>
                    <td><a href="/alfresco${child.parent.url}" target="new">${child.displayPath?replace(fullSpacePath,".")}</a></td>
                    <td>${child.properties["cm:modified"]?datetime}</td>
                 </tr>
           </#list>
        </table>
              
<#– Recent Topics/Posts –>
        <#assign recentPosts=space.childrenByXPath[".//*[subtypeOf('fm:post')]"]?sort_by(['properties','cm:modified'])?reverse>
        <#if (recentPosts?size > 0) >
        <h2 style="margin-bottom:0.2em;">Most Recent Topics/Posts</h2>
                <table cellpadding=2>
                   <tr>
                      <td></td>
                      <td><b>Topic/Post</b></td>
                      <td><b>Date/Author</b></td>
                   </tr>
                   <#list recentPosts as child>
                      <#if child_index = 8><#break></#if>
                         <tr>
                            <td valign="top"><a href="/alfresco${child.parent.url}"><img src="/alfresco${child.parent.icon16}" border=0></a></td>
                            <td valign="top"><a href="/alfresco${child.parent.url}">${child.parent.properties.name}</a><br/>
                            <#– <a href="/alfresco${child.url}" target="new">${child.properties.name}</a><br/> –>
                            <#if child.content?length < 40>
                                <a style="font-size:.9em;" href="/alfresco${child.url}" target="new">${child.content?replace("<br/>","- ")}</a><br/>
                            <#else>
                                <a style="font-size:.9em;" href="/alfresco${child.url}" target="new">${child.content?substring(0,40)?replace("<br/>","- ")}…</a><br/>
                            </#if>
                           
                            </td>
                            <td valign="top">${child.properties["cm:modified"]?datetime}<br/>
                                <span style="font-size:.9em;">${child.properties["cm:modifier"]}</span>
                            </td>
                         </tr>
                   </#list>
                </table>
   
        </#if>
12 REPLIES 12

stk137
Champ in-the-making
Champ in-the-making
(Better Recent Docs Template  continued)

well I am not done with the template because I have run into a couple problems that I haven't found solutions for.  But here's where it is for now.

The current problems are
1.) child.displayPath causes UnexpectedRollbackException
http://forums.alfresco.com/viewtopic.php?t=8869&highlight=
2.) I don't of know a way to safely call child.parent.url
http://forums.alfresco.com/viewtopic.php?t=8780&highlight=
(some of that has been commented out below for now, remove those to see the full design)

(Neither or these errors occur if you're an admin or the query doesn't return any docs which pose authentication issues with getting path or parent.)

It's at least a better query/list than the example included with Alfresco.  It get's the last months of changes, sorts them, and displays the top 20.  The time span for the query and number of items to display can be set in assignments at the top.  I also split out forum posts to link to the topic instead of the individual post.  Now if the issues with displaying and linking to location are resolved I'll update to fix that.



<#ftl strip_whitespace=true />
<#setting locale="en_US"/>
<#setting datetime_format="medium_short">

<#if space?exists && space.hasPermission("Read")>

  <#assign spacePath = space.displayPath + "/" + space.name />
  <#assign fullSpacePath = space.displayPath + "/" + space.name + "/" />

  <#assign dateRangeBackMilliseconds = -1000*60*60*24*30 />
  <#assign endDate=date?string("yyyy\\-MM\\-dd") + "T00:00:00"/>
  <#assign startDate=incrementDate(date,dateRangeBackMilliseconds)?string("yyyy\\-MM\\-dd") + "T00:00:00"/>
  <#assign recentContentMaxCount = 20 />




  <#– recent content –>
  <h2 style="margin-bottom:0.2em;">Recently Created/Modified Content</h2>
  <script>var AlfNodeInfoMgr = new Alfresco.PanelManager("NodeInfoBean.sendNodeInfo", "noderef");</script>
  <table class="recordSet">
    <thead>
    <tr>
      <th style="padding:2px;text-align:left" class="recordSetHeader"><b>Content Item</b></th>
      <th style="padding:2px;text-align:left" class="recordSetHeader"><b>Location</b><#– <span style="font-weight:normal;">(${fullSpacePath})</span>–></th>
      <th style="padding:2px;text-align:left" class="recordSetHeader"><b>Date / Author</b></th>
    </tr>
    </thead>
    <tbody>
    <#list space.childrenByLuceneSearch["PATH:\"${space.qnamePath}//*\" AND TYPE:\"cm:content\" AND @cm\\:modified:[${startDate} TO ${endDate}]"]?sort_by(['properties','cm:modified'])?reverse as child>
      <#if child_index = recentContentMaxCount><#break></#if>
      <#assign rowstyle="recordSetRow" />
      <#if (child_index % 2 = 1)>
      <#assign rowstyle="recordSetRowAlt" />
      <#else>
      <#assign rowstyle="recordSetRow" />
      </#if>
      <#if child.type != "{http://www.alfresco.org/model/forum/1.0}post">
        <#– content other than forum posts –>
        <tr class="${rowstyle}">
          <td style="padding:2px;text-align:left;padding-right:10px;"><a href="/alfresco${child.url}" target="_blank"><img src="/alfresco${child.icon16}" border=0></a> <a href="/alfresco${child.url}" target="_blank">${child.properties.name}</a>
            <span onclick="AlfNodeInfoMgr.toggle('${child.nodeRef}',this);"><img id="browse:col1-img" src="/alfresco/images/icons/popup.gif" height="16" width="16" class="popupImage" /></span></td>
          <td style="padding:2px;text-align:left;padding-right:10px;">
            ${child.displayPath}
            <#–
            <#if child.displayPath=spacePath>
              <a href="/alfresco${child.parent.url}">.</a>
            <#else>
              <a href="/alfresco${child.parent.url}">${child.displayPath?replace(fullSpacePath,"")}</a>
            </#if>
            –>
          </td>
          <td style="padding:2px;text-align:left"><nobr>${child.properties["cm:modified"]?datetime}</nobr>
             / ${child.properties["cm:modifier"]}
          </td>
        </tr>
      <#else>
        <#– forum posts –>
        <tr class="${rowstyle}">
          <td style="padding:2px;text-align:left;padding-right:10px;"><a href="/alfresco${child.parent.url}"><img src="/alfresco${child.parent.icon16}" border=0></a> <a href="/alfresco${child.parent.url}">post to &lsquo;${child.parent.properties.name}&rsquo;</a>
          <span onclick="AlfNodeInfoMgr.toggle('${child.nodeRef}',this);"><img id="browse:col1-img" src="/alfresco/images/icons/popup.gif" height="16" width="16" class="popupImage" /></span></td>
          <td style="padding:2px;text-align:left;padding-right:10px;">
            ${child.displayPath}
            <#–
            <a href="/alfresco${child.parent.parent.url}">${child.parent.displayPath?replace(fullSpacePath,"")}</a>
            –>
          </td>
          <td style="padding:2px;text-align:left"><nobr>${child.properties["cm:modified"]?datetime}</nobr>
             / ${child.properties["cm:modifier"]}
          </td>
        </tr>
      </#if>

    </#list>
  </tbody>
  </table>


</#if>

alexandra
Champ on-the-rise
Champ on-the-rise
Thanks for a great script. I had been looking for something like this to start leveraging the metadata in the repository. I started out by modifying the example script and also noted  the bad performance. It was definiately an improvment with your new one.

I wonder if you have any luck in identifying the strange error you had.

For users in Europe that prefer 24H time representation instead of AM/PM you can replace the datetime_format with something like this.

<#setting datetime_format="dd MMM yy, HH:mm">


I have a question about how to do filtering in the query…

One of the problems of Mac OS X is that it creates metadata files on the filesystem that starts with a . (dot) for example:

._example.doc

which is the metadata companion to the real document called:

example.doc

Do you happen to know how to exclude files beginning with . from the search results?

kevinr
Star Contributor
Star Contributor
Since "." is a token separator in Lucene it will be tricky to filter by in the query. The best route is to simply test each file cm:name property to see if it beings with "." using the string comparison operators in FreeMarker.

Kevin