2

I have a SharePoint 2010 publishing site collection with a Term Store that I want to use for navigation. I understand the process of get the collection of published pages and examining the managed metadata column for a specific term or terms, but is it possible to find all items tagged with a specific term without iterating through every single page? Kind of like flipping the one to many relationship of items, pages, etc. to terms around backwards so for each term there could be one or more items using it.

If this doesn't make sense I'll clarify.

3 Answers 3

1

Yes, that is possible and perhaps Metadata navigation feature of list/libraries is using it behind the scene.

The article below precisely describes what it takes to build a CAML to query list/library items based on managed metadata fields:

Querying on Managed Metadata Field Values in SharePoint Server 2010 (ECM)

1

Using the query hints above I was able to build some web parts the show the term store as navigation and trigger that term search:

enter image description here

It's also available for A-Z glossary (flat structure):

enter image description here

Hope that helps.

1

You probably want to use CrossListQueryInfo and CrossListQueryCache to do cross-list queries. In your case, to get all the pages that have a certain metadata tag.
Here's a link on how to do those cross list queries: http://bloggingabout.net/blogs/bas/archive/2009/03/27/using-the-crosslistqueryinfo-and-crosslistquerycache.aspx

Then, for your CAML Query you should do something like:

TaxonomySession session = new TaxonomySession(SPContext.Current.Site, true);
Term term = session.GetTerm(termId);
var wssId = TaxonomyField.GetWssIdsOfTerm(site, term.TermStore.Id, term.TermSet.Id, term.Id, false, 1).FirstOrDefault();

string query = String.Format(@"<Where><Eq><FieldRef Name='YourFieldName' LookupId='TRUE' /><Value Type='Lookup'>{0}</Value></Eq></Where>", wssId);


Hope it's what you're looking for. Happy coding!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.