In addition a previous post that covered provisioning standard search, this post describes how to provision Ontolica search center configuration to your site.

Steps
The following steps can be used to create your Ontolica feature.

  • Configure your Ontolica settings on your environment.
  • Get the configuration files from the OntolicaConfig document library.
  • Get the xslt from your OntolicaStyles library.
  • Create a site scoped feature.

Scope
The documentation states that Farm and Application-level settings are stored in the property bag. To move those they refer to the SharePoint documentation for details about how to work with the property bag. But in general, you will probably don't need to do this. This example shows the provisioning of the sitecollection and site configs and xslt.

Getting the configuration
Sitecollection level settings are stored as XML files in a hidden document library at the root of the site collection. Sub site settings are stored in there as well. There is one XML file for each subsite where Ontolica settings have been made.

To access the hidden document library that holds the Ontolica configuration files for a given site collection and its sub-sites, enter the following URL into a browser:

http://<SiteCollectionRoot>/OntolicaConfig

Where <SiteCollectionRoot> is the top-level URL of your site collection.

Note: Be sure to update any statuc urls inside of the configuration file or modify the provisioning code to update them to the current site. This can happen when you are using lookup fields.

Getting the XSL
The xsl stylesheets are located in the Ontolica Style library, for each module there is a folder where the stylesheets are located.

http://<SiteCollectionRoot>/OntolicaStyles

Where <SiteCollectionRoot> is the top-level URL of your site collection.


Create feature 
Create a site scoped feature and add the xml and xsl files to feature elements, you could either use the module/file tag and provision the files to the Ontolica libraries or use code, with which you can explicitly overwrite the current files that exist there. Be sure that the folders are the same as the folders created by Ontolica.

Folder structure

  • My Feature Folder\
    • OntolicaConfig\
      • OntolicaSearchConfig_Root.xml
      • OntolicaSearchConfig_SiteName.xml
    • OntolicaStyles\
      • Search Summary
        • DefaultActions.xsl
      • Search Tabs
        • Default.xsl
    • elements.xml
    • feature.xml


Feature code
This code is an example of how to provision the xml and xsl files to the Ontolica libraries:

// Provision Ontolica style and config files.
ProvisionFolderContent(Path.Combine(properties.Definition.RootDirectory, "OntolicaStyles"), SPUrlUtility.CombineUrl(site.RootWeb.Url, "OntolicaStyles"), true);
ProvisionFolderContent(Path.Combine(properties.Definition.RootDirectory, "OntolicaConfig"), SPUrlUtility.CombineUrl(site.RootWeb.Url, "OntolicaConfig"), true);

/// <summary>
/// Provisions the content of the folder.
/// </summary>
/// <param name="source" />The source.</param>
/// <param name="destination" />The destination.</param>
/// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
public void ProvisionFolderContent(string source, string destination, bool overwrite)
{
   if (Directory.Exists(source))
   {
      string[] files = Directory.GetFiles(source);
     
string[] directories = Directory.GetDirectories(source);

      foreach (string directory in directories)
      {
         ProvisionFolderContent(directory, SPUrlUtility.CombineUrl(destination, Path.GetFileName(directory)), overwrite);
      }

      foreach (string file in files)
      {
         using (SPSite site = new SPSite(destination))
         {

            using (SPWeb web = site.OpenWeb())
         
  {
              
SPFolder folder = web.GetFolder(destination);

               if (folder != null)
               {
                  folder.Files.Add(Path.GetFileName(file), File.OpenRead(file), overwrite);
               }
           }
       }
   }
}
 

 

Tags: , , ,