Fives ways to query SharePoint 2013 Search - SharePoint Summit Toronto 2013


Published on

Slides from my talk about the SharePoint 2013 Search API at SharePoint Summit Toronto 2013

Published in: Technology
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Fives ways to query SharePoint 2013 Search - SharePoint Summit Toronto 2013

  1. 1. Five ways to query SharePoint2013 SearchCorey Roth - Infusion
  2. 2. www.sharepointsummit.orgCorey RothFrom Houston, TXPrincipal Architect at Infusion DevelopmentSP2 Apps for SharePoint 2013Three-time Microsoft SharePoint MVPSpecializing in ECM, Search, and apps2
  3. 3. www.sharepointsummit.orgContactE-mail: coreyroth@gmail.comTwitter: @coreyrothBlog: www.dotnetmafia.comApps: www.sp2apps.com3
  4. 4. www.sharepointsummit.orgKey TakeawaysUnderstanding Keyword QueriesQuerying from the ServerQuerying from the ClientChoosing the right API4
  5. 5. www.sharepointsummit.orgBack to BasicsBuilding Queries
  6. 6. the Keyword QueryLanguage (KQL)You’ve been using KQL and may not know itOOTB Search Box uses KQLSupports simple and advanced queriesRecommended query language for SharePoint
  7. 7. www.sharepointsummit.orgQuerying exactly what you wantUse OOTB Managed PropertiesAuthor, Write (ModifiedDate), Path, FileSize, FileExtension, and moreCreate your own managed propertiesMaps to your own site columnsCreated automatically now with owa prefixManaged at Search Schema at SA or Site CollectionRecrawl after mapping properties7
  8. 8. www.sharepointsummit.orgConstructing Keyword QueriesUse wildcard operator (*) to find more resultsi.e.: account* findsaccount, accounts, accountant, and accountingUse >, >=, <, <= operators to query results bydatei.e.: Write>=“1/1/2013”Query by author or title using built-in managedpropertiesi.e.: Author:”Christina Murphy”i.e.: Title:”Budget 2012” 8
  9. 9. www.sharepointsummit.orgHelpful Built-in Managed PropertiesManaged Property DescriptionAuthor Author of documentSite Used to query items by URLTitle Title of page or documentWrite Date document was modifiedIsDocument Set to 1 to return only documentsContentType Query by content type of item9
  10. 10. www.sharepointsummit.orgResult SourcesReplaces scopes (now deprecated)Several included OOTBEx: Documents, Popular, Recently Changed Items10
  11. 11. www.sharepointsummit.orgResult SourcesCan only be queried by Id (Guid) ScopeId KeywordIDs can only be retrieved via managed APIMost OOTB IDs are the same across farms
  12. 12. DemoKeyword Queries12
  13. 13. www.sharepointsummit.orgTesting Queries EasilyNew query testing interface in SharePoint 2013Available in:Script Search Web PartContent Search Web Part13
  14. 14. DemoSearch Web Parts14
  15. 15. www.sharepointsummit.orgQuerying byQuery String
  16. 16. www.sharepointsummit.orgUsing the Query StringUse the k parameter to query searchConstruct keyword query in your own appLet SharePoint handle displaying resultsGreat for:Custom advanced search pagesQuerying from external apps
  17. 17. www.sharepointsummit.orgQuerying from fulltrust code
  18. 18. www.sharepointsummit.orgFull Trust Code – Server Object ModelUse KeywordQuery class for full trust solutionsMust execute directly on SharePoint farmUses same KQL syntax
  19. 19. www.sharepointsummit.orgKeywordQuery ClassSet query with KeywordText propertyUse new SearchExecutor class to queryFilter result tables with Filter()Great for:Managed Code on SharePoint farm19
  20. 20. www.sharepointsummit.orgKeywordQuery - Snippet20
  21. 21. DemoKeywordQuery21
  22. 22. www.sharepointsummit.orgQuerying fromthe ClientManaged CSOM22
  23. 23. www.sharepointsummit.orgManaged CSOMGreat for:Provider hosted appsRemote .NET Application
  24. 24. www.sharepointsummit.orgUsing Managed CSOMUses similar KeywordQuery andSearchExecutor classesRequires a client contextReferencesMicrosoft.SharePoint.Client.dllMicrosoft.SharePoint.Client.Runtime.dllMicrosoft.SharePoint.Client.Search.dll24
  25. 25. www.sharepointsummit.orgManaged CSOM – Code Sample25
  26. 26. DemoManaged CSOM26
  27. 27. www.sharepointsummit.orgQuerying fromthe ClientSearch Client Object Model
  28. 28. www.sharepointsummit.orgSearching with JavaScript CSOMUses similar KeywordQuery andSearchExecutor objectsResults easier to parse than RESTREST is still preferred method
  29. 29. www.sharepointsummit.orgJavaScript CSOM Code Sample29
  30. 30. DemoJavaScript CSOM30
  31. 31. www.sharepointsummit.orgQuerying fromthe ClientREST
  32. 32. www.sharepointsummit.orgRESTNew Search REST API addedAvailable at /_api/search/queryUse querytext parameter to queryEnclose query in single quotesExamplehttp://server/_api/search/query?querytext=’SharePoint’Test directly in the browser
  33. 33. www.sharepointsummit.orgREST + JavaScriptAssemble REST API URLInclude path to REST APIUse KQL in querytext parameterUse $.ajax() to execute queryInclude Headers: { “Accept”: “application/json; odata=verbose” }Retrieve search results from:data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.resultsGreat forApps and Web Parts33
  34. 34. DemoSearch using REST34
  35. 35. DemoREST API + JavaScript35
  36. 36. www.sharepointsummit.orgWhich API?API UseKeywordQuery (Server OM) Full trust solutions on SharePointKeywordQuery (Client OM) Provider hosted appsJavaScript + REST SharePoint-hosted Apps, remote applicationsJavaScript CSOM SharePoint-hosted Apps, Web Parts, etc.Web Services Never36
  37. 37. www.sharepointsummit.orgDeprecated /Obsolete Features
  38. 38. www.sharepointsummit.orgDeprecated / Obsolete FeaturesFAST Query Language (FQL) – deprecatedFull Text SQL Query - obsoleteSearch Web Services - deprecated
  39. 39. www.sharepointsummit.orgKey TakeawaysUnderstanding Keyword QueriesQuerying from the ServerQuerying from the ClientChoosing the right API39
  40. 40. www.sharepointsummit.orgResourcesQuery Search with the KeywordQuery Class Search with the Managed Client ObjectModel Search with JavaScript CSOM Search with JavaScript and REST
  41. 41. Thank you for your attention!This presentation will be available on the TorontoSharePoint Summit web site a few days after the event.
  42. 42. Please rate this session!Fill out the survey and get a chance to win a Surface