JavaScript Search Widget for 5.0

Document created by Curtis Gross on Sep 8, 2011
Version 1Show Document
  • View in full screen mode

Usecase:

For Admins to provide a quick search widget to automatically select the place, person or content type that needs to be filtered on.

Use an HTML widget on an overview page.

 

Visual:

Screen shot 2011-09-08 at 9.54.38 AM.png

 

 

Code:

 

<script type="text/javascript" language="javascript">  
function fixurl ()  
{  


/* The easiest way to build out these variables is to run a search for
  what you would like this widget to return.  Copy and paste the URL of 
  that successful search into a plain text editor.  Copy all of the URLs 
  into this code below*/

        var query = document.getElementById("collateral_text-box").value  

  /* the search will be pulled from the text box*/
       var query = "&q=" + query;  

  /*search for content but be sure to select a user to limit results, 
  look in the URL and grab the variable for 'userID' and insert it here.*/
       var userID = "&userID="  

  /* 14=space, 700=group, 600=project.  
  You must have containerType, container # and container Name to search for 
  a space / group / project */
       var containerType = "&containerType="

  /* Run a search limited to a group, space, project and inspect the URL for
  the container number*/
        var container = "&container="

  /* Run a search to locate the container name - not required */
       var containerName = "&containerName="

  /* values:  all, yesterday, last7days, last30days, lastyear*/
  var dateRange = "&dateRange=all"

  /*values: relevance, likes, rating, subject, dates*/
       var rankBy = "&rankby=relevance"

  /* values: all, document, blogpost, message (discussions), task, external-site, poll, idea */
               var typeValue = "all"
       var contentType = "&contentType=" + typeValue ;

  /* from what I can tell, result type = contnt type...*/
       var resultTypes = "&resultTypes=" + typeValue ;
       
  /* number of results, enter a number!*/
            var numResults = "&numResults="
  
  

  var combined_url = userID + containerType + container + containerName + resultTypes + dateRange + rankBy + contentType + query + numResults ;  
  window.location = "/search.jspa?peopleEnabled=true" + combined_url;  
}  
</script>


          <form id="myform2" action="#" onSubmit="fixurl();return false;" style="margin:10px;">
               <input type="text" name="query" size="20" value="" id="collateral_text-box">   
               <input type="submit" id="go-button" value="Go" onClick="fixurl();return false;"/>
          </form> 

 

Example:

 

I wanted to search a specific space, to modify the code I changed 2 things

 

First I ran a search and selected a space within my environment, this was the URL result, I highlighted the important parts.

http://my-instance.jive.com/search.jspa?view=content&resultTypes=&dateRange=all&q=mysearch&rankBy=relevance&contentType=all&containerType=14&container=2010&containerName=Sales&userID=&numResults=15  

Then I made the changes in the code posted above.  I added 14 and 2010, then saved!

 

var containerType = "&containerType=14"

var container = "&container=2010"

Attachments

    Outcomes