BlendInteractive.Solr.Optimizely 1.1.0

Prefix Reserved
dotnet add package BlendInteractive.Solr.Optimizely --version 1.1.0
                    
NuGet\Install-Package BlendInteractive.Solr.Optimizely -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BlendInteractive.Solr.Optimizely" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BlendInteractive.Solr.Optimizely" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="BlendInteractive.Solr.Optimizely" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BlendInteractive.Solr.Optimizely --version 1.1.0
                    
#r "nuget: BlendInteractive.Solr.Optimizely, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BlendInteractive.Solr.Optimizely@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BlendInteractive.Solr.Optimizely&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=BlendInteractive.Solr.Optimizely&version=1.1.0
                    
Install as a Cake Tool

Blend Interactive's Solr integration

This repo contains a basic Solr integration implementation for Optimizely CMS 12. It is a ground-up rewrite of our CMS 11 implementation. If you are migrating from the CMS 11 version, not all features have been migrated over and there may be some gaps to fill.

While Issues and Pull Requets are welcome, Blend makes no guarantees about maintaining this library or responding quickly.

Installation and Usage

To install:

  1. Install the BlendInteractive.Solr.Optimizely nuget package.
  2. Optionally, create a custom Solr document type with the custom fields you wish to use. (Note: if using the default document, use SolrDocument instead of your custom class.)
    public class CustomSolrDocument : SolrDocument
    {
        [SolrField("headline_s")]
        public string? Headline { get; set; }
    }
  1. Add Solr services to your start up class.
        services
            .AddSolrNet<CustomSolrDocument>("http://localhost:8983/solr/example") // Adding a core for the `CustomSolrDocument` document type.
            .AddOptimizelySolr<CustomSolrDocument>() // Adds the Optimizely related services
            .AddCmsAspNetIdentity<ApplicationUser>()
            .AddCms()
            .AddAdminUserRegistration()
            .AddEmbeddedLocalization<Startup>();
  1. Add the synchronization events for your Solr document type:
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IContentEvents contentEvents)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseStaticFiles();
        app.UseRouting();
        app.UseAuthentication();
        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapContent();
        });

        contentEvents.SynchronizeSolr<CustomSolrDocument>(); // Adds content events to synchronize Solr documents
    }
  1. Configure your models to add their content to the full-text field for searching by implementing IHaveFullText:
    public T AddContent<T>(T builder) where T : FullTextBuilder
        => builder
            .AddText(Headline)
            .AddHtml(Body)
            .AddContentArea(Content);
  1. Optionally, you can set any custom fields by implementing IHaveCustomSolrDocument<> on your models:
    void IHaveCustomSolrDocument<CustomSolrDocument>.ApplyTo(CustomSolrDocument doc)
    {
        doc.Headline = Headline;
    }
  1. Optionally, you can exclude content from the index by implementing IExcludeFromSearch on your model:
    public bool ExcludeFromSearch => true;
  1. Finally, create a new OptimizelyQuery<> of your document type, and execute the search with the SolrSearchService<> service:
    // Query the full text and Headline, boosting headline a bit.
    var query = new OptimizelyQuery<CustomSolrDocument>(q, 
        new QueryField(SolrDocument.FieldNames.Text, 1),
        new QueryField(CustomSolrDocument.CustomFieldNames.Headline, 2)
    );

    // Only published, public pages, in the current language, under the current site.
    query
        .WithDefaults()
        .InLanguage(currentContent.Language.Name)
        .PagesOnly()
        .WithinSite(SiteDefinition.Current.Id);

    // Pagination
    page = Math.Max(0, page);
    var limit = new Limit(page * PageWeight, PageWeight);

    var results = searchService.ExecuteQuery(query, limit);

Reindex all content

If you'd like a scheduled job to reindex all content, add a new scheduled job to your project and extend AbstractSolrReindexScheduledJob<> for your document type. No logic is needed in the scheduled job. For example:

    [ScheduledPlugIn(
        DisplayName = "Reindex all content in Solr",
        DefaultEnabled = true,
        GUID = "eee2bc6d-2be1-4d35-8b1c-166c39bf4671")]
    public class SolrReindexScheduledJob : AbstractSolrReindexScheduledJob<CustomSolrDocument>
    {
        public SolrReindexScheduledJob(SolrSynchronizationUtility<CustomSolrDocument> synchronizationUtility, ISiteDefinitionRepository siteDefinitionRepository, IContentLoader contentLoader, ILanguageBranchRepository languageBranchRepository) : base(synchronizationUtility, siteDefinitionRepository, contentLoader, languageBranchRepository)
        {
        }
    }
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 189 9/5/2024