Search-driven solutions are applications that use a search engine to drive the data access and present results. Microsoft SharePoint 2013 offers developers new ways to extend search to create search-based solutions and Apps. Using Search applications, developers can unite and control data from different site collections and external locations. In this session, I will cover all different ways of querying SharePoint 2013 Search including Client-Side Object Model (CSOM) and REST API. The main goal of the session is to provide strong understanding of search-driven solutions for the attendees and encourage many new ideas for using search to deliver end-user productivity.
Darko Milevski
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Developing Search-driven application in SharePoint 2013
1. SharePoint 2013 Search Based
Solutions
Many MILEVSKI, NEXTSENSE
ways to query SharePoint Search
DARKO
SHAREPOINT AND PROJECT CONFERENCE ADRIATICS 2013
ZAGREB, NOVEMBER 27-28 2013
4. Agenda
• SharePoint 2013 Enterprise Search Overview
• Keyword Query Language Overview
• Developing Server Side Search
• Managed Server Side Object Model
• Demo
• Developing Client Side Search
•
•
•
•
•
•
Managed Client Side Object Model
Demo
JavaScript Client Side Object Model
Demo
REST APIs
Demo
5. What about search?
• Are you using Bing or Google?
• If you are a Dev, how many times have you tried to develop
without using a search engine?
• Was it good experience?
• Are using Search in SharePoint?
• Did you know that you can customize and develop over the
SharePoint Search?
• Do you know about rich Search functionalities like Managed
Properties, Result Sources, Query Rules, Keyword Query
Language, etc., ….
6. SharePoint 2013 Enterprise Search
• Search in 2010 + FAST Search Server
• Single Search
• Server vs. Foundation
• No more Express edition
• Deprecated Features
• SQL Full-Text Query syntax -> Keyword Query Language
• Search Scopes -> Result Sources
• Search Schema
• Managed Properties
7. Search Schema
• Query data according to their metadata
• Crawled and Managed Properties
• OOTB Managed Properties
• Author, Write (Modified Date), Path, FileSize, FileExtension, and more
• Create your own managed properties
•
•
•
•
•
Maps to your own site columns
Crawled properties created automatically with owa_ prefix
Managed at Search Schema at SA or Site Collection
Map Managed property with one or more Crawled properties
Recrawl after mapping properties
8. Result Sources
• Replaces scopes (now deprecated)
• Narrowing results
• One very good explanation what are Result
Sources “imagine that your search index is the
cube in the image on the slide, where you have
four result sources:
• Result source 1: search results can come from the entire
cube.
• Result source 2: search results can come only from the Bs.
• Result source 3: search results can come only from the Cs.
• Result source 4: search results can come only from the Ds.
• Query Transformation
• {searchTerms} path:http://intranet/sales
9. Keyword Query Language (1)
• A KQL query consists of one or more of the following elements:
• Free text-keywords—words or phrases
• Property restrictions
• Free text keywords
•
•
•
•
Word
Phrase
Operators and wildcard
Ex: conference / adria* / …
• Property restrictions
• <Property Name><Property Operator><Property Value>
10. Keyword Query Language (2)
• 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 managed property like author or title:
•
•
•
•
•
i.e.: Author:”Ian Peterson”
i.e.: Title:”Europe 2014”
i.e.: author:Shakesp*
i.e.: title:"Advanced Search“
i.e.: title:"Advanced Sear*“ - wildcard operator (*) in the query, and it is supported only
at the end of the phrase
• i.e.: author:"John Smith" author:"Jane Smith“ = author:"John Smith" OR author:"Jane Smith“
• i.e.: author:"John Smith" filetype:docx = author:"John Smith“ AND filetype:docx
12. Developing SharePoint 2013 Search
solutions
• Server Side or Client Side query execution
• Scenarios in Demos: Searching Invoices
•
•
•
•
•
Narrow invoices by Result Source that search for certain Content Type
Search by term or property restriction
Async query execution
Select Properties and Sorting
Results limit and Paging
13. Server Side Managed OM Querying
• Executed directly on the server
• Used for full trust code
• Use KeywordQuery class with SearchExecutor class
• Use KQL for query text
• Iterate ResultsTable of type RelevantResults
15. Managed Client Side Object Model (CSOM)
• SharePoint Managed Client Side Object Model classes
• Very similar classes and code like server side managed object
model
• Familiar programming from CSOM back in SP2010
• Use ExecuteQuery
• Select Properties
• Selecting Custom Managed Properties
• Sort List
17. JavaScript CSOM Search
• JavaScript in SharePoint 2013 is derived from the .NET server
programming model, and the programming capabilities defined
here reflect those found in the original .NET server source.
• Reference .js files
• <script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
• <script type="text/javascript" src="/_layouts/15/sp.js"></script>
• <script type="text/javascript" src="/_layouts/15/sp.search.js"></script>
• Use ExecuteQueryAsync(OnSucess,OnFail)
• Using Result Source
• Query Only Documents of certain Content Type
• Sorting
• Search Paging
19. SharePoint 2013 REST APIs
• SharePoint 2013 adds the ability to remotely interact with
SharePoint sites by using REST
• Construct a RESTful HTTP request, using the Open Data
Protocol (OData) standard
• Response is either Atom or JSON
20. Search REST APIs
• [site]/_api/[name of SP API]/[name of operation]?[parameters]
• http://intranet/_api/search/query?querytext='invoice'
Operation
Sample REST URL
Use a search Result
Source (i.e. a scope)
/_api/search/query?querytext='search term'&sourceid='B09A7990-05EA-4AF981EF-EDFAB16C4E31'
Specify a start row
(i.e. in paging)
Specify a number of
results to return
Specify particular
(managed) properties
to return
/_api/search/query?querytext='search term'&startrow=11
/_api/search/query?querytext='search term'&startrow=11&rowlimit=10
/_api/search/query?querytext='search
term'&selectproperties='Author,Path,Title,Url'
21. REST search calls
• Create HttpWebRequest
• Await for HttpWebResponse and the Load ResponseSretam
• Result parsing
• OAuth authentication for remote apps
23. Why to use Search in solutions
• Site Collections consolidation
• Security Trimming (Custom Security Trimming)
• Fast query results
• High Availability and Load Balancing
Pros
Cons
•
•
•
•
•
• Time from data entry till crawl
• Additional space on disk
Search Features
Programmability possibilities
Fast results
Use refiners
Querying Index on disk, not in SQL