cancel
Showing results for 
Search instead for 
Did you mean: 

list of documents linked to a category in freemarker ftl

omegerard
Champ in-the-making
Champ in-the-making
Hi,

I'm trying to extract a list of documents that are linked to a specific category in freemarker templates. I've been trying a few tricks, but the only things they produced were lots of error lines in the log file.

Now, reading through the template guide, I was fairly convinced that childrenByLuceneSearch was the API to be used. (I'm sure that childrenBySavedSearch will do the job as well, but I don't want to clutter the repository with saved searches.). The only thing is, I can't get it to work. If I do

<#list companyhome.childrenByLuceneSearch(TEXT="3MF") as doc>


or, more specifically,


<#list companyhome.childrenByLuceneSearch(PATH:"/cm:generalclassifiable//cm:D6DocType/MPR/member") as doc>

the Freemarker syntax checker appears to be unhappy. Apprently, maps cannot be "listed". But, what can be done then?

Is there anybody out there who has already played with categories in Freemarker templates?

Regards

Ludo
14 REPLIES 14

kevinr
Star Contributor
Star Contributor
Hi,

The name of the API call childrenByLuceneSearch() is a bit misleading - it will return ALL items in the repo that match the lucene search string - not just children of the current node. Basically the API is there as a way to get to Lucene searches from within FreeMarker templates. Calls to the API expect a String so you must wrap the search in quotes:

<#list companyhome.childrenByLuceneSearch("TEXT:3MF") as doc>
If you want to perform a PATH search or something that already contains quote characters then you will need to escape the quote characters:
http://freemarker.sourceforge.net/docs/dgui_template_exp.html#dgui_template_exp_direct

Hope this helps,

Kevin

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

OK. I got the quotes right now, but still get an error message that I can't translate into a meaningful debugging action:

Error during processing of the template 'Expected method. companyhome.childrenByLuceneSearch evaluated instead to freemarker.template.SimpleHash on line 6, column 8 in workspace://SpacesStore/a287ff98-d6b4-11da-b76a-236c1d63a3ab.'. Please contact your system adminstrator.

It looks like the API does not expect a string but a hash?

Ludo

omegerard
Champ in-the-making
Champ in-the-making
Hi,

I've just learned that Freemarker/Lucene has problems with the integer "3" in the search string.


<#list companyhome.childrenByLuceneSearch("TEXT:3MF") as doc>

If I remove the "3" and make it


<#list companyhome.childrenByLuceneSearch("TEXT:MF") as doc>

it appears to work.

Now, what do I do if I'd really wanted to search for 3M? I tried \"3MF\", but then I get an error message again. (from the user interface???)

11:20:25,361 ERROR [ui.common.Utils] Error during processing of the template 'Fa
iled to execute search: TEXT:3MF'. Please contact your system adminstrator.
org.alfresco.service.cmr.repository.TemplateException: Error during processing o
f the template 'Failed to execute search: TEXT:3MF'. Please contact your system
adminstrator.

Any idea?

Regards

Ludo

kevinr
Star Contributor
Star Contributor
I'll take a look and see if i can get to the bottom of the errors.

Thanks,

Kevin

omegerard
Champ in-the-making
Champ in-the-making
OK Kevin, thanks.

I have been experimenting with PATH searches in FreeMarker templates and I must admit I'm still confused.

I put the following line in a template:

<#list companyhome.childrenByLuceneSearch["PATH:\"//cm:generalclassifiable//cm:D6Activity//cm:M4//cm:M4QoE//member\""] as member>
and I expected it to yield a list of all the documents that had been categorized as M4QoE. I know there are 4 documents that fullfill this requirement, but all I got was an empty list. (At least, it was not an error message. )

Now, this could be due to two reasons. Either I abused the search string, or the string did produce the four documents, but I was unable to "catch" them. The reason for my confusion is that I'm not sure if I understood the term "member" in the Search#Category_Queries wiki page. Is it correct that there IS a child relationship between category and its subcategories, but that actual documents are members and not children? If so,

1. why does the following freemarker script not produce a list of the subcatories of the "D6Activity"?


<table>
<#list companyhome.childrenByLuceneSearch["PATH:\"//cm:generalclassifiable//cm:D6Activity//*\""] as child>
    <tr><td>${child}</td></tr>
