SIF/1011/SXA/sxa-solr.json

{
    "Parameters": {
        "SolrUrl": {
            "Type": "string",
            "DefaultValue": "https://localhost:8983/solr",
            "Description": "The Solr instance url."
        },
        "SolrRoot": {
            "Type": "string",
            "DefaultValue": "c:\\solr-6.6.1",
            "Description": "The file path to the Solr instance."
        },
        "SolrService": {
            "Type": "string",
            "DefaultValue": "Solr-6.6.1",
            "Description": "The name of the Solr service."
        },
        "SolrBaseConfig": {
            "Type": "string",
            "DefaultValue": "_default",
            "Description": "The configset to copy as a base for each core."
        },
        "SolrCorePrefix": {
            "Type": "string",
            "DefaultValue": "sitecore",
            "Description": "The prefix for each of the created indexes."
        }
    },
    "Variables": {
        "Solr.Root": "[resolvepath(parameter('SolrRoot'))]",
        "Solr.Server": "[joinpath(variable('Solr.Root'), 'server', 'solr')]",
        "Solr.BaseConfigs": "[joinpath(variable('Solr.Server'), 'configsets', parameter('SolrBaseConfig'))]",
        "Solr.SchemaFileName": "managed-schema",
        "Solr.Xpath.SchemaRoot": "//schema",
        "Solr.Xpath.UniqueKey": "[concat(variable('Solr.Xpath.SchemaRoot'), '/uniqueKey')]",
        "Solr.UniqueField": "_uniqueid",
        "Solr.UniqueField.Attributes": {
            "name": "[variable('Solr.UniqueField')]",
            "type": "string",
            "indexed": "true",
            "required": "true",
            "stored": "true"
        },
        "Solr.Core.Master.Name": "[concat(parameter('SolrCorePrefix'), '_sxa_master_index')]",
        "Solr.Core.Web.Name": "[concat(parameter('SolrCorePrefix'), '_sxa_web_index')]",
 
        "Solr.Core.Master.Root": "[joinpath(variable('Solr.Server'), variable('Solr.Core.Master.Name'))]",
        "Solr.Core.Web.Root": "[joinpath(variable('Solr.Server'), variable('Solr.Core.Web.Name'))]",
 
        "Solr.Core.Master.Conf": "[joinpath(variable('Solr.Core.Master.Root'), 'conf')]",
        "Solr.Core.Web.Conf": "[joinpath(variable('Solr.Core.Web.Root'), 'conf')]"
    },
    "Tasks": {
        "StopSolr": {
            "Description": "Stops the Solr service if it is running.",
            "Type": "ManageService",
            "Params": {
                "Name": "[parameter('SolrService')]",
                "Status": "Stopped",
                "PostDelay": 1000
            }
        },
        "CleanCores": {
            "Description": "Creates/clears core paths.",
            "Type": "EnsurePath",
            "Params": {
                "Clean": [
                    "[variable('Solr.Core.Master.Root')]",
                    "[variable('Solr.Core.Web.Root')]"
                ]
            }
        },
        "PrepareCores": {
            "Description": "Copies base configs into the core paths.",
            "Type": "Copy",
            "Params": [
                {
                    "Source": "[joinpath(variable('Solr.BaseConfigs'), '*')]",
                    "Destination": "[variable('Solr.Core.Master.Root')]"
                },
                {
                    "Source": "[joinpath(variable('Solr.BaseConfigs'), '*')]",
                    "Destination": "[variable('Solr.Core.Web.Root')]"
                }
            ]
        },
        "AddSchemaUniqueKeyField": {
            "Description": "Amends the core managed schema uniqueKey element",
            "Type": "SetXml",
            "Params": [
                {
                    "FilePath": "[joinpath(variable('Solr.Core.Master.Conf'), variable('Solr.SchemaFileName'))]",
                    "Xpath": "[variable('Solr.Xpath.SchemaRoot')]",
                    "Element": "field",
                    "Attributes": "[variable('Solr.UniqueField.Attributes')]"
                },
                {
                    "FilePath": "[joinpath(variable('Solr.Core.Web.Conf'), variable('Solr.SchemaFileName'))]",
                    "Xpath": "[variable('Solr.Xpath.SchemaRoot')]",
                    "Element": "field",
                    "Attributes": "[variable('Solr.UniqueField.Attributes')]"
                }
            ]
        },
        "UpdateSchemaUniqueKey": {
            "Description": "Amends the core managed schema uniqueKey element",
            "Type": "SetXml",
            "Params": [
                {
                    "FilePath": "[joinpath(variable('Solr.Core.Master.Conf'), 'managed-schema')]",
                    "Xpath": "[variable('Solr.Xpath.UniqueKey')]",
                    "Value": "[variable('Solr.UniqueField')]"
                },
                {
                    "FilePath": "[joinpath(variable('Solr.Core.Web.Conf'), 'managed-schema')]",
                    "Xpath": "[variable('Solr.Xpath.UniqueKey')]",
                    "Value": "[variable('Solr.UniqueField')]"
                }
            ]
        },
        "StartSolr": {
            "Description": "Starts the Solr service.",
            "Type": "ManageService",
            "Params": {
                "Name": "[parameter('SolrService')]",
                "Status": "Running",
                "PostDelay": 8000
            }
        },
        "CreateCores": {
            "Description": "Tells Solr to create the new cores.",
            "Type": "ManageSolrCore",
            "Params": [
                {
                    "Action": "Create",
                    "Address": "[parameter('SolrUrl')]",
                    "Arguments": {
                        "name": "[variable('Solr.Core.Master.Name')]",
                        "property.update.autoCreateFields": "false"
                    }
                },
                {
                    "Action": "Create",
                    "Address": "[parameter('SolrUrl')]",
                    "Arguments": {
                        "name": "[variable('Solr.Core.Web.Name')]",
                        "property.update.autoCreateFields": "false"
                    }
                }
            ]
        }
    }
}