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
<PackageReference Include="BlendInteractive.Solr.Optimizely" Version="1.1.0" />
paket add BlendInteractive.Solr.Optimizely --version 1.1.0
#r "nuget: BlendInteractive.Solr.Optimizely, 1.1.0"
// Install BlendInteractive.Solr.Optimizely as a Cake Addin #addin nuget:?package=BlendInteractive.Solr.Optimizely&version=1.1.0 // Install BlendInteractive.Solr.Optimizely as a Cake Tool #tool nuget:?package=BlendInteractive.Solr.Optimizely&version=1.1.0
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:
- Install the
BlendInteractive.Solr.Optimizely
nuget package. - 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; }
}
- 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>();
- 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
}
- 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);
- Optionally, you can set any custom fields by implementing
IHaveCustomSolrDocument<>
on your models:
void IHaveCustomSolrDocument<CustomSolrDocument>.ApplyTo(CustomSolrDocument doc)
{
doc.Headline = Headline;
}
- Optionally, you can exclude content from the index by implementing
IExcludeFromSearch
on your model:
public bool ExcludeFromSearch => true;
- Finally, create a new
OptimizelyQuery<>
of your document type, and execute the search with theSolrSearchService<>
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 | Versions 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. |
-
net6.0
- BlendInteractive.Solr (>= 1.1.0)
- EPiServer.CMS.Core (>= 12.4.0 && < 13.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- SolrNet (>= 1.1.1)
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 | 126 | 9/5/2024 |