In the last article, we saw how to do a CAML Query execution against the taxonomy field. In this article, again, let us discuss about the Managed Properties and How to do a Search based on the Taxonomy Field.
Basically, Managed Metadata Service Application and the Search Service Application are more of a kind of integral architecture. And one important interesting thing is, when we search for a Term, there are certain options like, whether the Results mapped to the Child Terms should also come or not.
In detail, Let us assume that, we have a Term called Term1 and a child term called Term11. When I search for the records which are mapped for Term1, then obviously the records mapped for Term11 will also come. We can restrict this as well.
To do that, the Search Query will be as below. This example is for the OOB Content Search WebPart.
To retrieve the Child Terms
owsTaxIdMyTerm: {Term.IDWithChildren} -> This will retrieve the Term from the Navigation and render the results with Children.
owsTaxIdMyTerm: {Term} or {Term.ID} or {Term.IDNoChildren} – This will retrieve only the current term and not the child terms.
The same thing during the custom content Search WebPart can be as below.
owsTaxIdMyTerm:#0<<TermGUID>> – This will retrieve the Term from the Navigation and render the results with Children.
owsTaxIdMyTerm:#<<TermGUID>> – This will retrieve only the current term and not the child terms.
The sample query would be
"(" + MyTaxonomyColumn1 + ":#0" + strTermid + " OR " + MyTaxonomyColumn2 + ":#0" + strTermid + ")
As I said, earlier I am not sure how the Search Service Application differentiates between the #0 and #.
When I closely looked at the results given on the ManagedProperty of a TaxonomyField,
GP0|#<<GUID of the Term>>;L0|#0<<GUID of the Term>>|<<Term Name>>;GTSet|#<<GUID of TermSet>>;GPP|#<<Guid of the Parent Term>>;GPP|#<<Guid of the Parent Term>>
The GPP is the Parent Term GUID till the top most Parent Term.
In case of a Multi Value column, the Managed Property would be separated by a ‘;’.
When I was struggling with this kind of requirement, the Technet Article helped a lot. I request the readers to go through that as well to get a clear understanding about this.
Again, this kind of information will not be required frequently. But when we got struck with this kind of requirement, then we will require this for sure. Post your queries on the below discussion section for further information.
Happy Coding,
Sathish Nadarajan.
Leave a comment