Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Fives ways to query SharePoint 2013 Search - SharePoint Summit Toronto 2013
1. Five ways to query SharePoint
2013 Search
Corey Roth - Infusion
2. www.sharepointsummit.org
Corey Roth
From Houston, TX
Principal Architect at Infusion Development
SP2 Apps for SharePoint 2013
Three-time Microsoft SharePoint MVP
Specializing in ECM, Search, and apps
2
6. www.sharepointsummit.org
(Re)introducing the Keyword Query
Language (KQL)
You’ve been using KQL and may not know it
OOTB Search Box uses KQL
Supports simple and advanced queries
Recommended query language for SharePoint
7. www.sharepointsummit.org
Querying exactly what you want
Use OOTB Managed Properties
Author, Write (Modified Date), Path, FileSize,
FileExtension, and more
Create your own managed properties
Maps to your own site columns
Created automatically now with owa prefix
Managed at Search Schema at SA or Site Collection
Recrawl after mapping properties
7
8. www.sharepointsummit.org
Constructing Keyword Queries
Use wildcard operator (*) to find more results
i.e.: account* finds account, accounts, accountant,
and accounting
Use >, >=, <, <= operators to query results by
date
i.e.: Write>=“1/1/2013”
Query by author or title using built-in managed
properties
i.e.: Author:”Christina Murphy”
i.e.: Title:”Budget 2012” 8
9. www.sharepointsummit.org
Helpful Built-in Managed Properties
Managed Property Description
Author Author of document
Site Used to query items by URL
Title Title of page or document
Write Date document was modified
IsDocument Set to 1 to return only documents
ContentType Query by content type of item
9
11. www.sharepointsummit.org
Result Sources
Can only be queried by Id (Guid)
ScopeId Keyword
IDs can only be retrieved via managed API
Most OOTB IDs are the same across farms
http://tinyurl.com/b5bflbl
11
16. www.sharepointsummit.org
Using the Query String
Use the k parameter to query search
Construct keyword query in your own app
Let SharePoint handle displaying results
Great for:
Custom advanced search pages
Querying from external apps
18. www.sharepointsummit.org
Full Trust Code – Server Object Model
Use KeywordQuery class for full trust solutions
Must execute directly on SharePoint farm
Uses same KQL syntax
24. www.sharepointsummit.org
Using Managed CSOM
Uses similar KeywordQuery and
SearchExecutor classes
Requires a client context
References
Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll
Microsoft.SharePoint.Client.Search.dll
24
32. www.sharepointsummit.org
REST
New Search REST API added
Available at /_api/search/query
Use querytext parameter to query
Enclose query in single quotes
Example
http://server/_api/search/query?querytext=’SharePoint’
Test directly in the browser
33. www.sharepointsummit.org
REST + JavaScript
Assemble REST API URL
Include path to REST API
Use KQL in querytext parameter
Use $.ajax() to execute query
Include Headers: { “Accept”: “application/json; odata=verbose” }
Retrieve search results from:
data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results
Great for
Apps and Web Parts
33
36. www.sharepointsummit.org
Which API?
API Use
KeywordQuery (Server OM) Full trust solutions on SharePoint
KeywordQuery (Client OM) Provider hosted apps
JavaScript + REST SharePoint-hosted Apps, remote applications
JavaScript CSOM SharePoint-hosted Apps, Web Parts, etc.
Web Services Never
36
40. www.sharepointsummit.org
Resources
Query Search with the KeywordQuery Class
http://tinyurl.com/c9q76le
Query Search with the Managed Client Object
Model
http://tinyurl.com/ckxhm8g
Querying Search with JavaScript CSOM
http://tinyurl.com/d685a5g
Querying Search with JavaScript and REST
http://tinyurl.com/dyhwvje
40
41. Thank you for your attention!
This presentation will be available on the Toronto
SharePoint Summit web site a few days after the event.
42. Please rate this session!
Fill out the survey and get a chance to win a Surface