您的位置:首页 > 其它

Customize the SharePoint 2013 search experience with a Content Enrichment web service

2013-12-12 21:39 573 查看
Didyoueverwishyouhadmorecontroloverhowyourcontentisindexedandpresentedassearchresults?InSharePoint2013,youhavetheoptiontoaddacalloutfromthecontentprocessingcomponenttoyourownwebservicesoyoucanmanipulatethecontentbeforeitgetsindexed.Thismakesitpossibletocreatenewwaystopivotoverthesearchresults.Herearesomeexamplesofwhatyoucoulddo:

Normalizethecaseforrefinablemanagedpropertiestomaketherefinerslookcleaner.

Createnewrefinersbyextractingdatafromunstructuredtext.

Calculatenewrefinersbasedonmanagedpropertyvalues.

ThisfeatureissimilartothepipelineextensibilitystageinFASTSearchforSharePoint2010,buttherearesomedifferences:

InFASTSearchforSharePoint2010,thecodewasexecutedinasandbox,whereasSharePoint2013letsyouputthecodeinawebservice.Thisreducestheoverheadandletsyourunthecodeanywhere.
Thewebserviceprocessesandreturnsmanagedproperties,notcrawledproperties.Managedpropertiescorrespondtowhatactuallygetsindexedandarethereforeeasiertomanage.
Youcandefineatriggertolimitthesetofitemsthatareprocessedbythewebservice.Thiswilloptimizetheoverallperformanceifyouonlywanttoprocessasubsetofthecontent.
Inthisblogpost,we’llgothroughabasicscenariowherewehavealistofpopularmovies.Themetadataisnotconsistentwithregardstocasing,andthereislimitedmetadatatouseforpivotingoverthesearchresults.

Wewillwalkyouthroughhowyoucangofromthissearchexperience…





…totheonebelow,withoutmodifyingtheoriginalcontent.NoticethatthelistTitleandtheDirectorrefinerhavebeennormalizedtotitlecase,andthatthereisnowanewrefinercalled“YearsSinceRelease”.





Tounderstandwhat’spossibletoachievewiththecontentenrichmentwebservice,itisimportanttohaveagoodconceptualunderstandingofwhatgoesonduringcontentprocessing,andwherethewebservicecallouttakesplaceinrelationtoeverythingelse.

Thisblogpostgoesintodetailonwhathappensduringcontentprocessingandhowthewebservicecalloutfitsintotheoverallpicture.We’llthenshowyouhowtocreateasamplelistandcreateawebservicethatmanipulatesthedatainthelisttocreatenewsearchrefiners.

Whathappensduringcontentprocessing

ThecontentprocessingcomponentreceivescrawledPropertiesfromthecrawlercomponentandoutputsmanagedpropertiestotheindexcomponent,butwhatgoesonin-between?

Insidethecontentprocessingcomponent,thereare“flows”thatprocessonecrawleditematatime.Whenanitemhasbeenindexed,acallbackissentbacktothecrawlertoacknowledgewhethertheitemissearchableornot.ThesuccessorfailureofanitemcanthenbeinspectedbytheadministratorintheSearchAdministration(navigatetoCrawlLogandthentoErrorBreakdown).

Theflowisthespecificationforhowthecrawleditemshouldbeprocessedtoprepareitforindexing.Theflowhasbranchesthathandledifferentoperations,likeinserts,deletes,andpartialupdates.Thebranchesthathandledeletionsandpartialupdatesdonothaveawebservicecallout.





Themainbranchoftheflowhandlesinsertionofnewandupdateddocumentsandcontainsdifferentstagesthatextractinformationfromthecrawleditemandcreatemanagedproperties.

