Should I use the SharePoint Search API?
I was recently tasked with creating an effective means of tracking/reporting on project tasks in SharePoint Online. Based on the requirements I setup everything “out of the box” to show what could be accomplished by using simply using Content Types, Site Columns, Managed Properties and Search. The client liked the outcome but didn’t necessarily love it. Search API to the rescue.
If you are not familiar with the SharePoint Search REST API click the link here to find out more but as the name implies it essentially allows developers to interact with SharePoint’s Search via REST. There are definitely times where we will want to stick to making direct REST calls to perform GET operations but using the Search API we can eliminate a lot of REST calls and resource usage as we can get all data pertaining to our query from a single call against the Search API vs. looping through sites/lists to find the information we need.
Of course the Search API does have a few downsides:
- New/edited items are not going to be displayed in your results until SharePoint has crawled the content.
- In SharePoint Online it seems to take between 5 – 10 minutes depending on the amount of content being crawled whereas SharePoint On-Premises (2013 and above) the time frame is based on your farms incremental crawl schedule.
- In order to take full advantage of the Search API you need to establish a solid baseline for your content including but not limited to: Content Types, Site Columns, Managed Properties and Enterprise Search.
- This is necessary to make sure you can easily filter and grab the data you are looking for but I consider this part of a normal SharePoint project implementation.
- Whomever is managing the SharePoint environment needs to ensure that when new content is added it is done with the appropriate Content Type/s in place.
- It does no one any good to create a solution that isn’t going to be utilized.
If you would like to delve further into the SharePoint Search API I would highly suggest taking a look at the SharePoint Search Query Tool on CodePlex. It will allow you to connect to your environment and test out queries to your hearts content.