Kieran’s Tech Talk – Searching for empty managed metadata columns

admin July 13th, 2017

Searching for empty managed metadata columns

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:

GP0|#062a3a03-14f7-4d16-88b4-efec8aff6c82;L0|#0062a3a03-14f7-4d16-88b4-efec8aff6c82|My Term;GTSet|#ce70ce15-52da-434c-a0f5-b81751d5db75

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:

NOT(MyManagedProperty:’G*’)

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/.

K.


 

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.


Comments (0)

Can you relate
to any of these
problems?