I am using XMLUI (Mirage) on DSpace 6.2 and am trying to insert the "Most Downloaded Items" into the home page.
I have figured out the SOLR query for this, namely (in page-structure.xsl):
<xsl:variable name="statsURL">
<xsl:text>http://localhost/solr/statistics</xsl:text>
</xsl:variable>
<xsl:apply-templates select="document(concat($statsURL,'/select?q=type:0+-isBot:true+statistics_type:view&wt=xml&indent=true&facet=true&facet.field=id&facet.sort=count&facet.limit=10'))" mode="mostdownloaded"/>
This query returns an xml document:
<response>
+<result name="response" numFound="8" start="0"></result>
-<lst name="facet_counts">
<lst name="facet_queries"/>
-<lst name="facet_fields">
-<lst name="id">
<int name="49b63c98-122c-40d4-9181-2ad4db8853c9">8</int>
<int name="061c72a0-3edc-4e17-8f33-4e7f6ce4573a">0</int>
<int name="0e124f85-4636-4eb5-85cb-2e4afd3e3ed0">0</int>
<int name="19095190-9074-4a4a-bb59-abcb539c8c38">0</int>
<int name="1e5350e0-83d9-4f26-bd76-e5d660254ee6">0</int>
<int name="432038ee-a7d7-4c69-80c1-02641e105286">0</int>
<int name="6b70eeea-be33-4489-8370-189ef041ba93">0</int>
<int name="9a8cd24e-3d88-43fc-8e92-b4e2c6142fbc">0</int>
<int name="bba37b59-7edc-453c-87d2-4039e432217b">0</int>
<int name="cc78e683-9563-49df-b5cf-35d506b4a27d">0</int>
</lst>
</lst>
<lst name="facet_dates"/>
<lst name="facet_ranges"/>
<lst name="facet_intervals"/>
</lst>
</response>
I then match this to a template as in:
<xsl:template match="/response/lst/lst/lst/int" mode="most-downloaded">
<div class="most_downloaded">
<xsl:value-of select="./@name"/>
</div>
<div class="downloaded_count">
<xsl:value-of select="text()"/>
</div>
</xsl:template>
I expect to see 8 divs of class "most_downloaded", each containing the id of the item, interspersed with another 8 divs of class "downloaded_count" containing the actual value. I do see these divs, but above them, I get a dump of all of the XML text nodes. I think that this is happening due to my poor understanding of template matching.
My questions are:
i) Is my query to get the list of most downloaded items correct? I have tried to test this but did not receive positive results.
ii) What is the correct way to match the template? /response/lst/lst/lst/int just sounds wrong.
iii) How can I use the id (which I believe is the item uuid in the database) to get the mets.xml data via cocoon?
iv) Is there an easier way to do all of this?
Thanks for any help.
i) Your query gets bitstream IDs, not the IDs of the owning item. For most downloaded items you'll want facet.field=owningItem
, and possibly also an exclusion so you don't count thumbnails (something like &fq=bundleName:ORIGINAL
- you'll need to adjust that if you have non standard bundle names).
ii) Looks good to me. You probably want something like <xsl:template match="*" mode="most-downloaded">
to suppress the random XML junk you're seeing.
iii) I think it'll be better to get the metadata from the Discovery Solr core rather than trying to obtain the mets.xml file. You may be able to do a Solr join to the discovery core and get the title (or whatever other metadata you want) from there all in one query, but I'm not sure that works with faceting. You could, in your template, make a query to the Discovery core for each ID to get what you're after (eg http://localhost:8080/solr/search/select?q=*:*&fq=search.id=[id-goes-here]&rows=1&fl=title).
iv) Depends on whether you think writing Java code is easier ;) I have solved much the same issue locally in a two-step process: (a) query solr once per day with a query much like yours and write the results to a (JSON) file; (b) write Java code for a Cocoon transformer that loads the item IDs from the file, looks up the corresponding item's title then puts that into the page in a useful format. Not sure whether your approach is any better/worse! Though my approach avoids having to query Solr in real time, which we found to be quite resource intense.
Just for reference, my query for the JSON file mentioned in (iv) is http://localhost:8080/solr/statistics/select?q=*:*&fq=-isBot:true&fq=type:0&fq=statistics_type:view&facet=true&facet.field=owningItem&facet.limit=5&indent=true&rows=0&fq=time:[NOW/DAY-7DAYS+TO+NOW/DAY]&facet.mincount=5&fq=bundleName:ORIGINAL&wt=json&omitHeader=true