Atthestartoftheflow,newcrawledpropertiesareregisteredintheSearchadministrationdatabase.ThisisfollowedbyastagethatparsesbinarydocumentformatssuchasOfficeorPDFdocuments.Duringdocumentparsing,thereisacallouttoIFiltersforcertaindocumenttypes.Documentparsingaddsnewcrawledpropertiesfromtheparsers.Acrawledpropertycannotbemappedtoamanagedpropertyuntilithasbeenregisteredintheadmindatabase.Afterallcrawledpropertieshavebeencollected,anotherstagemapscrawledpropertiestomanagedpropertiesaccordingtotheSearchschema.Allstagesafterthisoneworkonmanagedpropertiesonly.

Thenextstageprocessessecuritydescriptorsandconvertsthemtotheinternalformatusedbytheindexcomponent.AutomaticLanguagedetectiontakesplacebeforethewebservicecallout,andsetsthevalueofthelanguagesmanagedproperty.Afterthewebservicecallout,thereisprocessingrelatedtopeoplesearchthatcreatesphoneticnamevariations.

Next,wordbreakingisdoneonallmanagedpropertiesthataremarkedforwordbreakingintheSearchschema.Thisisfollowedbyentityextractionandotherstages,likemetadataextractionanddocumentsummarization.LinksthatarediscoveredwithinthedocumentarewrittentotheAnalyticsreportingdatabaseforlaterprocessing.Finally,themanagedpropertiesareindexed.

Tosummarize,itisimportanttonotethatthewebservicecalloutcanonlyreadmanagedproperties.Anycrawledpropertyvaluethatthewebserviceneedsasinputmustfirstbemappedtoamanagedproperty.ThewebservicecalloutcanonlyAccessmanagedpropertiesthatexistbeforethewebservicecallout,andnotmanagedpropertiesthataresetfurtherdownintheflow.Thewebservicecalloutcanpassmanagedpropertiesbacktotheflow,butonlyiftheyareapartoftheSearchschema.

The“PopularMovie”webservice

Let’sgothroughafullscenariothatcoverseverythingfromcreatingthecontentandthewebservice,tocustomizingthesearchexperiencewithnewrefiners.Thefirstthingwe’lldoistocreatealistofsomeall-timepopularmovieswithinformationaboutthereleaseyear,director,andwhetherthefilmreceivedanOscar.We’llthencreateawebservicethatdoesacoupleofthingstoimprovethesearchexperience:

CalculatestheyearssincethemoviewasreleasedbylookingattheReleaseYearmanagedproperty

NormalizestheDirectormanagedpropertytotitlecase

Createsatimestampforwhenthewebserviceprocessedtheitem

Thesearethestepsthatwe’llwalkyouthrough:

Createasamplelist

Createthewebservice

Configurecrawledandmanagedproperties

Crawlandsearchthecontent

Createasamplelist

OpentheSharePoint2013ManagementShellasadministrator.MakesurethattheuseryouareloggedonasisamemberoftheWSS_ADMIN_WG
group,becauseweneedwriteaccesstoSharePointresources.

Typethefollowingcommandstocreateanewlist:

$SPWeb=Get-SPWebhttp://myserver
$CustomListTemplate=$SPWeb.ListTemplates|where{$_.Name-eq"CustomList"}

$listUrl="PopularMovies"

$description="Alistofpopularmovies"

$lists=$SPWeb.Lists

$lists.Add($listUrl,$description,$CustomListTemplate)

Younowcanbrowsetoyourlistbygoingtohttp://myserver/lists/PopularMovies

$list=$lists|where{$_.Title-eq"PopularMovies"}
Belowarethecommandstocreatethedifferentfields(columns)inthelist.

$spFieldType=[Microsoft.SharePoint.SPFieldType]::Text$list.Fields.Add("Director",$spFieldType,$false)$spFieldType=[Microsoft.SharePoint.SPFieldType]::Integer$list.Fields.Add("ReleaseYear",$spFieldType,$false)$spFieldType=[Microsoft.SharePoint.SPFieldType]::Boolean$list.Fields.Add("WonOscar",$spFieldType,$false)$spFieldType=[Microsoft.SharePoint.SPFieldType]::DateTime$list.Fields.Add("ReleaseDate",$spFieldType,$false)$list.Update()
Ifyouwantthenewlycreatedfieldstobepartofthedefaultlistview,youcanaddthemtothedefaultview.ThisisanexampleofhowwediditfortheDirectorfield.

$spView=$spWeb.GetViewFromUrl("/Lists/PopularMovies/Allitems.aspx”)$spfield=$list.Fields["Director"]
$spview.ViewFields.Add($spfield)

$spview.Update()

Nowwearereadytostartpopulatingthelist.Eachlistitemrepresentsamovie,andwestartoffwith“PulpFiction”.

$spListItem1=$list.AddItem()$spListItem1["Title"]="PulpFiction"
$spListItem1["ReleaseYear"]=1994
$spListItem1["Director"]="QuentinTarantino"
$date=Get-Date"10/21/1994"
$spListItem1["ReleaseDate"]=$date
$spListItem1.Update()


Thescreenshotbelowshowsthelistafterwehaveaddedafewmoremovies:





TheTitleandtheDirectorhavebeenaddedwithinconsistentcasingtoshowhowwecanfixthisautomaticallyinthewebservice.

Createthewebservice

Nowlet’screateawebservicethatcanreadthelistwecreated,andcreatesomenewmanagedpropertiesthatwecanuseasrefiners.

usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingMicrosoft.Office.Server.Search.ContentProcessingEnrichment;usingMicrosoft.Office.Server.Search.ContentProcessingEnrichment.PropertyTypes;usingSystem.Globalization;usingSystem.Threading;namespacePopularMovieService{publicclassPopularMovieService:IContentProcessingEnrichmentService{//Definevariablestoholdthemanagedpropertiesthatthe//webservicewillpopulate.privateProperty<Int64>NewIntegerMP=newProperty<Int64>();privateProperty<DateTime>NewDateTimeMP=newProperty<DateTime>();privatereadonlyProcessedItemprocessedItemHolder=
newProcessedItem{ItemProperties=newList<AbstractProperty>()};publicProcessedItemProcessItem(Itemitem){//Iterateoverallmanagedpropertiespassedtothewebservice.foreach(varpropertyinitem.ItemProperties){vars=propertyasProperty;if(s!=null){//Thevalueofthenewtextmanagedpropertyisthe//stringintitlecase.CultureInfocultureInfo=Thread.CurrentThread.CurrentCulture;TextInfotextInfo=cultureInfo.TextInfo;stringnormalizedString=textInfo.ToTitleCase(s.Value.ToLower());s.Value=normalizedString;processedItemHolder.ItemProperties.Add(s);}varl=propertyasProperty;if(l!=null){//Thevalueofthenewintegermanagedpropertythe//numberofyearssincethereleasedate.intCurrentYear=DateTime.Now.Year;NewIntegerMP.Name="YearsSinceRelease";NewIntegerMP.Value=CurrentYear-l.Value;processedItemHolder.ItemProperties.Add(NewIntegerMP);}//Setthetimeforwhenthepropertieswhereaddedbythe//webservice.NewDateTimeMP.Name="ModifiedByWebService";NewDateTimeMP.Value=DateTime.Now;processedItemHolder.ItemProperties.Add(NewDateTimeMP);}returnprocessedItemHolder;}}}

Configurecrawledandmanagedproperties

WhenyoucreatealistinSharePoint,thecolumnnamesarepickedupbythecrawlerascrawledproperties.Thenameofthecrawledpropertyisthesameasthelistcolumnname,butwith“ows_”infront,so“ReleaseYear”becomes“ows_ReleaseYear”.ThereareseveralwaysanewcrawledpropertycanberegisteredaspartoftheSearchschema:bycrawlingorbyaddingitprogrammatically,forexample,throughaWindowsPowerShellcmdlet.Inthisblogpost,westicktoWindowsPowerShellwheneverpossible.

$cp=New-SPEnterpriseSearchMetadataCrawledProperty-SearchApplication$ssa-CategorySharePoint-Name"ows_ReleaseYear"-IsNameEnum$false-PropSet"00130329-0000-0130-c000-000000131346"–VariantType0

$mp=New-SPEnterpriseSearchMetadataManagedProperty-SearchApplication$ssa-Name"ReleaseYear"-Type2-Queryable$True

$mp.Refinable=$True

$mp.Update()

New-SPEnterpriseSearchMetadataMapping-SearchApplication$ssa-ManagedProperty$mp-CrawledProperty$cp

Weneedtodothesamefortheothermanagedproperties(Director,WonOscar,andReleaseDate).Foreasyreference,thesearethetypestousewhencreatingthemanagedproperty:Text=1,Integer=2,DateTime=4,andBoolean(YesNo)=5.

Wealsoneedtocreatethenewmanagedpropertiesthatthewebservicepopulates:

$mp=New-SPEnterpriseSearchMetadataManagedProperty-SearchApplication$ssa–Name"ModifiedByWebService"–Type4–Queryable$True

$mp.Refinable=$True

$mp.Update()

$mp=New-SPEnterpriseSearchMetadataManagedProperty-SearchApplication$ssa–Name"YearsSinceRelease"–Type2–Queryable$True

$mp.Refinable=$True

$mp.Update

Crawlandsearchthecontent

Beforestartingthecrawl,wemustfirstenableandconfigurethewebservicecallout.ThisisdoneinWindowsPowerShell.

$config=New-SPEnterpriseSearchContentEnrichmentConfiguration

$config.Endpoint="http://localhost:817/PopularMovieService.svc"

$config.InputProperties="Director","Title","ReleaseYear"

$config.OutputProperties="Director","Title","YearsSinceRelease","ModifiedByWebService"

Set-SPEnterpriseSearchContentEnrichmentConfiguration-SearchApplication$ssa-ContentEnrichmentConfiguration$config

Wearenowreadytokickoffafullcrawlofthelistwecreated,andobservewhatgetssenttothewebservice.

Ifyoudon’talreadyhaveanEnterpriseSearchCenter,youcancreateoneusingthesitecollectiontemplatecalled“EnterpriseSearchCenter”undertheEnterprisetab.





Tomakeiteasiertoseetheeffectofthewebservice,we’vecustomizedthesearchcentertoshowrefinersforthemanagedPropertiesthatthewebservicemodifies.

Toshowthenewrefiners,wewilledittheresulttemplateinthesearchsitecollection.Firstwedoaquerytoseetheresultpagewithrefiners.Ifwesearchfor“PulpFiction”,thiswillshowarefinerforModifiedDate,whichisoneoftheout-of-theboxrefiners.Clickthetoolsiconattheupper-right,andthenclickEditPage.

ClickEditwebpartfortheRefinementWebPart.Thisbringsupaconfigurationpanel,whichletsyouchooserefinersfortheWebPart.Addallthenewmanagedpropertiesasrefiners.





Wenowneedtocheckinandpublishourchanges.

Ifwenowtryoutaqueryfor“ReleaseYear>0”,wegetbackallthreeresultswithrefiners,justlikethescreenshotatthebeginningoftheblogpost.





Lookingformoreinformation?

CheckouttheMSDNdocumentationforcontentenrichment.ThereisalsoaHowtoarticlethatgivesyouanexampleofhowtocreateacontentenrichmentwebserviceinVisualStudio.

Finally,lookoutforourupcomingblogpostsonthatwillprovidebestpracticesfordebuggingthecontentenrichmentserviceandshowyouhowtouseWCFRoutingtodocontent-basedroutingandloadbalancing

原文地址:http://blogs.msdn.com/b/sharepointdev/archive/2012/11/13/customize-the-sharepoint-2013-search-experience-with-a-content-enrichment-web-service.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