</#list>
</table>

2. 1. why does the following freemarker script not produce a list documents?


<table>
<#list companyhome.childrenByLuceneSearch["PATH:\"//cm:generalclassifiable//cm:D6Activity//cm:SDRFLAI//member*\""] as member>
    <tr><td><a href="/alfresco${member.url}" title="Download this file">${member.properties.name}</a></td></tr>
</#list>
</table>

Or, do these PATH search string always have to be combined with TEXT searches as in the web interface?

Ludo

omegerard
Champ in-the-making
Champ in-the-making
I must have had a bad day yesterday.

I have been testing these lucene search PATHs again and I can confirm that the following freemarker template yields the results that I expected:


<table>
<#list companyhome.childrenByLuceneSearch["PATH:\"/cm:generalclassifiable/*\""] as category>
    <tr><td>${category.name}</td></tr>
</#list>
</table>

It lists the names of the children of the root category.

omegerard
Champ in-the-making
Champ in-the-making
Did I really have a bad day yesterday?

What if I'd uncovered a bug?

Look, I tested two very similar Freemarker templates.

The first is:

<table>
<#list companyhome.childrenByLuceneSearch["PATH:\"/cm:generalclassifiable/cm:D6Activities/*\""] as category>
    <tr><td>${category.name}</td></tr>
</#list>
</table>

The other is:

<table>
<#list companyhome.childrenByLuceneSearch["PATH:\"/cm:generalclassifiable/cm:DesicsActivities/*\""] as category>
    <tr><td>${category.name}</td></tr>
</#list>
</table>

The latter works as expected. It produces a list of three subcategories:

ActivityOne
ActivityTwo
ActivityThree

The former should produce a list of 2 categories: "M4" and "test", but instead it produces an empty list (no error message).

Either this is a bug, or else there should be a means to "escape" the numbers.

This somehow confirms one of my earlier posts in this thread.

Regards

omegerard
Champ in-the-making
Champ in-the-making
I'm pleased to tell you that the confusion between member and child is over. I think that the wiki documentation is fairly clear: a child can be anything, a subcategory or a document that is linked to the particular category. A member is only the latter.

Now, there's still one thing that I don't understand I'm afraid. I'll have to go into some detail to explain it.

The following freemarker template

<table>
<#list companyhome.childrenByLuceneSearch["+PATH:\"/cm:generalclassifiable/cm:Desics/*\"  -PATH:\"/cm:generalclassifiable/cm:Desics/member\""] as category>
    <tr><td>${category.name}</td></tr>
</#list>
</table>
produces the following output:
Research
Contract
Type
Outlet
This is consistent with what I had expected.

If I include the members in the search string:

<table>
<#list companyhome.childrenByLuceneSearch["PATH:\"/cm:generalclassifiable/cm:Desics/*\""] as category>
    <tr><td>${category.name}</td></tr>
</#list>
</table>

then the output becomes as follows:

Research
Contract
Type
Outlet
ResearchGroups
Samsung CGA M4 MMPR April 2006.doc
Samsung CGA M4 MMPR March 2006.doc
Samsung CGA M4 TMPR March 2006.doc
Samsung DDT M4 TMPR March 2006.doc
Samsung INT ADRES AVC M4 MMPR March 2006.doc
Samsung INT ADRES AVC M4 TMPR March 2006.doc
Samsung INT SDR M4 MMPR March 2006.doc
Samsung INT SDR M4 TMPR March 2006.doc
…..

You will have recognized the four subcategories and the bunch of doc files that are linked to the Desics category. But why on earth is the name "ResearchGroups" listed? "ResearchGroups" isn't a document. Neither is it a child of the "Desics" category. It is a subdirectory of a directory with the name "Desics" that resides right under the Company Home. Again, why is it listed here?


Regards

Ludo

andy
Champ on-the-rise
Champ on-the-rise
Hi Ludo

Can you query for just members?
Is ResearchGroups included?

Does the advanced search agree with your results?

Although I think it is not exposed in the UI, folders can be categorised.

Have you got an rule that is setting categories?
It may also have set category on the folder.

Regards

Andy