11
DNV GL © 2014 DRAFT August 22 2014 SAFER, SMARTER, GREENER DNV GL © 2014 DRAFT August 22 2014 Mikael Svenson SOFTWARE SharePoint – Client Search API’s 1 Grokking search via CSOM/JSOM and REST

Share point – client search api’s

Embed Size (px)

DESCRIPTION

Small presentation on the client search API's available which I did for my team at DNVGL.

Citation preview

Page 1: Share point – client search api’s

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

Page 2: Share point – client search api’s

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

Page 3: Share point – client search api’s

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) {}

});

Page 4: Share point – client search api’s

DNV GL © 2014

DRAFT

August 22 20144

SharePoint 2013 Search Query Tool

https://sp2013searchtool.codeplex.com/

Page 5: Share point – client search api’s

DNV GL © 2014

DRAFT

August 22 20145

Fiddler or similar to explore the JSON data

Page 6: Share point – client search api’s

DNV GL © 2014

DRAFT

August 22 20146

Benefits of using CSOM

You can batch queries, optimizing query execution

Page 7: Share point – client search api’s

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

Page 8: Share point – client search api’s

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)

Page 9: Share point – client search api’s

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

Page 11: Share point – client search api’s

DNV GL © 2014

DRAFT

August 22 201411

SAFER, SMARTER, GREENER

www.dnvgl.com

Questions?