0

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?
2
  • is this a SXA website? Commented Dec 15, 2019 at 21:32
  • No. Its not a SXA website. We are using Sitecore JSS.
    – Jitendra
    Commented Dec 16, 2019 at 7:17

1 Answer 1

1

Sitecore OOTB uses two parameters for the crawler

  • Database - Database on which you want to perform the indexing
  • Root - the path of the Sitecore node

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);
        }
    }
3
  • 1
    This is solving crawler problem more or less but how you will instruct Sitecore to use different index during it's searching in Content Editor, using Sitecore's Search API, ...? Commented Dec 13, 2019 at 9:46
  • Thanks Mahendra !!! will try and let you know here.
    – Jitendra
    Commented Dec 13, 2019 at 10:28
  • 1
    Good Point @PeterProcházka! , We don't need to change anything in Sitecore's master, web and core indexes crawler, they will use the same existing crawler. So for example, we need en-Us and en-Ca as language indexing then these will be additional indexes with "sitecore_master_index", "Sitecore_web_index" and "Sitecore_code_index". A new patch file for "Sitecore_master_en_us_index" and "Sitecore_master_en_ca_index" and similar for the web database Commented Dec 13, 2019 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.