Posts

Showing posts with the label Solr

Back to Basics: Fetch Solr Index Field Name for Sitecore Fields Using Solr FieldNameTranslator

Image
I have been meaning to write this post for a while as I have been using this nifty little feature in all my content search API implementations using the Solr provider. Unsafe: Defining SearchResultItem classes using hard coded Solr fields names for IndexField data annotation attributes as follows: [IndexField("page_title")] public string PageTitle { get; set; }   Problems : Cause runtime errors when field names change in Sitecore Hard coded strings, sort of magic values Unmanageable code Safe: Define SearchResultItem classes using strongly typed constants for data annotation attributes as follows: [IndexField(SampleItem.PageTitleSolrIndexFieldName)] public string PageTitle { get; set; } Solution : Compile time errors are way better than runtime errors More manageable code More readable code More dynamic query building Trick : Fetch Solr translated field name values on template fields  using  FieldNameTranslator  and reference them  with code gener

Published content does not get indexed for language variants when using Language Fallback Module

Just when I thought I have Alex Shyba's Language Fallback module all figured out, I ran into a bug related to indexing fallback versions of items. Bug (Short Version): Fallback language variants of items do not get crawled by the default SitecoreItemCrawler.  Bug Explained (Long Version) The reason is that the default crawler relies on field values stored in the database in order to index them. The Fallback Provider in the fallback module "spoofs" fallback language version of  the field values by returning the field values of the master language version of the item, and as such does not store these values in database. The result is that you only have the master language field values available for crawling. But thanks to the Sitecore community, had already been resolved  here . However, this resolution assumes that you are working with SEARCH CONTRIB / ADVANCED DATABASE CRAWLER module. I wasn't looking to introduce more uncertainty to my solution by add

Sitecore: Extract Indexed Content of Media Files using MediaItemContentExtractor

Here is something in addition to my previous post regarding indexing associated content: Here is a common scenario: Your custom index configuration is set up to crawl all the content for your website which is then used by your site search (keywords search) to fetch search results. In addition to you content item crawlers, you add a crawler for Media Library items as well and Sitecore does a great job of indexing PDF, DOCX, DOC, etc. files automatically, provided your have a valid IFilter installed, and now you have search extended to show file items as search results. Now consider the following scenario: One of the lookup fields on your page points to a file in the media library and the new requirement is to show the page item in the search result when the search phrase matches the content in the associated file. Solution (Lucene & Solr): Create a computed field called "related_content" that stored the crawled content of the associate file and extend the query to now se

RESOLVED: Sitecore Solr provider error: Value cannot be null. Parameter name: fieldNameTranslator.

Server Error in '/' Application. Value cannot be null. Parameter name: fieldNameTranslator Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: fieldNameTranslator Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [ArgumentNullException: Value cannot be null. Parameter name: fieldNameTranslator]    Sitecore.ContentSearch.Linq.Solr.SolrIndexParameters..ctor(IIndexValueFormatter valueFormatter, IFieldQueryTranslatorMap`1 fieldQueryTranslators, FieldNameTranslator fieldNameTranslator, IExecutionContext[] execut

RESOLVED: Connection error to search provider [Solr] : Unable to connect to , Core: [index_name]

If you are working with Solr provider for Sitecore 8, I'm sure you have already read this  article regarding changes to the Schema.xml that must be applied. In a recent Solr integration with Sitecore 8 Update 5  (rev. 150812) , I ran into the following error(s): Connection error to search provider [Solr] : Unable to connect to <solr service address>, Core: [index_name] Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: Sitecore.ContentSearch.Exceptions.SearchProviderConnectionException: Connection error to search provider [Solr] : Unable to connect to [http://ocomp-sc-solr:8080/solr], Core: [social_messages_master] Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be id

Sitecore: Indexing Associated Content

Setting up indexes and indexing content for site search in Sitecore is a pretty straightforward task and there is an extensive knowledge base put together by the community with various examples. One useful construct we often find ourselves implementing for keyword search is  setting up a computed field . I typically use this construct to index any additional content referenced by a page, typically (content blocks, promos, callouts) added to the page via presentation details The Need: Index externally reference content by a page item Solve: Create a computed field to index TextField and HtmlText type fields of referenced items This implementation fetches all the renderings for the current item's presentation for the default device and checks their datasource item for index-able content. As a suggestion, check if the current item inherits from certain page templates else skip the execution. Step1: Create a class and implemented the IComputedIndexField interface as shown below: pu

Solr Error: Plugin init failure for [schema.xml] fieldType "x": Error loading class 'solr.xfield'

I recently integrated Solr with Sitecore 7.2 and found that the Schema.xml generated by Sitecore is only supported up to Solr 4.x.  Configuring Solr for Sitecore 8  provides the steps required to upgrade Schema.xml to work with Solr 5.x, especially the Step 3 that mentions that Solr.IntField is deprecated and must be replaced with Solr.TrieIntField. What is fails to mention is that you need to replace the other field types as well else you run into the following error for each of the field types: Could not load conf for core contentindex: Plugin init failure for [schema.xml] fieldType "plong": Error loading class 'solr.LongField'. The Fix: In Sitecore generated Schema.xml Replace     <fieldType name="pint" class="solr.IntField" />     <fieldType name="plong" class="solr.IntField" />     <fieldType name="pfloat" class="solr.FloatField" />     <fieldType name="pdou