Failed to execute template. Cause: [Access denied when checking [script] access to [xwiki:Collaboratory.UX.HbpSkin.WebHome] for user [xwiki:XWiki.Admin]]. Click on this message for details.

Context Search - HBP Wiki

IAM21 instance, do not create collab nor modify a team, your changes will be lost


Context Search

Version 12.1 by bougault on 2022/10/14 08:41


  /*
  async function fetchGlobalSearch(term) {
    const res = await fetch(`/rest/wikis/query?q=${term}&media=json`)
    const json = await res.json();
    return JSON.stringify(json, null, 2);
  }
  async function fetchCurrentCollabSearch(term) {
    const res = await fetch(`/rest/wikis/xwiki/spaces/Collabs/spaces/bougaultx/search?q=${term}&media=json`)
    const json = await res.json();
    return JSON.stringify(json, null, 2);
  }
  window.addEventListener('DOMContentLoaded', function() {
    const contextSearchType = document.getElementById("context-search-type");
    const contextSearchText = document.getElementById("context-search-text");
    const contextSearchResponse = document.getElementById("context-search-response");
    const contextSearchButton = document.getElementById("context-search-button");
    contextSearchButton.addEventListener('click', function() {
      const context = contextSearchType.options[contextSearchType.selectedIndex].value;
      const term = contextSearchText.value;
      switch(context) {
          case 'collabs':
            document.location.href = `/bin/view/Collabs/#search=${term}`;
            break;
          case 'current-collab':
            fetchCurrentCollabSearch(term).then(results => contextSearchResponse.innerText = results);
            break
          default:
            fetchGlobalSearch(term).then(results => contextSearchResponse.innerText = results);
      }

    });
  });
*/
  console.log('hello world');
const solrServiceURL = new XWiki.Document('SuggestSolrService', 'XWiki').getURL('get');
console.log('xxxxx', solrServiceURL);

require(['jquery'], function($) {
  console.log('ZZZZ');
  var solrServiceURL = new XWiki.Document('SuggestSolrService', 'XWiki').getURL('get');
  const contextSearchButton = document.getElementById("context-search-button");
  contextSearchButton.addEventListener('click', function() {
    $.post(solrServiceURL, {
      outputSyntax: 'plain',
      media: 'json',
      query: [
        'q=*__INPUT__*',
        'fq=type:DOCUMENT',
        'fq=space:Collabs.the-collaboratory'
      ].join('\n'),
      input: $('#context-search-text').val()
    });
  });
});