Code source wiki de Solr Suggestion Service
Modifié par Thomas Mortagne le 2022/06/29 13:01
Afficher les derniers auteurs
author | version | line-number | content |
---|---|---|---|
1 | {{include reference="XWiki.SuggestSolrMacros" /}} | ||
2 | |||
3 | {{template name="hierarchy_macros.vm" /}} | ||
4 | |||
5 | {{velocity output="false"}} | ||
6 | #macro (serializeResultsAsXML $results) | ||
7 | #set ($discard = $response.setContentType('text/xml')) | ||
8 | <?xml version="1.0" encoding="UTF-8"?> | ||
9 | <results> | ||
10 | #foreach ($result in $results) | ||
11 | #set ($resultReference = $services.solr.resolve($result)) | ||
12 | #set ($id = $escapetool.xml($services.model.serialize($resultReference, 'default'))) | ||
13 | #set ($type = $escapetool.xml($resultReference.type.toString().toLowerCase())) | ||
14 | #set ($url = $escapetool.xml($xwiki.getURL($resultReference))) | ||
15 | #set ($title = $resultReference.name) | ||
16 | #if ($resultReference.type == 'DOCUMENT') | ||
17 | #set ($title = $result.title_) | ||
18 | #if ($resultReference.locale) | ||
19 | ## Display the document locale after the title. | ||
20 | #set ($title = "$title ($resultReference.locale)") | ||
21 | #end | ||
22 | #end | ||
23 | #set ($title = $escapetool.xml($title)) | ||
24 | #set ($options = { | ||
25 | 'excludeSelf': true, | ||
26 | 'limit': 4 | ||
27 | }) | ||
28 | ## We don't want the full HTML generated by the hierarchy macro but we can't use the 'plain' option either because | ||
29 | ## we loose the home icon. | ||
30 | #getHierarchyPath($resultReference $path $options) | ||
31 | #getHierarchyPathLabels($path $labels $options) | ||
32 | #set ($location = $escapetool.xml($stringtool.join($labels, ' / '))) | ||
33 | <rs id="$!id" type="$!type" url="$!url" info="$!location">$!title</rs> | ||
34 | #end | ||
35 | </results> | ||
36 | #end | ||
37 | {{/velocity}} | ||
38 | |||
39 | {{velocity wiki="false"}} | ||
40 | #if ("$!request.query" != '' && "$!request.input" != '') | ||
41 | #getSearchSuggestResults($results) | ||
42 | #if ($request.media == 'json' || $request.getHeader('Accept') == 'application/json') | ||
43 | #jsonResponse($results) | ||
44 | #else | ||
45 | #serializeResultsAsXML($results) | ||
46 | #end | ||
47 | #end | ||
48 | {{/velocity}} | ||
49 | |||
50 | {{velocity}} | ||
51 | #if ("$!request.query" == '' || "$!request.input" == '') | ||
52 | {{info}} | ||
53 | This service provides search results for the search suggest UI component. | ||
54 | Examples: | ||
55 | * [[$doc.getExternalURL('get', 'outputSyntax=plain&query=__INPUT__*&input=test')]] | ||
56 | {{/info}} | ||
57 | #end | ||
58 | {{/velocity}} |