SharePoint has a Search REST service that provides functionality to search your site/s and deliver content that meets your query. You can use this in any of ShortPoint’s design elements to display a list of search results.


Follow this link for more information about SharePoint’s Search REST service.


Let us integrate this functionality and display results in a ShortPoint design element just like this example:



TABLE OF CONTENTS


Step 1: Insert ShortPoint design element


Bring your SharePoint page to edit mode, add a web part, and use the ShortPoint app to insert the design element of your choice.


In our example, we are using a Simple Files List design element.


  • In Modern Pages:

Edit your page, insert a web part using the ShortPoint app, and click the plus sign to access the Page Builder.


  • In Classic Pages:

Edit your page, go to the Insert tab and click the plus sign in the ShortPoint section of the SharePoint ribbon.


 You can then go to the Lists tab and choose Simple Lists.



Step 2: Choose REST API in Connect Tab


Go to the Connect Tab and select REST API in the connection types options.



Step 3: Enter your query GET request


In the REST API URL field, input your HTTP GET request. To find guidance about the parameters you can use, check this article on Querying with the Search REST service.


Here are some example queries that may be useful:


  • Simple search query
<Your site URL>/_api/search/query?querytext='text'

    Where you replace <Your site URL> with your site collection URL and text with a term you want to search.



  • Search a specific site
<Your site URL>/_api/search/query?querytext='Path:"https://xyz/*" AND IsDocument:True'&rowlimit=1000&sourceid='40f080a5-da63-4dce-b33a-fdad0dc83d1c'&refinementfilters='fileExtension:or("docx","wmv","pdf","doc","xls","xlsx","ppt","pptx","mpp","csv","txt")'

    

    Where you replace <Your site URL> with your site collection URL and https://xyz/* is the specific site URL


  • Filter results by document type
<Your site URL>/_api/search/query?querytext='ContentTypeId:"0x0101*" AND IsDocument:True'&rowlimit=1000&refinementfilters='fileExtension:or("docx","wmv","pdf","doc","xls","xlsx","ppt","pptx","mpp","csv","txt")'

    

    Where you replace <Your site URL> with your site collection URL


In our example, we are using a simple GET request that searches for a specific term “project” and filtering by defined document types.


You can also add the specific number of results to show on your page by adding a number in the Items Limit field.




Step 4: Paste code in Map Results


The result provided by your query will not be in a format that ShortPoint can display in the design element. To correct this, you will need to use the code provided below:


var returnData = [];
var $ = shortpoint.$;
var results = data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results;
$.each(results, function () {
var row = {};
$.each(this.Cells.results, function () {
row[this.Key] = this.Value;
});
returnData.push(row);
});
return returnData;


Copy the code, enable Advanced Settings, and paste in the Map Results field.


Note: For more information, access the Map Results function for your Custom REST APIs article.



Once done, click the Connect button and wait for the connection to load.



Step 5: Map Items to Display


Choose the properties of the results you want to display from the drop-down.


We have chosen to show the Title and Author as the item information. We also selected to add Path information in the link field and go to a new window as action when opened. The ShortPoint Connect: Basic Tutorial has more detailed instructions on this step.



Step 6. Insert and Publish


Choose to Preview the output like the example below and click the Insert/Update button to complete the steps. Publish your page to finally display your new content.



Search queries are flexible and can be used in different settings. Have fun!


Related articles: