39
Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Embed Size (px)

Citation preview

Page 1: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Developing against Managed Meta Data – Blackbelt

Bart-Jan HoeijmakersDonald Hessing

Page 2: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Introduction – Who are we? Donald Hessing

– Working with SharePoint since 2007, before .Net architect– Technical Manager, Lead SharePoint Architect at VX Company– Virtual Technology Solution Professional for Microsoft Netherlands

Bart-Jan Hoeijmakers– Working with SharePoint since 2006, before .Net developer– Lead SharePoint Developer at VX Company– Strong focus on developing custom solutions

Page 3: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Agenda• Introduction – Who are We?• Architectural overview of Managed Meta Data• Provision Taxonomy Field• How to set Taxonomy Field value programmatically?• Query List items by Taxonomy Field value using CAML• Search for items by Term• Column specific TermSets

Page 4: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

MANAGED META DATA ARCHITECTURE

Page 5: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Managed Meta Data Service Application

• Sharing meta data cross:– Sites, Site Collections, Web Applications, Farms

• Centralized management of:– TermSets, Terms, ContentTypes

• MMS can be connected cross farm• Multiple MMS can be connected to the same web application• MMS is Tenant “aware” partitioned

Page 6: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Terminology

= TermStore= TermGroup= TermSet= Term

= Term

Page 7: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Administration• Managed Meta Data Service Application

– Administrators• Manage the properties of the Service Applications• Are NOT Term Store Administrator by default

– Permissions• Local Farm: By default all services local to the farm have full access

• Term Store Administrator– Create Term Groups– Assign Term Group Managers

• Can assign Term Group Contributors– Create and manage Term Sets and Terms

Page 8: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Consuming Managed Meta Data• Webapplication must be connected to the Service

Application– Managed Meta Data Service Applications in the default

proxy group are connected automatically

Page 9: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Enterprise Keywords• Enterprise Keyword Field allows users to select enterprise

keywords and managed terms• Used keywords are stored in the Keywords TermSet of the

System Group in the MMS• Set the default storage location for keywords

• Users must have permissions on the MMS

Page 10: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

TaxonomyHiddenList

• Stores taxonomy values for:– Assigned Taxonomy values in the site collection– Default values of the Taxonomy Field Site Column

• The Taxonomy Field is a lookup field to TaxonomyHiddenList– This prevents a hotspot on MMS

• TaxonomyHiddenList is synchronized with the TermStore by the Taxonomy Update Scheduler Timer Job

• Updating a term in the TermStore doesn’t change the field– The new value is provided by the lookup to the synchronized TaxonomyHiddenList

Location: [SiteCollectionUrl]/Lists/TaxonomyHiddenList

Page 11: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

PROVISION MANAGED META DATA FIELD

Page 12: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Provision Managed Metadata Field• For provisioning a Taxonomy Field you need 2 Fields: <Field Type=“TaxonomyFieldTypeMulti” Name=“DemoTaxField” ..../> <Field Type=“Note” Name=“DemoTaxFieldTaxHTField0” .... />

