Wiki-Quellcode von SearchSuggestCode

Zuletzt geändert von admin am 2025/02/23 19:33

Verstecke letzte Bearbeiter
admin 1.1 1 {{velocity output="false"}}
2 #if ($xcontext.action == 'get')
3 ## Iterate over the sources defined in the configuration document, and create a source array to be passed to the
4 ## search suggest contructor.
5 #set ($sources = [])
6 #set ($searchSuggestConfig = $xwiki.getDocument('XWiki.SearchSuggestConfig'))
7 #foreach ($source in $searchSuggestConfig.getObjects('XWiki.SearchSuggestSourceClass'))
8 #if ($source.getProperty('activated').value == 1)
9 #set ($engine = $source.getProperty('engine').value)
10 #if ("$!engine" == '')
11 ## For backward compatibility we consider the search engine to be Lucene when it's no specified.
12 #set ($engine = 'lucene')
13 #end
14 #set ($discard = $xwiki.getDocument('XWiki.SearchCode').getRenderedContent())
15 #if ($engine == $searchEngine)
16 #try("evaluateException")
17 #set ($evaluatedSource = $source.evaluate())
18 #end
19 #if ("$!evaluateException" != '')
20 #set ($discard = $logtool.error(
21 "Error when trying to evaluate XWiki.SearchSuggestSourceClass: $evaluateException"))
22 #set ($discard = $logtool.debug($exceptiontool.getStackTrace($evaluateException)))
23 #end
24 #set ($name = $source.getProperty('name').value)
25 #if ($services.localization.get($name))
26 #set ($name = $services.localization.render($name))
27 #elseif ("$!evaluatedSource" != '')
28 ## Evaluate the Velocity code for backward compatibility.
29 #set ($name = $evaluatedSource.name)
30 #end
31 #set ($icon = $source.getProperty('icon').value)
32 #if ($icon.startsWith('icon:'))
33 #set ($icon = $xwiki.getSkinFile("icons/silk/${icon.substring(5)}.png"))
34 #elseif ("$!evaluatedSource" != '')
35 ## Evaluate the Velocity code for backward compatibility.
36 #set ($icon = $evaluatedSource.icon)
37 #end
38 #set ($service = $source.getProperty('url').value)
39 #set ($parameters = {
40 'query': $source.getProperty('query').value,
41 'nb': $source.getProperty('resultsNumber').value
42 })
43 #if ($xwiki.exists($service))
44 #set ($discard = $parameters.put('outputSyntax', 'plain'))
45 #set ($service = $xwiki.getURL($service, 'get', $escapetool.url($parameters)))
46 #else
47 ## Evaluate the Velocity code for backward compatibility.
48 #set ($service = "#evaluate($service)")
49 #set ($service = "$service#if ($service.contains('?'))&#else?#end$escapetool.url($parameters)")
50 #end
51 #set ($highlight = $source.getProperty('highlight').value == 1)
52 #set ($discard = $sources.add({
53 'name': $name,
54 'varname': 'input',
55 'script': $service,
56 'icon': $icon,
57 'highlight': $highlight
58 }))
59 #end
60 #end
61 #end
62 #jsonResponse($sources)
63 #end
64 {{/velocity}}