Upload
mikael-svenson
View
204
Download
4
Embed Size (px)
DESCRIPTION
Small presentation on the client search API's available which I did for my team at DNVGL.
Citation preview
DNV GL © 2014
DRAFT
August 22 2014 SAFER, SMARTER, GREENER1 DNV GL © 2014
DRAFT
August 22 2014Mikael Svenson
SOFTWARE
SharePoint – Client Search API’s
Grokking search via CSOM/JSOM and REST
DNV GL © 2014
DRAFT
August 22 20142
CSOM/JSOM
Client Side Object Model
JavaScript object model
http://msdn.microsoft.com/en-us/library/office/dn423226(v=office.15).aspx
DNV GL © 2014
DRAFT
August 22 20143
REST
http://msdn.microsoft.com/en-us/library/office/jj163876(v=office.15).aspx
Wrapper functions will help: http://www.skylinetechnologies.com/Blog/Article/2480/Using-the-SharePoint-2013-Search-REST-API.aspx
jQuery.ajax({url: webUrl + "/_api/search/query?querytext='SharePoint'&rowlimit=10",type: "GET",headers: { "Accept": "application/json;odata=verbose" },success: function (data) {
var hitCount = data.d.query.PrimaryQueryResult.RelevantResults.TotalRows;var hitCountwithDuplicates = data.d.query.PrimaryQueryResult.RelevantResults.TotalRowsIncludingDuplicates;var results = data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results;
$.each(results, function () { $.each(this.Cells.results, function () {
var propertyName = this.Key;var propertyValue = this.Value;
}); });
/* get result blocks */if (data.d.query.SecondaryQueryResults != null) {
for (var i = 0; i < data.d.query.SecondaryQueryResults.results.length; i++) {var resultBlock = data.d.query.SecondaryQueryResults.results[i];$.each(resultBlock.RelevantResults.Table.Rows.results, function () {
$.each(this.Cells.results, function () { var propertyName = this.Key;var propertyValue = this.Value;
}); });
}}
},error: function (data) {}
});
DNV GL © 2014
DRAFT
August 22 20144
SharePoint 2013 Search Query Tool
https://sp2013searchtool.codeplex.com/
DNV GL © 2014
DRAFT
August 22 20145
Fiddler or similar to explore the JSON data
DNV GL © 2014
DRAFT
August 22 20146
Benefits of using CSOM
You can batch queries, optimizing query execution
DNV GL © 2014
DRAFT
August 22 20147
Batching with REST
Can be achieved using query rules and result blocks, but will limit the number of results per type to 10
That said, using a query rule with result blocks makes updates a lot easier if you need to change the search queries
– Example: Intranet front page which shows
– Top 4 articles
– Top X blog posts
– Latest user documents
– etc
DNV GL © 2014
DRAFT
August 22 20148
Refiners with REST
Use the query tool
Specify the refiners you want returned
Pick values from the Refinement results table
Use the Refinement Token valueand(ContentType:ǂǂ746578742f68746d6c3b20636861727365743d7574662d38,FileType:ǂǂ68746d6c)
The value is hex encodedand(ContentType:"text/html; charset=utf-8",FileType:html)
DNV GL © 2014
DRAFT
August 22 20149
Refiners in CSOM
Similar to REST, set the .Refiners property of the KeywordQuery object
Set the RefinementFilters property to add filtersRefinementFilters.Add(<filter>)
http://techmikael.blogspot.no/2013/07/working-with-refiners-in-csomsharepoint.html
DNV GL © 2014
DRAFT
August 22 201410
Anonymous
Requires some configuration
http://msdn.microsoft.com/en-us/library/office/jj163876(v=office.15).aspx#bk_AnonymousREST
Waldek Mastykarz is your man when it comes to anonymous and WCM
http://blog.mastykarz.nl/configuring-sharepoint-2013-search-rest-api-anonymous-users/
http://blog.mastykarz.nl/inconvenient-search-rest-api-anonymous-users/
http://blog.mastykarz.nl/debugging-setting-properties-anonymous-search-rest-queries/
DNV GL © 2014
DRAFT
August 22 201411
SAFER, SMARTER, GREENER
www.dnvgl.com
Questions?