Skip to content

Commit

Permalink
chore: move services from infrastructure to search project, so search…
Browse files Browse the repository at this point in the history
… project is indepedant
  • Loading branch information
bielu1 committed Feb 18, 2023
1 parent d1e25b1 commit e984791
Show file tree
Hide file tree
Showing 43 changed files with 129 additions and 374 deletions.
7 changes: 5 additions & 2 deletions src/Umbraco.Core/Models/Search/IUmbracoSearchResult.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
namespace Umbraco.Cms.Core.Models.Search;

public class IUmbracoSearchResult
public interface IUmbracoSearchResult
{

public int Id { get; set; }

public float Score { get; set; }
public IDictionary<string, IList<object>> Values { get; set; }
}
6 changes: 0 additions & 6 deletions src/Umbraco.Core/Services/IExamineIndexCountService.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Examine;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -50,7 +49,6 @@
using Umbraco.Cms.Infrastructure.Runtime;
using Umbraco.Cms.Infrastructure.Runtime.RuntimeModeValidators;
using Umbraco.Cms.Infrastructure.Scoping;
using Umbraco.Cms.Infrastructure.Search;
using Umbraco.Cms.Infrastructure.Serialization;
using Umbraco.Cms.Infrastructure.Services.Implement;
using Umbraco.Extensions;
Expand Down Expand Up @@ -168,7 +166,6 @@ public static IUmbracoBuilder AddCoreInitialServices(this IUmbracoBuilder builde

builder.Services.AddSingleton<IContentLastChanceFinder, ContentFinderByConfigured404>();

builder.Services.AddScoped<UmbracoTreeSearcher>();

// replace
builder.Services.AddSingleton<IEmailSender, EmailSender>(
Expand All @@ -179,20 +176,17 @@ public static IUmbracoBuilder AddCoreInitialServices(this IUmbracoBuilder builde
services.GetService<INotificationHandler<SendEmailNotification>>(),
services.GetService<INotificationAsyncHandler<SendEmailNotification>>()));

builder.Services.AddSingleton<IExamineManager, ExamineManager>();

builder.Services.AddScoped<ITagQuery, TagQuery>();

builder.Services.AddSingleton<IUmbracoTreeSearcherFields, UmbracoTreeSearcherFields>();
builder.Services.AddSingleton<IPublishedContentQueryAccessor, PublishedContentQueryAccessor>(sp =>
new PublishedContentQueryAccessor(sp.GetRequiredService<IScopedServiceProvider>()));
builder.Services.AddScoped<IPublishedContentQuery>(factory =>
{
IUmbracoContextAccessor umbCtx = factory.GetRequiredService<IUmbracoContextAccessor>();
IVariationContextAccessor variationContext = factory.GetRequiredService<IVariationContextAccessor>();
IUmbracoContext umbracoContext = umbCtx.GetRequiredUmbracoContext();
return new PublishedContentQuery(
umbracoContext.PublishedSnapshot,
factory.GetRequiredService<IVariationContextAccessor>(), factory.GetRequiredService<IExamineManager>());
umbracoContext.PublishedSnapshot,variationContext);
});

