390 likes | 489 Views
Minneapolis Office Developer Interest Group (MODIG). April 22, 2008 The MOSS Search API. Mike Hodnick http://www.kindohm.com mike.hodnick@gmail.com. Agenda. Introduction Feature Presentation MOSS Search API Topic Discussion Random Stuff. User Group Goals.
E N D
Minneapolis Office Developer Interest Group (MODIG) April 22, 2008The MOSS Search API Mike Hodnick http://www.kindohm.com mike.hodnick@gmail.com
Agenda • Introduction • Feature Presentation • MOSS Search API • Topic Discussion • Random Stuff
User Group Goals • Provide a community for SharePoint Developers • Share development knowledge • Exchange tips/tricks/other/free pizza
User Group Format • Presentations • 1-2 per meeting • Hopefully Demo Heavy • Highlights of Nifty Things • QA/Discussion/Random Things
Call for Cool Stuff • Created something cool? • Send Screenshots or Videos • We’ll try to feature some items here
sharepointmn.com/modig • Our current home • Meeting information • Usually has the right time • Previous presentations • Running on SharePoint • As required by SharePoint User Group Law
Upcoming • Next Meeting • May ?? (5:30pm) • Topic: Web Part Development • MNSPUG • May 14 (9:00am – Noon) • Topic : TBD (sharepointmn.com)
MODIG T-Shirts • http://www.cafepress.com/cp/customize/product.aspx?clear=true&number=%20253292961
Let’s dig in to the Search API… • Very, very, very brief overview of MOSS Search features • Scenario • Keyword searches • Full Text Searches • Search Metadata • Search Web Service • SharePoint Search Bench I like to search
Very, very, very brief overview of MOSS Search • Content Sources • Crawled Properties • Managed Properties • Scopes • Keyword Search • Advanced Search • “full text search” • Search Web Parts
What out-of-the-box MOSS Search CAN’T do… • Drive app navigation • Complex searches • Execute searches in another app • Custom UI layout/logic …and I thought that MOSS Search was so cool….
Keyword Searches with the MOSS Search API • Microsoft.Office.Server.Search.Query.KeywordQuery • Inherits from Query base class • Constructed with an SPSite (or ServerContext) • Properties of importance • QueryText (keywords) • StartRow • RowLimit • ResultTypes • SelectProperties (columns) • SortList (columns)
Keyword Searches with the MOSS Search API • Returns a ResultTableCollection • Contains ResultTables (ResultTable implements IDataReader) • Query Syntax
Default ResultTypes Value • ResultTypes property defaults to “None” • To get results, you must set this property every time • Set to “RelevantResults” 99.999% of the time
Full Text Searches with the MOSS Search API • Microsoft.Office.Server.Search.Query.FullTextSqlQuery • Inherits from Query base class (just like KeywordQuery) • Constructed with an SPSite (or ServerContext) • Properties of importance • QueryText • StartRow • RowLimit • ResultTypes • Remember to set this value!
Full Text Searches with the MOSS Search API • Returns a ResultTableCollection • SQL Full Text style syntax http://msdn2.microsoft.com/en-us/library/bb219479.aspx SELECT Title, Author, Path, Rank FROM Scope() WHERE FREETEXT(DEFAULTPROPERTIES, ‘music guitar’) ORDER BY RANK DESC
Specifying a Full Text Search Scope • “FROM Scope()” has nothing to do with search scopes • “FROM Scope()” cannot change • To specify a scope, use a scope constraint in the WHERE clause SELECT Title, Author, Path, Rank FROM Scope() WHERE FREETEXT(DEFAULTPROPERTIES, ‘music guitar’)AND “Scope = ‘MusicLibrary’” ORDER BY RANK DESC
Search Metadata • Managed Properties • Microsoft.Office.Server.Search.Query.Query class • Query.GetProperties() • PropertyInformation class • Scopes • Microsoft.Office.Server.Search.Administration.Scopes class • Scopes.AllScopes property • Scope class
Search Web Service • http://server/_vti_bin/Search.asmx • Relevant methods
Search Web Service • Query() and QueryEx() methods receive a string parameter • QueryPacket xml • Specify search type (Keyword vs. Full Text) • Specify properties found in FullTextSqlQuery and KeywordQuery classes • QueryPacket Schemahttp://msdn2.microsoft.com/en-us/library/ms563775.aspx
Web Service vs. API Quirk • StartRow • API – index starts at zero • Web Service – index starts at one
Difficulties with the MOSS Search API • Differences between Keyword and Full Text • On server vs. off server • Full Text query syntax is ugly • Pain to set up and debug searches • Trying out a search scope • Trying out a managed property
SharePoint Search Bench • Open Source (CodePlex) • Testing ground for searches • Uses object model or web service • Targets Keyword or Full Text • SPSearch Bench API • Homogeneous search calls • Full Text query generator • http://codeplex.com/spsearchbench
SharePoint Search Bench API • Search class • Context Uri • SearchType • ApiSource • SearchText • Credentials (for web service calls)
SharePoint SearchBench API • Object Model, Keyword search Search search = new Search(); search.ContextUri = new Uri(“http://server”); search.ApiSource = ApiSource.ObjectModel; search.SearchType = SearchTypes.Keyword; search.SearchText = new SearchText(“music”); DataSet results = search.Execute();
SharePoint SearchBench API • Web Service, Full Text search Search search = new Search(); search.ContextUri = new Uri(“http://server/_vti_bin/search.asmx”); search.ApiSource = ApiSource.Service; search.SearchType = SearchTypes.FullText; search.SearchText = new SearchText(“Select Title ” + “, Author, Rank From Scope() Where “ + “FREETEXT(DEFAULTPROPERTIES, ‘music’) “ + “Order By Rank”); Search.Credentials = new NetworkCredential(…); DataSet results = search.Execute();
SharePoint Search Bench Full Text Query Generation • FullTextBuilder class • Select (adds columns) • Where (adds a constraint) • Order By • Constraint class • Freetext • Contains • Property equality comparison • .Or(Constraint) • .And(Constraint)
FullTextBuilder Examples string fields = “Author, Title, Rank”; string keywords = “music”; FullTextBuilder output = FullTextBuilder.Select(fields).Where( Condition.FreeText(keywords)); string fields = “Author, Title, Rank”; string keywords = “music”; Condition c1 = Condition.FreeText(keywords); Condition c2 = Condition.Contains(“Author”, “John”); c1.And(c2); FullTextBuilder output = FullTextBuilder.Select(fields).Where(c1);
Resources • Writing relevant Full Text queries:http://msdn2.microsoft.com/en-us/library/bb219479.aspx • Query Packet XML Schema:http://msdn2.microsoft.com/en-us/library/ms563775.aspx • SharePoint Search Bench:http://codeplex.com/SPSearchBench • Microsoft.Office.Server.Search.Query Namespace:http://msdn2.microsoft.com/en-us/library/microsoft.office.server.search.query.aspx
It looks like you’ve reached the end. Would you like to… • Go home • Ask a question • Wake up • Don’t show this tip again