AI Search Results Action parameters

Danny Roso
Tera Contributor

Hi everyone,

 

I would like to get a url parameter of the search results page and pass it from the search results page to the resulting url when clicking a search result so that this url parameter can be used for further processing on the appropriate portal page.

 

With the AI Search Results Action I do not see a possibility to apply the url parameter of the search results page to the resulting url.

 

An alternative would be to store the url parameter in the user session so that it can be picked up at a later stage, but before looking into alternative ways I would like to check here if I am perhaps missing a possibility of AI Search Results Action or perhaps other more convienient ways?

 

 

5 REPLIES 5

ondreJm
Tera Contributor

setURL was not working for me, and even if it worked, its only the server code anyway
Its little bit sad how hard is to modify the AI search componets and instead of few lines of code in the earch restult widget, you need to spend hours of investigation

SOLUTION
this worked for me 🙂
1)just create a new portal widget
2) add it to the page with the search results
3) into the client script of the widget add this code (dont forget to inject $rootScope+$window)

$rootScope.$on('$locationChangeStart', function(e,newUrl,oldUrl){
    // add search query to the redirected URL if current url contains q= param and target url not
    if ((oldUrl.indexOf('q=') != -1) && (newUrl.indexOf('q=') == -1) ) {
      var url = oldUrl;
      // get the q= param
      var regex = /[?&]q=([^&]+)/;
      var match = url.match(regex);
      if (match) {
        var searchText = match[1];
        // stop redirect
        e.preventDefault();

                      // redirect to the updated links
        $window.location.href = newUrl + '&q='+ searchText
      }
    }

  })
4)enjoy

TAG: how to add search query to the AI search result, modify search result link

PS: parsing of the url can be done better, its just proof of concept