Attachment Search Module

Last modified by Eleni Cojocariu on 2026/10/01 09:49

Reference

The RequireJS module xwiki-attachment-picker-solr-search, one of the two modules of the Attachment Picker WebJar, returns the SolrSearch class. It is what a picker searches with, and it needs no picker: it sends every query to the get action of the XWiki.SuggestSolrService page, resolved once when the object is built.

Members

MemberReturnsDescription
new SolrSearch(options)A SolrSearchTakes one object, holding the three options below.
search(query, isGlobal)A promise of an array of resultsAlways searches the target Page. When isGlobal is true, it also runs an unscoped search and merges the two.
OptionValueDefault
limitThe maximum number of results a search resolves to20
targetThe reference of the Page a local search is scoped to. It replaces the Page and its location, and replaces the wiki too when the reference names oneThe Page the script runs on
solrOptionsfilter, a comma-separated list of media types, and sort, a Solr sort clauseNeither
Result fieldValue
idThe reference of the attachment, serialized
filenameThe file name, as an array of one element
mimetypeThe media type, as an array of one element
isLocalWhether the attachment comes from the target Page
require(['xwiki-attachment-picker-solr-search'], function (SolrSearch) {
  const search = new SolrSearch({
    limit: 10,
    target: 'Sandbox.WebHome',
    solrOptions: {filter: 'image/png,image/jpeg'}
  });

  // Pass true to search beyond the target page as well.
  search.search('logo', true).then(function (results) {
    results.forEach(function (result) {
      console.log(result.id, result.filename[0], result.mimetype[0], result.isLocal);
    });
  });
});

Rules of a Search

RuleBehaviour
The order of a global searchThe results of the target Page first, then those found elsewhere minus the ones already listed, the whole cut back to limit.
The scope of a global searchNo wiki, location or Page clause at all, so the second query reaches the whole farm the search service covers.
The scope of every queryAttachments only and, deliberately, every locale, so the attachments of a Page translated into another language than the current one are not dropped.
An empty querySearched as *, so an empty search field lists everything in scope.

FAQ

Why does a filter of several media types match nothing?

The list is split on commas and on nothing else, so each media type becomes one clause of the query only when the list carries no separator and no spacing of its own: write image/png,image/jpeg.

Related

Get Connected