Computed index fields are allow you to perform additional processing before adding data to an index. For example, you may want to store the contents of a droplink field (the raw value being a GUID) as the target item's name, or a particular field value from the target item. This short blog post covers a couple of tips on how to set up and configure your computed field.
In .config, a computed field looks like this:
Notice that indexType is set to untokenized - you would expect that your computed field is now indexed as a single string, but it will actually still appear as tokenized (split up, noise words and separators removed) in your index.
If you are storing a value for display or faceting purposes (e.g. the name of a city, which you would want saved as 'Los Angeles', not 'Los' and 'Angeles' separately), you want it to be stored as untokenized. To do this, add your computed field as an entry in the <fieldNames hint="raw:AddFieldByFieldName"> section of the config (in my case,Sitecore.ContentSearch.Lucene.DefaultIndexConfiguration.config)
alongside the regular, non-computed fields and specify an Analyzer:
The computed value will now be indexed as untokenized.
When creating your own computed or virtual field, don't return String.Empty unless it is important that your index contains an empty string (e.g. you are storing form submissions and String.Empty indicates that a choice was made to omit information, whilst null might mean that there was never an opportunity to enter the information in the first place) - that value will actually be indexed, and you might end up with 12,000 entries for 'nothing' that take up space in your index. If you return null, nothing will be added to your index.
Hi, I tried adding them in the regular non computed section and it still index as tokenised. Do I still need to keep my config entry in the computed section too. Also <fieldType fieldName="summaryimagecomputed" is this supposed to be <field fieldName="summaryimagecomputed"
Yes, you're right, that was a copy-paste error - it's 'field' rather than 'fieldType'. And you do need it in both section - a) in raw:AddComputedIndexField and b) in raw:AddFieldByFieldName. 'parsedlanguage' is a good field to use as an example in a plain installation.
That analyzer you use converts the field to lower case. Which analyzer would I want to use if I want to maintain case?
Thanks for the tip! I was losing my mind over this issue :D
Nice one I was also losing my mind over this one. :D
Can you tell me what the values of "boost" can be? Is this a hex decimal value? Thanks.