Mark's Sitecore Blog

Use System.Boolean when indexing checkbox fields

I faced the issue that checkbox values were not being updated in the index correctly. When I unchecked a checkbox and saved, the index would still have “1” stored as value for my field. To prevent this issue, use Sytem.Boolean as type instead of System.String.

<field fieldName=”MyCheckboxField” storageType=”YES” indexType=”TOKENIZED” vectorType=”NO” boost=”1f” type=”System.Boolean” settingType=”Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider” />

Internally, lucene still stores “0” or “1”, but when using System.String, values of false would be considered as “nothing” when updating the index, leading to not updating the value of the field. Changing to System.Boolean made it work.

 

TwitterGoogle+Facebook 

2 thoughts on “Use System.Boolean when indexing checkbox fields

  1. Mike

    I’m facing the issue that when I uncheck the value (false) then the index field is no longer present for that item. When I check the value (true) then the field reappears in the index. Any idea?

    1. Mark Post author

      This is standard Lucene behavior as far as I am concerned. Lucene won’t store the “false” value explicitly but instead just store no value at all because System.Boolean defaults to false.

Leave a Reply

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