2

I would like to create a custom aspx page to populate Solr schema akin to how you create a custom aspx page to rebuild indexes (https://doc.sitecore.com/xp/en/developers/102/platform-administration-and-architecture/rebuild-search-indexes.html)

This is part of a larger PaaS deployment automation so I will not be using the endpoint that you can use to populate schema as that requires logging into Sitecore first (https://doc.sitecore.com/xp/en/developers/102/platform-administration-and-architecture/solr-managed-schemas.html)

Is there a good way to create a custom aspx page for calling a populate schema akin to the example in the Sitecore docs per rebuilding indexes?

I use the Sitecore CLI for my local development but am choosing the custom aspx pages as part of the larger deployment automation for Azure PaaS environments.

1 Answer 1

2

There is a PopulateManagedSchema.aspx admin page at sitecoreinstance\sitecore\admin folder. When you click on Populate Solr Managed Schema link under the control panel, select the indexes checkbox and hit Populate button, under the hood it triggers the PopulateManagedSchema.aspx page load method to populate schema. Here you will see the populate schema code. It is part of Sitecore.ContentSearch.Client.dll

If you want some custom implementation then you can try out to create a custom aspx page and use any decompiler tool to understand and see the code Sitecore.ContentSearch.Client.dll you will find this code at Sitecore.ContentSearch.Client.sitecore.admin.PopulateManagedSchema and customize as per your requirement.

You need to mainly use this piece of code:

try
{
    bool flag = text2.ToLower().Equals("all");
    Log.Audit("Start Populating Managed Schema from Admin Page, indexes: " + string.Join(", ", list.ToArray()), this);
    foreach (ISearchIndex index in ContentSearchManager.Indexes)
    {
        if (flag || list.Contains(index.Name.ToLower()))
        {
            SchemaCustodian.PopulateManagedSchema(index);
        }
    }
    stringBuilder.Append(" OK<br/>");
}
catch (Exception ex)
{
    stringBuilder.Append(string.Concat("<textarea class='exception'>", ex, "</textarea><br/>"));
}

You can validate it directly like, if you call it with URL and pass '|' index names it would update the managed-schema and then you can check at solr folder.

https://yourSitecoreInstance/sitecore/admin/PopulateManagedSchema.aspx?indexes=sitecore_master_index|test_products_master_index

Hope it helps!

1
  • Thanks. I pulled that and need it outside the admin page. I may move it to the root and invoke a web request
    – Kode
    Commented May 6, 2023 at 13: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.