Searching for empty managed metadata columns can now be achieved.
When working with SharePoint search programmatically, one weakness that developers often face is the inability to query for “null” or empty values. One solution I saw when performing some maintenance on a client’s (heavily customised) intranet was to do a NOT match against a*, b*, c*… z*. This worked for their usage, but it was a bit ugly, and the resulting query was enormous. Additionally, it only gets more complex if we consider that not all of our data will start with alphabetical characters.
When working with managed metadata, I found that a far more elegant solution was to query a managed property mapped to the a taxonomy ID crawled property (eg: ows_taxId_MyColumn). When content is tagged with data, this managed property will look something like this:
Content with a value will always start with G, so we can do a search for items that do not start with G to match all blank selections. This might look like:
Using the taxonomy ID also gives us the ability to do exact matches against terms using ‘#0<TermId>’ (helpful when there are multiple terms that share a label), or match all children of a particular term ‘#<TermId>’.
I’ve found this to be extremely powerful when used correctly!
Please send us your feedback to https://fivep.com.au/contact-fivep/.
|Kieran Cumming | Solution Architect | FiveP
About the author: Kieran’s IT knowledge surpasses that of many elders. He does anything from back-end code to the user interface, he can script or code his way out of any problem.