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.
2 responses to “Use System.Boolean when indexing checkbox fields”
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?
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.