I am using Sitecore 9.2
and SOLR
. We have huge content and multi-language environment. We would like to create separate SOLR core index for each of the language.
- Is it possible?
- If yes, please guide me how?
I am using Sitecore 9.2
and SOLR
. We have huge content and multi-language environment. We would like to create separate SOLR core index for each of the language.
Sitecore OOTB uses two parameters for the crawler
There is no parameter for the language in it, So OOTB it is not possible. However, you can perform this by creating your custom crawler by inheriting the OOTB crawler. You can do this by adding a new parameter and crawler type in the config. I am taking an example of the web database index here -
<locations hint="list:AddCrawler">
<crawler type="xyz.Foundation.Indexing.CustomSitecoreItemCrawler, xyz.Foundation.Indexing">
<Database>web</Database>
<Root>/sitecore</Root>
<LanguageName>your-lanague</LanguageName>
</crawler>
</locations>
and base on the lanague you can specifiy the index name such as "sitecore_web_en_us_index
".
Next, you need to write a custom crawler code for this, you can inherit the SitecoreItemCrawler
located in Sitecore.ContentSearch
dll.
In your custom crawler, you need to set the language from the config -
public string LanguageName
{
get
{
if (!string.IsNullOrEmpty(this.language))
return this.language;
return (string)null;
}
set
{
this.language = value;
}
}
public Language Language
{
get
{
Database master =
Sitecore.Configuration.Factory.GetDatabase(this.database);
return master.GetLanguages().Where(x => x.Name.ToLower() == this.language.ToLower())
.FirstOrDefault();
}
}
and after that need to override the DoAdd
function, by removing the foreach
loop of indexable item languages and pass our language -
protected override void DoAdd(IProviderUpdateContext context, SitecoreIndexableItem indexable)
{
Assert.ArgumentNotNull((object)context, nameof(context));
Assert.ArgumentNotNull((object)indexable, nameof(indexable));
using (new LanguageFallbackItemSwitcher(new bool?(context.Index.EnableItemLanguageFallback)))
{
this.Index.Locator.GetInstance<IEvent>().RaiseEvent("indexing:adding", (object)context.Index.Name, (object)indexable.UniqueId, (object)indexable.AbsolutePath);
if (!this.IsExcludedFromIndex(indexable, false))
{
Language language = this.Language;
//foreach (Language language in indexable.Item.Languages)
//{
Item obj1;
using (new WriteCachesDisabler())
obj1 = indexable.Item.Database.GetItem(indexable.Item.ID, language, Sitecore.Data.Version.Latest);
if (obj1 == null)
{
CrawlingLog.Log.Warn(string.Format("SitecoreItemCrawler : AddItem : Could not build document data {0} - Latest version could not be found. Skipping.", (object)indexable.Item.Uri), (Exception)null);
}
else
{
Item[] objArray1;
using (new WriteCachesDisabler())
{
Item[] objArray2;
if (obj1.IsFallback)
objArray2 = new Item[1] { obj1 };
else
objArray2 = obj1.Versions.GetVersions(false);
objArray1 = objArray2;
}
foreach (Item obj2 in objArray1)
{
SitecoreIndexableItem sitecoreIndexableItem = (SitecoreIndexableItem)obj2;
IIndexableBuiltinFields indexableBuiltinFields = (IIndexableBuiltinFields)sitecoreIndexableItem;
indexableBuiltinFields.IsLatestVersion = indexableBuiltinFields.Version == obj1.Version.Number;
this.Operations.Add((IIndexable)sitecoreIndexableItem, context, this.index.Configuration);
}
}
//}
}
this.Index.Locator.GetInstance<IEvent>().RaiseEvent("indexing:added", (object)context.Index.Name, (object)indexable.UniqueId, (object)indexable.AbsolutePath);
}
}