• TaxonomyFieldTypeMulti renders the hierarchical meta data field (FieldControl)– Stores the WssId of the item in the TaxonomyHiddenList– [4;#SharePoint 2010]– Value is provided by the Lookup to the TaxonomyHiddenList

• Note field stores the selected term label and term GUID – [SharePoint 2010|dd212d38-417e-4a9d-8222-e856b05d627b]

Page 13: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Provision Taxonomy Field

• When provisioning TaxonomyFields, also provision the hidden notefield!

Microsoft Naming Convention

Page 14: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Add Field to ContentType• Manually add the TaxCatchAll and TaxCatchAllLabel fields to the

listdefinition, or to your contenttype• Seach refinement panel and Document Information Panel rely

on these fields

Page 15: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Event Receivers• Manually add the

TaxonomyItemSynchronousAddedEventReceiver and TaxonomyItemUpdatingEventReceiver to the list definition

Synchronizes the TaxCatchAll fields and the hidden notefield

Page 16: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Bind Taxonomy Field to TermStore• Taxonomy Field is a specialized lookup field• After provisioning it should be binded to a

TermStore:– Bind TermStoreID and TermSetID in event receiver– Bind the hidden note field in event receiver

This doesn’t work for SandBox solutions because the “Microsoft.SharePoint.Taxonomy” DLL is not available!!

Page 17: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing
Page 18: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

TaxonomyFieldAdded featureWhen using custom webtemplates, or site definitions based on Blank Site Template make sure that hidden feature 73ef14b1-13a9-416b-a9b5-ececa2b0604c (TaxonomyFieldAdded) is activated on the sitecollection!

Page 19: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

DEMO

Page 20: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

SET TAXONOMY FIELD VALUE PROGRAMMATICALLY

Page 21: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

How to set a value of a Taxonomy field programmatically?

• In General: Terms that were not used before will be added to the TaxonomyHiddenList of the SiteCollection

• Taxonomy Field can be updated by– TermGUID– Term from the Term Store (MMS)

• The Taxonomy Field has a reference to the TermStore (SspId) and TermSet (TermSetId)

Page 22: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Set value by the Guid of the TermSite can have

multiple TermStores associated

We usually don’t know the GUID of

the Term

Page 23: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Set term based on LabelThe Taxonomy Field has a reference to the TermStore and TermSet Taxonomy

Field

Get the Term by

label

Page 24: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

DEMO

Set taxonomy valueTaxonomyHiddenList

Page 25: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

QUERY LIST ITEMS BY TAXONOMY FIELD VALUE USING CAML

Page 26: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Query the list using CAML• Get all list items that are tagged with a

term or one of its child terms• CAML query can be constructed to

achieve this goal<Where><In><FieldRef LookupId="TRUE" Name=“MyTaxonomyField" /><Values> <Value Type="Integer">7</Value>

<Value Type="Integer">5</Value><Value Type="Integer">6</Value>

</Values></In></Where>

TaxonomyField.GetWssIdsOfTerm(..,..,..)

Page 27: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Taxonomy Fields and CAMLGet the Lookup Id’s of the Term from the TaxonomyHiddenList

Construct the CAML query

Execute the CAML Query against the list

Page 28: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

DEMOQuery List Items by Taxonomy Field value using CAML

Page 29: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

SEARCH FOR ITEMS BY TERM

Page 30: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Setting up Metadata properties• For Taxonomy Fields, Crawled and Managed properties are

automatically created after the first full crawl– Only when a list item is added and contains a taxonomy field value

• Nice for out of the box implementations, but for custom solutions :– You can’t first call someone to create a listitem for the managed properties– Create the crawled and managed properties in advance by using

powershell– Provide crawled property with prefix ows_taxId_– Provide managed property with prefix owstaxId

Page 31: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Managed and crawled properties

To create and map properties in PowerShell, use the following commandlets:• New-SPEnterpriseSearchMetadataCrawledProperty• New-SPEnterpriseSearchMetadataManagedProperty• New-SPEnterpriseSearchMetadataMapping

Page 32: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Search by Term in code

Page 33: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Hierarchical search vs exact search• Prefix term GUID in search query with # or

with #0• #0 = exact search SharePoint

• # = search for the term or any child terms below it in the TermStore hierarchy

SharePoint, MOSS 2007, SharePoint 2010

Page 34: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

DEMOSearching items by term from code

Page 35: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

COLUMN SPECIFIC TERMSETS

Page 36: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Column specific TermSets• In general Taxonomy Fields are connected to a central TermSet

– Departments

• It is also possible to create and connect to a local TermSet– To provide team specific termsets that don’t make sense for global availability– Termsets are stored in the MMS with SiteCollection-FieldName as name

• Default storage location for column specific Term Sets should be enabled

Page 37: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Other Gotcha’ s• TaxonomyHiddenList is resource throttled• The TaxonomyHiddenList is not cleaned up with unused

terms• Keywords stored in the termstore are not security trimmed• The number of lookupFields is limited to 8 by default

number of joins allowed per query• Import of termsets will get a new GUID during import |

DTAP

Page 38: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Key take aways!• MMS can provide taxonomy for Sites, SiteCollections, Web Applications

or Farms• TaxonomyHiddenList in the Site Collection prevents hotspot on MMS• Provisioning Taxonomy Fields requires additional Fields and attached

EventReceivers• The Taxonomy Field contains a reference to the TermStore and TermSet• Hierachical search on Taxonomy Fields can be done by using Search

– Use #0 for exact match– Use # for search on child terms

Page 39: Developing against Managed Meta Data – Blackbelt Bart-Jan Hoeijmakers Donald Hessing

Q & A

ContactDonald [email protected]://bloggingabout.net/blogs/donaldTwitter:@dhessing

ContactBart-Jan [email protected]://www.insidesharepoint.net