This question about Missing functionality: Answered

How to retrieve number of attachments in search?

Suppose I have a query-search looking for all topics with field F having value V, and in the resulting format="" string I want to list the number of attachments in that topic? Or suppose I want to do a query-search looking for all topics that have exactly 2 or 3 attachments?

I sort of assumed that would be easy, but as yet I haven't found a way to do either of these. frown, sad smile

What did I miss?

Hi Bob, I'd suggest taking a look at DBCacheContrib, DBCachePlugin and FormQueryPlugin Unfortunately from what I could read in the docs, they can't directly query the attachment count. But possibly someone with more knowledge of these plugins might some ideas.

-- GeorgeClark - 12 May 2010

Use AttachmentListPlugin.

-- ArthurClemens - 12 May 2010

It doesn't seem as if either option (i.e. the DBCache stuff or the AttachmentListPlugin) can do this simple task, unless I'm very much mistaken:

Given a query search looking for field F having value V, produce output like this:

  • Topic1 has 2 attachment(s)
    • Attachment1
    • Attachment2
  • Topic2 has 1 attachment(s)
    • Attachmentxxx
  • Topic3 has 0 attachment(s)

... and so on. At least I can't make them do that. Can they?

-- BigBaaadBob - 12 May 2010

I haven't tested DBCache, but I am almost sure it will work with it. This is an example for AttachmentListPlugin.

Basically you are listing properties of topics (a filtered selection), so start with a SEARCH first that outputs the desired topics. Assuming you are looking for topics with the value of "Category" is "Interesting":


Then instead of just listing each topic, perform an ATTACHMENTLIST action on those topics. This should be escaped to postpone rendering:
format="$percntATTACHMENTLIST{topic=$quot$topic$quot web=$quot$web$quot header=$quot   * [[$web.$topic][$topic]] has $fileCount attachment(s):$quot format=$quot      * $fileName$quot}$percnt"

This gives the exact output as you described above:

  • BlogPostExample has 1 attachment(s):
    • Triumph__Daytona_675_2006_07_1024x768.jpg
  • Some_stuff_IVe_read has 2 attachment(s):
    • extra-sms.png
    • icon_address_book.png
  • Some_title has 1 attachment(s):
    • icon_checkmark-black.png

-- ArthurClemens - 12 May 2010

Ah! I didn't think of that use of the header part. Thanks!

So, this structurally works, but in my case it doesn't actually work because the search returns something like 1300 topics, but only about 80 get printed! A whole bunch of errors get printed in the apache log. I submitted Tasks.Item9015 for that.

-- BigBaaadBob - 13 May 2010

QuestionForm edit

Subject Missing functionality
Version Foswiki 1.0.9
Status Answered
Topic revision: r6 - 13 May 2010, BigBaaadBob - This page was cached on 22 May 2019 - 16:54.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy