12
Writing Code to interact with Enterprise Search Corey Roth Blog: www.dotnetmafia.com Twitter: twitter.com/ coreyroth

Writing Code To Interact With Enterprise Search

Embed Size (px)

DESCRIPTION

Slides from my talk at SharePoint Saturday Ozarks 2009 about writing code to interact with MOSS Enterprise Search.

Citation preview

Page 1: Writing Code To Interact With Enterprise Search

Writing Code to interact with Enterprise Search

Corey RothBlog: www.dotnetmafia.comTwitter: twitter.com/coreyroth

Page 2: Writing Code To Interact With Enterprise Search

Corey Roth

• Consultant for Stonebridge• Worked in Consumer Electronics, Travel, Advertising, and

Energy industries• Currently doing MOSS development specializing in

Enterprise Search• Microsoft Award for Customer Excellence (ACE) Winner• MCTS: MOSS 2007 Configuring• E-mail: [email protected] • Twitter: twitter.com/coreyroth• Blog: www.dotnetmafia.com (mirrored on

sharepointblogs.com)

Page 3: Writing Code To Interact With Enterprise Search

What is Enterprise Search?

• Enterprise Search is one of Microsoft’s current offerings to do search in the Enterprise

• Included in MOSS 2007• Also available as a stand alone product (Search Server 2008 /

Search Server Express)• Allows for indexing and querying of documents from

multiple sources (i.e.: documents, web sites, file shares, Active Directory (people), databases, web services, etc.)

Page 4: Writing Code To Interact With Enterprise Search

Interacting with Search

• Search Center• Query String• RSS• KeywordQuery Class• FullTextSqlQuery Class• Web Service

Page 5: Writing Code To Interact With Enterprise Search

Keyword Query Syntax

• Used to search by Managed Properties• Can specify Scopes (Scope:”MyScope”)• Does not support wildcard search• AND implied between each keyword (i.e.: Color:”Red”

Size:”M” is the same Color=“Red” AND Size=“M”)• OR implied when multiple keywords of the same managed

property used (i.e.: Color:”Red” Color:”Blue” translates to Color=“Red” OR Color=“Blue”)

• Can Specify Content Sources (ContentSource:”My Source”• IsDocument:”1” – Query Documents Only

Page 6: Writing Code To Interact With Enterprise Search

URL Syntax

• Search Center and RSS pages accept queries via the query string

• Uses the keyword syntax specified on the K parameter (i.e.: results.aspx?k=Accounting)

• Can specify scope using the S parameter (i.e.: results.aspx?k=Account&s=Corporate Documents)

• Results can be paged with the start parameter

Page 7: Writing Code To Interact With Enterprise Search

KeywordQuery Class

• SharePoint API class to execute a query using Keyword Syntax

• Returns a ResultsTableCollection object which can be converted to a DataTable

• Can only be used on the SharePoint server• Uses the credentials of the application executing the code

(i.e.: the user who ran a console application, or the application pool account)

• SelectProperties can be used to add custom managed properties. You must add all default properties as well as your own custom properties if this is used.

Page 8: Writing Code To Interact With Enterprise Search

Full Text SQL Syntax

• T-SQL style method of querying Enterprise Search• Can be used to do a wildcard search• Specify columns in SELECT statement

– SELECT Title, Path, Write, Rank,…• Always FROM Scope()• Note syntax when using WHERE with a Scope

– WHERE “Scope” = ‘File Share’• CONTAINS predicate supports wildcard search, FREETEXT

does not• ORDER BY clause can be used for ordering• See Office Server SDK for more information

Page 9: Writing Code To Interact With Enterprise Search

Web Services

• Located on your SharePoint server in the _vti_bin virtual folder

• /_vti_bin/search.asmx – Enterprise Search web service• /vti_bin/spsearch.asmx – WSS3 Search web service• Both use the same syntax• Web Service requires authentication

– Specify using .Credentials property• Requires an input XML string• Query method returns an XML string• QueryEx method returns a DataSet

Page 10: Writing Code To Interact With Enterprise Search

Query Request Schema

• Can use Keyword Query syntax or Full Text SQL Query syntax• QueryText element contains the query

– type=“STRING” – Keyword Query– type=“MSSQLFT” – Full Text SQL Query

• Range / StartAt / Count elements can be used for paging• Properties element can be used to specify custom managed

properties when using Keyword Query syntax• SortByProperties element sorts keyword queries• Note the casing of everything

Page 11: Writing Code To Interact With Enterprise Search

RSS

• Can use the URL syntax with the RSS page at http://<moss-server>/<SearchCenterUrl>/_layouts/srchrss.aspx

• Returns an XML document in RSS format containing search results

• Will not return custom managed properties

Page 12: Writing Code To Interact With Enterprise Search

Questions?

Corey RothBlog: www.dotnetmafia.comTwitter: twitter.com/coreyroth