Skip to main content

Digital Transformation

Sitecore Search with MustNot QueryOccurance

Sitecore Search, and before it Lucene indexes are great to use within Sitecore implementations when you have a large list of items that you need to query.  The new namespace Sitecore.Search allows you to query specific fields for values, and through the use of the QueryOccurance enumerator, gives you the option to choose whether the value you’re looking for must equal that of the item (Must), cannot equal that of the item (MustNot), or can equal that item (Should).  The ability to set a MustNot QueryOccurance cannot be understated, as it allows you the ability to weed out any items with a specific value. 

For instance, I’ve had the case where I used an “Inactive” checkbox field on an item and I wanted my query to only return items that are active (thus the checkbox is not checked), so I set up a MustNot query on that field with the value 1.  (The value 1 indicates that the checkbox is checked.)    Unfortunately, there is a little bit of a caveat if this is the only query you need – because it seems that a lone MUSTNOT query will not return results.  Don’t fret though, there’s a pretty easy way around this that will still give you the results you’re looking for. 

Check out this blog post for the quick technical details on how to utilize a lone MustNot query.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Jamie Stump

My name is Jamie Stump, and I am a Senior Sitecore Consultant at Perficient. I was honored to be named one of only 42 2013 Sitecore MVP’s worldwide. I specialize in Sitecore Architecture and Development and my broad Sitecore experience includes Sitecore installation, configuration and CEP development, including custom DMS implementations for clients. I have implemented Sitecore solutions for a number of industry verticals including manufacturing, healthcare, financial services, advertising and retail. In addition to architecting and implementing Sitecore sites and eCommerce solutions, I also work with other Microsoft Technologies, including the .NET platform and SQL Server. You can read through my older Sitecore related blog posts here and my newer ones here. I graduated with a Bachelor of Science in Information Systems Development from York College of PA. I am originally from the suburbs of Philadelphia, PA, and still reside there with my wife, son, English bulldog and 2 cats.

More from this Author

Follow Us
TwitterLinkedinFacebookYoutubeInstagram