Wiki-Quellcode von Solr Suche Administration
Zuletzt geändert von Daniel Herrmann am 2025/11/08 02:44
Verstecke letzte Bearbeiter
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | {{velocity output='false'}} |
| 2 | #macro (displaySolrIndexForm) | ||
| 3 | {{html clean="false"}} | ||
| 4 | <form class="xform" action="$xwiki.relativeRequestURL" method="post"> | ||
| 5 | <div class="hidden"> | ||
| 6 | <input type="hidden" name="form_token" value="$services.csrf.token" /> | ||
| 7 | </div> | ||
| 8 | <dl> | ||
| 9 | <dt> | ||
| 10 | <label for="solrAdminAction">$services.localization.render('solr.admin.indexing.action.label')</label> | ||
| 11 | <span class="xHint">$services.localization.render('solr.admin.indexing.action.hint')</span> | ||
| 12 | </dt> | ||
| 13 | <dd> | ||
| 14 | <select id="solrAdminAction" name="action"> | ||
| 15 | <option value="index">$services.localization.render('solr.admin.indexing.action.select_index')</option> | ||
| 16 | <option value="delete">$services.localization.render('solr.admin.indexing.action.select_delete')</option> | ||
| 17 | <option value="reindex">$services.localization.render('solr.admin.indexing.action.select_reindex')</option> | ||
| 18 | </select> | ||
| 19 | </dd> | ||
| 20 | ## Indexing on the entire farm or on various wikis is done only on the main wiki. | ||
| 21 | #if ($xcontext.isMainWiki()) | ||
| 22 | <dt> | ||
| 23 | <label for="solrAdminWiki">$services.localization.render('solr.admin.indexing.wiki.label')</label> | ||
| 24 | <span class="xHint">$services.localization.render('solr.admin.indexing.wiki.hint')</span> | ||
| 25 | </dt> | ||
| 26 | <dd> | ||
| 27 | <select id="solrAdminWiki" name="wiki"> | ||
| 28 | <option value="">$services.localization.render('solr.admin.indexing.wiki.select_farm')</option> | ||
| 29 | #foreach ($wiki in $allWikis) | ||
| 30 | #set ($wikiPrettyName = $services.wiki.getById($wiki).prettyName) | ||
| 31 | #if ("$!wikiPrettyName.trim()" == '') | ||
| 32 | #set ($wikiPrettyName = $wiki) | ||
| 33 | #end | ||
| 34 | <option value="$wiki">$wikiPrettyName</option> | ||
| 35 | #end | ||
| 36 | </select> | ||
| 37 | </dd> | ||
| 38 | #end | ||
| 39 | ## We allow only users with programming rights to execute custom queries in order to prevent administrators that | ||
| 40 | ## don't have programming rights from executing full statement queries when this page is saved with programming | ||
| 41 | ## rights. | ||
| 42 | #if ($hasProgramming) | ||
| 43 | <dt> | ||
| 44 | <label for="solrAdminCustomQuery">$services.localization.render('solr.admin.indexing.query.label')</label> | ||
| 45 | <span class="xHint">$services.localization.render('solr.admin.indexing.query.hint')</span> | ||
| 46 | </dt> | ||
| 47 | <dd> | ||
| |
2.1 | 48 | <label class="sr-only" for="customQueryLanguage">## |
| 49 | $escapetool.xml($services.localization.render('solr.admin.indexing.query.language.label'))## | ||
| 50 | </label>## | ||
| 51 | <select id="customQueryLanguage" name="customQueryLanguage"> | ||
| |
1.1 | 52 | <option value="xwql">XWiki Query Language (XWQL)</option> |
| 53 | <option value="hql">Hibernate Query Language (HQL)</option> | ||
| 54 | </select> | ||
| 55 | <textarea id="solrAdminCustomQuery" name="customQuery" rows="7" cols="45"></textarea> | ||
| 56 | </dd> | ||
| 57 | #end | ||
| 58 | </dl> | ||
| 59 | <p class="buttons"> | ||
| 60 | <span class="buttonwrapper"> | ||
| 61 | <input type="submit" class="button" value="$services.localization.render('solr.admin.submit')" /> | ||
| 62 | </span> | ||
| 63 | </p> | ||
| 64 | </form> | ||
| 65 | {{/html}} | ||
| 66 | #end | ||
| 67 | |||
| 68 | #macro (displaySolrAdminSection) | ||
| 69 | #set ($discard = $xwiki.ssx.use('XWiki.SolrSearchAdmin')) | ||
| 70 | #set ($discard = $xwiki.jsx.use('XWiki.SolrSearchAdmin')) | ||
| 71 | == $services.localization.render('solr.admin.status.title') == | ||
| 72 | |||
| 73 | (% class="xform" %)((( | ||
| 74 | ; {{html clean="false"}}<label>$services.localization.render('solr.admin.status.queueSize.label')</label>{{/html}}## | ||
| 75 | (% class="xHint" %)$services.localization.render('solr.admin.status.queueSize.hint') | ||
| 76 | : (% class="solrQueueSize" %)$services.solr.queueSize | ||
| 77 | ))) | ||
| 78 | |||
| 79 | == $services.localization.render('solr.admin.indexing.title') == | ||
| 80 | |||
| 81 | #displaySolrIndexForm() | ||
| 82 | #end | ||
| 83 | |||
| 84 | #macro (handleSolrIndexAction) | ||
| 85 | ## | ||
| 86 | ## Build the targets. | ||
| 87 | ## | ||
| 88 | #set ($targetReferences = []) | ||
| 89 | #set ($wikis = $request.getParameterValues('wiki')) | ||
| 90 | #if ($xcontext.isMainWiki()) | ||
| 91 | #if (!$wikis || ($wikis.size() == 1 && $wikis[0] == '')) | ||
| 92 | ## No wiki specified => target the entire farm. | ||
| 93 | #set ($wikis = $allWikis) | ||
| 94 | #end | ||
| 95 | #else | ||
| 96 | ## Target only the current (sub)wiki. | ||
| 97 | #set ($wikis = [$xcontext.database]) | ||
| 98 | #end | ||
| 99 | ## On each wiki, execute the custom query or add the entire wiki. | ||
| 100 | #foreach ($wiki in $wikis) | ||
| 101 | #set ($wikiReference = $services.model.createWikiReference($wiki)) | ||
| 102 | ## Only administrators with programmings rights are allowed to execute a custom query. | ||
| 103 | #if ($hasProgramming && !$stringtool.isBlank($request.customQuery)) | ||
| 104 | #set ($query = $services.query.createQuery($request.customQuery, $request.customQueryLanguage)) | ||
| 105 | ## Always use the database specified by the wiki parameter. | ||
| 106 | #set ($discard = $query.setWiki($wiki).addFilter('unique')) | ||
| 107 | ## Run the custom query and get the document references. | ||
| 108 | #foreach ($documentName in $query.execute()) | ||
| 109 | #set ($documentReference = $services.model.resolveDocument($documentName, $wikiReference)) | ||
| 110 | #set ($discard = $targetReferences.add($documentReference)) | ||
| 111 | #end | ||
| 112 | #else | ||
| 113 | #set ($discard = $targetReferences.add($wikiReference)) | ||
| 114 | #end | ||
| 115 | #end | ||
| 116 | ## | ||
| 117 | ## Perform the action on the computed targets. | ||
| 118 | ## | ||
| 119 | #if ($request.action == 'index') | ||
| 120 | #set ($discard = $services.solr.index($targetReferences)) | ||
| 121 | #elseif ($request.action == 'delete') | ||
| 122 | #set ($discard = $services.solr.delete($targetReferences)) | ||
| 123 | #elseif ($request.action == 'reindex') | ||
| 124 | #set ($discard = $services.solr.delete($targetReferences)) | ||
| 125 | ## Proceed to the index step only if the delete step was successful. | ||
| 126 | #if ("$!xcontext.lastexception" == '') | ||
| 127 | #set ($discard = $services.solr.index($targetReferences)) | ||
| 128 | #end | ||
| 129 | #end | ||
| 130 | ## | ||
| 131 | ## Display the action result. | ||
| 132 | ## | ||
| 133 | #set ($exception = $xcontext.lastexception) | ||
| 134 | #if ("$!exception" != '') | ||
| 135 | #set ($message = "$services.localization.render('solr.admin.error.action', $stringtool.capitalize($request.action)) $exception.message ($exception.class)") | ||
| 136 | #if ($isAjaxRequest) | ||
| 137 | $response.sendError(500, $message) | ||
| 138 | #else | ||
| 139 | {{error}}$message{{/error}} | ||
| 140 | #end | ||
| 141 | #elseif (!$isAjaxRequest) | ||
| 142 | {{success}}$services.localization.render('solr.admin.success.action', $escapetool.xml($stringtool.capitalize($request.action))){{/success}} | ||
| 143 | ## Only administrators with programmings rights are allowed to execute a custom query. | ||
| 144 | #if ($hasProgramming && !$stringtool.isBlank($request.customQuery)) | ||
| 145 | |||
| 146 | {{info}}$services.localization.render('solr.admin.info.affectedDocuments') $targetReferences{{/info}} | ||
| 147 | #end | ||
| 148 | |||
| 149 | #displaySolrAdminSection() | ||
| 150 | #end | ||
| 151 | #end | ||
| 152 | |||
| 153 | #macro(handleSolrAction $withValidToken) | ||
| 154 | #set ($indexActions = ['index', 'reindex', 'delete']) | ||
| 155 | #if ($withValidToken && $indexActions.contains($request.action)) | ||
| 156 | #set ($allWikis = $collectiontool.sort($xwiki.wikiNames)) | ||
| 157 | #handleSolrIndexAction() | ||
| 158 | #elseif ($request.action == 'getQueueSize') | ||
| 159 | $response.setContentType('application/json') | ||
| 160 | $jsontool.serialize({ | ||
| 161 | 'queueSize': $services.solr.queueSize, | ||
| 162 | 'timestamp': $datetool.date.time | ||
| 163 | }) | ||
| 164 | #else | ||
| 165 | #set ($allWikis = $collectiontool.sort($xwiki.wikiNames)) | ||
| 166 | #displaySolrAdminSection() | ||
| 167 | #end | ||
| 168 | #end | ||
| 169 | |||
| 170 | #macro (handleSolrRequest) | ||
| 171 | #if (!$hasGlobalAdmin) | ||
| 172 | #if ("$!request.action" != '') | ||
| 173 | {{error}}$services.localization.render('solr.admin.error.notallowed'){{/error}} | ||
| 174 | #else | ||
| 175 | {{error}}$services.localization.render('solr.admin.error.norights'){{/error}} | ||
| 176 | #end | ||
| 177 | #elseif ($request.form_token) | ||
| 178 | #if ($services.csrf.isTokenValid($request.form_token)) | ||
| 179 | #handleSolrAction(true) | ||
| 180 | #elseif ($isAjaxRequest) | ||
| 181 | $response.sendError(401, 'CSRF token verification failed!') | ||
| 182 | #else | ||
| 183 | $response.sendRedirect($services.csrf.getResubmissionURL()) | ||
| 184 | #end | ||
| 185 | #else | ||
| 186 | #handleSolrAction(false) | ||
| 187 | #end | ||
| 188 | #end | ||
| 189 | {{/velocity}} | ||
| 190 | |||
| 191 | {{velocity}} | ||
| 192 | #set ($isAjaxRequest = $request.getHeader('X-Requested-With') == 'XMLHttpRequest') | ||
| 193 | #handleSolrRequest() | ||
| 194 | {{/velocity}} |