SHAREPOINT AND PROJECT CONFERENCE ADRIATICS 2013
ZAGREB, NOVEMBER 27-28 2013
SharePoint 2013 Search Based SolutionsMany ways to query SharePoint SearchDARKO MILEVSKI, NEXTSENSE
sponsors
http://darkomilevski.info
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
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., ….
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
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
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
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>
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
SHAREPOINT SEARCH CENTER
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
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
SERVER-SIDE OM SEARCH
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
MANAGED CLIENT-SIDE OBJECT MODEL SEARCH
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
CLIENT-SIDE SEARCH FROM JAVASCRIPT
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
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-4AF9-81EF-EDFAB16C4E31'
Specify a start row (i.e. in paging)
/_api/search/query?querytext='search term'&startrow=11
Specify a number of results to return
/_api/search/query?querytext='search term'&startrow=11&rowlimit=10
Specify particular (managed) properties to return
/_api/search/query?querytext='search term'&selectproperties='Author,Path,Title,Url'
REST search calls• Create HttpWebRequest • Await for HttpWebResponse and the Load
ResponseSretam• Result parsing• OAuth authentication for remote apps
REST
Why to use Search in solutions• Site Collections consolidation• Security Trimming (Custom Security Trimming)• Fast query results• High Availability and Load Balancing
Pros Cons
• Search Features• Programmability possibilities• Fast results• Use refiners• Querying Index on disk, not in
SQL
• Time from data entry till crawl• Additional space on disk
questions?
HTTP://DARKOMILEVSKI.INFO
@DARKOMILEVSKI
i
thank you.
SHAREPOINT AND PROJECT CONFERENCE ADRIATICS 2013
ZAGREB, NOVEMBER 27-28 2013