// register accessors for cultures
Expand All @@ -202,8 +196,6 @@ public static IUmbracoBuilder AddCoreInitialServices(this IUmbracoBuilder builde

builder.Services.AddSingleton<IUmbracoComponentRenderer, UmbracoComponentRenderer>();

builder.Services.AddSingleton<IBackOfficeExamineSearcher, NoopBackOfficeExamineSearcher>();

builder.Services.AddSingleton<UploadAutoFillProperties>();
builder.Services.AddSingleton<IImageDimensionExtractor, NoopImageDimensionExtractor>();
builder.Services.AddSingleton<IImageUrlGenerator, NoopImageUrlGenerator>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ internal static IUmbracoBuilder AddServices(this IUmbracoBuilder builder)
builder.Services.AddSingleton(CreatePackageDataInstallation);
builder.Services.AddUnique<IPackageInstallation, PackageInstallation>();
builder.Services.AddUnique<IHtmlMacroParameterParser, HtmlMacroParameterParser>();
builder.Services.AddTransient<IExamineIndexCountService, ExamineIndexCountService>();
builder.Services.AddUnique<IUserDataService, SystemInformationTelemetryProvider>();
builder.Services.AddTransient<IUsageInformationService, UsageInformationService>();
builder.Services.AddSingleton<IEditorConfigurationParser, EditorConfigurationParser>();
Expand Down
82 changes: 0 additions & 82 deletions src/Umbraco.Infrastructure/IPublishedContentQuery.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Xml.XPath;
using Examine.Search;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Xml;

Expand Down Expand Up @@ -47,85 +46,4 @@ public interface IPublishedContentQuery
IEnumerable<IPublishedContent> Media(IEnumerable<Guid> ids);

IEnumerable<IPublishedContent> MediaAtRoot();

/// <summary>
/// Searches content.
/// </summary>
/// <param name="term">The term to search.</param>
/// <param name="skip">The amount of results to skip.</param>
/// <param name="take">The amount of results to take/return.</param>
/// <param name="totalRecords">The total amount of records.</param>
/// <param name="culture">The culture (defaults to a culture insensitive search).</param>
/// <param name="indexName">
/// The name of the index to search (defaults to
/// <see cref="Constants.UmbracoIndexes.ExternalIndexName" />).
/// </param>
/// <param name="loadedFields">
/// This parameter is no longer used, because the results are loaded from the published snapshot
/// using the single item ID field.
/// </param>
/// <returns>
/// The search results.
/// </returns>
/// <remarks>
/// <para>
/// When the <paramref name="culture" /> is not specified or is *, all cultures are searched.
/// To search for only invariant documents and fields use null.
/// When searching on a specific culture, all culture specific fields are searched for the provided culture and all
/// invariant fields for all documents.
/// </para>
/// <para>While enumerating results, the ambient culture is changed to be the searched culture.</para>
/// </remarks>
IEnumerable<PublishedSearchResult> Search(
string term,
int skip,
int take,
out long totalRecords,
string culture = "*",
string indexName = Constants.UmbracoIndexes.ExternalIndexName,
ISet<string>? loadedFields = null);

/// <summary>
/// Searches content.
/// </summary>
/// <param name="term">The term to search.</param>
/// <param name="culture">The culture (defaults to a culture insensitive search).</param>
/// <param name="indexName">
/// The name of the index to search (defaults to
/// <see cref="Cms.Core.Constants.UmbracoIndexes.ExternalIndexName" />).
/// </param>
/// <returns>
/// The search results.
/// </returns>
/// <remarks>
/// <para>
/// When the <paramref name="culture" /> is not specified or is *, all cultures are searched.
/// To search for only invariant documents and fields use null.
/// When searching on a specific culture, all culture specific fields are searched for the provided culture and all
/// invariant fields for all documents.
/// </para>
/// <para>While enumerating results, the ambient culture is changed to be the searched culture.</para>
/// </remarks>
IEnumerable<PublishedSearchResult> Search(string term, string culture = "*", string indexName = Constants.UmbracoIndexes.ExternalIndexName);

/// <summary>
/// Executes the query and converts the results to <see cref="PublishedSearchResult" />.
/// </summary>
/// <param name="query">The query.</param>
/// <returns>
/// The search results.
/// </returns>
IEnumerable<PublishedSearchResult> Search(IQueryExecutor query);

/// <summary>
/// Executes the query and converts the results to <see cref="PublishedSearchResult" />.
/// </summary>
/// <param name="query">The query.</param>
/// <param name="skip">The amount of results to skip.</param>
/// <param name="take">The amount of results to take/return.</param>
/// <param name="totalRecords">The total amount of records.</param>
/// <returns>
/// The search results.
/// </returns>
IEnumerable<PublishedSearchResult> Search(IQueryExecutor query, int skip, int take, out long totalRecords);
}
16 changes: 8 additions & 8 deletions src/Umbraco.Infrastructure/Models/Mapping/EntityMapDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Globalization;
using Examine;
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Models.Entities;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Models.Search;
using Umbraco.Extensions;

namespace Umbraco.Cms.Core.Models.Mapping;
Expand All @@ -20,11 +20,11 @@ public void DefineMaps(IUmbracoMapper mapper)
mapper.Define<EntityBasic, ContentTypeSort>((source, context) => new ContentTypeSort(), Map);
mapper.Define<IContentTypeComposition, EntityBasic>((source, context) => new EntityBasic(), Map);
mapper.Define<IEntitySlim, SearchResultEntity>((source, context) => new SearchResultEntity(), Map);
mapper.Define<ISearchResult, SearchResultEntity>((source, context) => new SearchResultEntity(), Map);
mapper.Define<ISearchResults, IEnumerable<SearchResultEntity>>((source, context) =>
context.MapEnumerable<ISearchResult, SearchResultEntity>(source).WhereNotNull());
mapper.Define<IEnumerable<ISearchResult>, IEnumerable<SearchResultEntity>>((source, context) =>
context.MapEnumerable<ISearchResult, SearchResultEntity>(source).WhereNotNull());
mapper.Define<IUmbracoSearchResult, SearchResultEntity>((source, context) => new SearchResultEntity(), Map);
mapper.Define<IUmbracoSearchResults, IEnumerable<SearchResultEntity>>((source, context) =>
context.MapEnumerable<IUmbracoSearchResult, SearchResultEntity>(source).WhereNotNull());
mapper.Define<IEnumerable<IUmbracoSearchResult>, IEnumerable<SearchResultEntity>>((source, context) =>
context.MapEnumerable<IUmbracoSearchResult, SearchResultEntity>(source).WhereNotNull());
}

// Umbraco.Code.MapAll -Alias
Expand Down Expand Up @@ -195,7 +195,7 @@ private static void Map(EntitySlim source, SearchResultEntity target, MapperCont
}

// Umbraco.Code.MapAll -Alias -Trashed
private static void Map(ISearchResult source, SearchResultEntity target, MapperContext context)
private static void Map(IUmbracoSearchResult source, SearchResultEntity target, MapperContext context)
{
target.Id = source.Id;
target.Score = source.Score;
Expand All @@ -215,7 +215,7 @@ private static void Map(ISearchResult source, SearchResultEntity target, MapperC
if (culture.IsNullOrWhiteSpace() == false)
{
target.Name = source.Values.ContainsKey($"nodeName_{culture}")
? source.Values[$"nodeName_{culture}"]
? source.Values[$"nodeName_{culture}"].FirstOrDefault().ToString()
: target.Name;
}

Expand Down
Loading

0 comments on commit e984791

Please sign in to comment.