Sitecore 8.1 computed index field for image only indexing alt text on solr -


ran issue other day can't find yet (from googling) addresses issue.

i using solr indexing engine. trying index image field in template. indexing working fine it's not indexing media url (that returning code) instead it's indexing alt text of image. if alt text not present it's indexing media url. have index configuration in separate file.

i think below line in default sitecore.contentsearch.solr.defaultindexconfiguration.config file messing config. how overwrite "main_image" field.

<fieldreader fieldtypename="image" fieldreadertype="sitecore.contentsearch.fieldreaders.imagefieldreader, sitecore.contentsearch" /> 

below how configuration looks like:

<?xml version="1.0" encoding="utf-8" ?> <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">   <sitecore>     <myindex>       <indexconfigurations>         <mysolrindexconfiguration ref="contentsearch/indexconfigurations/defaultsolrindexconfiguration">             <fields hint="raw:addcomputedindexfield">                 <field fieldname="main_image" returntype="text">my.indexing.namespace.mymainimageindexing,my.indexing</field>                 <field fieldname="thumbnail" returntype="text">my.indexing.namespace.mythumbnailindexing,my.indexing</field>             </fields>         </mysolrindexconfiguration>       </indexconfigurations>     </myindex>   </sitecore> </configuration> 

one of implementations looks below (the other 1 similar)

public class mymainimageindexing : icomputedindexfield {     public string parameters { get; set; }     public string fieldname { get; set; }     public string returntype { get; set; }      public object computefieldvalue(iindexable indexable)     {         assert.argumentnotnull(indexable, "indexable");         var indexableitem = indexable sitecoreindexableitem;          if (indexableitem == null)         {             log.warn(string.format("{0} : unsupported iindexable type : {1}", this, indexable.gettype()), this);             return null;         }          imagefield img = indexableitem.item.fields["main image"];          return (img == null || img.mediaitem == null) ? null : mediamanager.getmediaurl(img.mediaitem);     } } 

could please shed light here on how resolve issue.

thanks in advance.

p.s> have seen john west's post here http://www.sitecore.net/de-de/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2013/05/sitecore-7-pre-render-image-fields.aspx

your code looks fine. have bug in configuration.

you set returntype of fields text means solr tokenize fields. means solr won't keep values 1 string, instead create tokens allow full text search in future.

you should change configuration

<field fieldname="main_image" returntype="string">... 

after reindex, solr keep whole value single string.

also should aware if rename media item, solr have outdated urls , not rebuild referencing documents automatically.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -