Minneapolis Office Developer Interest Group (MODIG) Mike Hodnick April 22, 2008 The MOSS Search API
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)sharepointmn.com
MODIG T-Shirts true&number=% true&number=%
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
scenario
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 Query TypeFormatExample Single keyword[keyword]Music Multiple keyword[keyword1] [keyword2]Music Guitar Keyword inclusion/exclusion+[keyword to include] –[keyword to exclude] +music –guitar Managed Property match[property]:[value]Artist:Helmet
Default ResultTypes Value ResultTypes property defaults to “None” To get results, you must set this property every time – Set to “RelevantResults” % of the time
keyword query demo
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 SELECT Title, Author, Path, Rank FROM Scope() WHERE FREETEXT(DEFAULTPROPERTIES, ‘music guitar’) ORDER BY RANK DESC WHERE ConditionFormat FREETEXTFREETEXT(Property, ‘[keywords]’) CONTAINSCONTAINS(Property, ‘[keywords]’) Exact Property Match[property] = [value] Scope“Scope = ‘[scope name]’”
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
full text query demo
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 metadata demo
Search Web Service Relevant methods MethodReturns Query(string)Returns string xml of results QueryEx(string)Returns DataSet of results GetSearchMetadata()Returns DataSet of Scopes and ManagedProperties
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 Schema
search web service demo
Web Service vs. API Quirk StartRow – API – index starts at zero – Web Service – index starts at one
Search Llama asks: “How many values does a Boolean have?”
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
SPSearchBench UI demo
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(“ 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(“ 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();
SPSearchBench API demo
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);
SPSearchBench FullTextBuilder demo
Resources Writing relevant Full Text queries: Query Packet XML Schema: SharePoint Search Bench: Microsoft.Office.Server.Search.Query Namespace: us/library/microsoft.office.server.search.query.aspx 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