Implement selectfields for examine
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
<dependency id="ClientDependency" version="[1.9.9,1.999999)" />
|
||||
<dependency id="ClientDependency-Mvc5" version="[1.9.3,1.999999)" />
|
||||
<dependency id="CSharpTest.Net.Collections" version="[14.906.1403.1082,14.999999)" />
|
||||
<dependency id="Examine" version="[1.0.2,1.999999)" />
|
||||
<dependency id="Examine" version="[1.1.0,1.999999)" />
|
||||
<dependency id="HtmlAgilityPack" version="[1.8.14,1.999999)" />
|
||||
<dependency id="ImageProcessor" version="[2.7.0.100,2.999999)" />
|
||||
<dependency id="LightInject.Mvc" version="[2.0.0,2.999999)" />
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<!-- note: NuGet deals with transitive references now -->
|
||||
<PackageReference Include="Examine" Version="1.0.2" />
|
||||
<PackageReference Include="Examine" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub">
|
||||
<Version>1.0.0-beta2-19324-01</Version>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
||||
@@ -11,7 +11,7 @@ using Lucene.Net.Store;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Logging;
|
||||
using Examine.LuceneEngine;
|
||||
|
||||
using Examine.Search;
|
||||
namespace Umbraco.Examine
|
||||
{
|
||||
/// <summary>
|
||||
@@ -21,7 +21,7 @@ namespace Umbraco.Examine
|
||||
{
|
||||
public const string VariesByCultureFieldName = SpecialFieldPrefix + "VariesByCulture";
|
||||
protected ILocalizationService LanguageService { get; }
|
||||
|
||||
private readonly ISet<string> _idOnlyFieldSet = new HashSet<string> { "id" };
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
@@ -131,8 +131,9 @@ namespace Umbraco.Examine
|
||||
var searcher = GetSearcher();
|
||||
var c = searcher.CreateQuery();
|
||||
var filtered = c.NativeQuery(rawQuery);
|
||||
var results = filtered.Execute();
|
||||
|
||||
var selectedFields = filtered.SelectFields(_idOnlyFieldSet);
|
||||
var results = selectedFields.Execute();
|
||||
ProfilingLogger.Debug(GetType(), "DeleteFromIndex with query: {Query} (found {TotalItems} results)", rawQuery, results.TotalItemCount);
|
||||
|
||||
//need to queue a delete item for each one found
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Castle.Core" Version="4.3.1" />
|
||||
<PackageReference Include="Examine" Version="1.0.2" />
|
||||
<PackageReference Include="Examine" Version="1.1.0" />
|
||||
<PackageReference Include="HtmlAgilityPack">
|
||||
<Version>1.8.14</Version>
|
||||
</PackageReference>
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
<PackageReference Include="CSharpTest.Net.Collections" Version="14.906.1403.1082" />
|
||||
<PackageReference Include="ClientDependency" Version="1.9.9" />
|
||||
<PackageReference Include="ClientDependency-Mvc5" Version="1.9.3" />
|
||||
<PackageReference Include="Examine" Version="1.0.2" />
|
||||
<PackageReference Include="Examine" Version="1.1.0" />
|
||||
<PackageReference Include="ImageProcessor.Web" Version="4.10.0.100" />
|
||||
<PackageReference Include="ImageProcessor.Web.Config" Version="2.5.0.100" />
|
||||
<PackageReference Include="Microsoft.AspNet.Identity.Owin" Version="2.2.2" />
|
||||
|
||||
@@ -9,6 +9,31 @@ using Umbraco.Core.Xml;
|
||||
namespace Umbraco.Web
|
||||
{
|
||||
using Examine = global::Examine;
|
||||
public interface IPublishedContentQuery2 : IPublishedContentQuery
|
||||
{
|
||||
/// <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">The fields to load in the results of the search (defaults to all fields loaded).</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 = Umbraco.Core.Constants.UmbracoIndexes.ExternalIndexName, ISet<string> loadedFields = null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query methods used for accessing strongly typed content in templates
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Umbraco.Web
|
||||
/// <summary>
|
||||
/// A class used to query for published content, media items
|
||||
/// </summary>
|
||||
public class PublishedContentQuery : IPublishedContentQuery
|
||||
public class PublishedContentQuery : IPublishedContentQuery2
|
||||
{
|
||||
private readonly IPublishedSnapshot _publishedSnapshot;
|
||||
private readonly IVariationContextAccessor _variationContextAccessor;
|
||||
@@ -190,6 +190,10 @@ namespace Umbraco.Web
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<PublishedSearchResult> Search(string term, int skip, int take, out long totalRecords, string culture = "*", string indexName = Constants.UmbracoIndexes.ExternalIndexName)
|
||||
=> Search(term, skip, take, out totalRecords, culture, indexName, null);
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<PublishedSearchResult> Search(string term, int skip, int take, out long totalRecords, string culture = "*", string indexName = Constants.UmbracoIndexes.ExternalIndexName, ISet<string> loadedFields = null)
|
||||
{
|
||||
if (skip < 0)
|
||||
{
|
||||
@@ -212,7 +216,7 @@ namespace Umbraco.Web
|
||||
}
|
||||
|
||||
var query = umbIndex.GetSearcher().CreateQuery(IndexTypes.Content);
|
||||
|
||||
|
||||
IQueryExecutor queryExecutor;
|
||||
if (culture == "*")
|
||||
{
|
||||
@@ -231,6 +235,10 @@ namespace Umbraco.Web
|
||||
var fields = umbIndex.GetCultureAndInvariantFields(culture).ToArray(); // Get all index fields suffixed with the culture name supplied
|
||||
queryExecutor = query.ManagedQuery(term, fields);
|
||||
}
|
||||
if (loadedFields != null && queryExecutor is IBooleanOperation booleanOperation)
|
||||
{
|
||||
queryExecutor = booleanOperation.SelectFields(loadedFields);
|
||||
}
|
||||
|
||||
var results = skip == 0 && take == 0
|
||||
? queryExecutor.Execute()
|
||||
|
||||
@@ -19,6 +19,7 @@ using Umbraco.Core.Composing;
|
||||
using System.ComponentModel;
|
||||
using System.Threading;
|
||||
using Umbraco.Web.Scheduling;
|
||||
using Examine.Search;
|
||||
|
||||
namespace Umbraco.Web.Search
|
||||
{
|
||||
@@ -39,6 +40,7 @@ namespace Umbraco.Web.Search
|
||||
private readonly IProfilingLogger _logger;
|
||||
private readonly IUmbracoIndexesCreator _indexCreator;
|
||||
private readonly BackgroundTaskRunner<IBackgroundTask> _indexItemTaskRunner;
|
||||
private readonly ISet<string> _idOnlyFieldSet = new HashSet<string> { "id" };
|
||||
|
||||
|
||||
// the default enlist priority is 100
|
||||
@@ -425,7 +427,7 @@ namespace Umbraco.Web.Search
|
||||
while (page * pageSize < total)
|
||||
{
|
||||
//paging with examine, see https://shazwazza.com/post/paging-with-examine/
|
||||
var results = searcher.CreateQuery().Field("nodeType", id.ToInvariantString()).Execute(maxResults: pageSize * (page + 1));
|
||||
var results = searcher.CreateQuery().Field("nodeType", id.ToInvariantString()).SelectFields(_idOnlyFieldSet).Execute(maxResults: pageSize * (page + 1));
|
||||
total = results.TotalItemCount;
|
||||
var paged = results.Skip(page * pageSize);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Examine;
|
||||
using Examine.Search;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Examine;
|
||||
@@ -17,6 +18,7 @@ namespace Umbraco.Web.Search
|
||||
private readonly IIndex _index;
|
||||
private static readonly string[] IgnoreProperties = { "Description" };
|
||||
|
||||
private readonly ISet<string> _idOnlyFieldSet = new HashSet<string> { "id" };
|
||||
public GenericIndexDiagnostics(IIndex index)
|
||||
{
|
||||
_index = index;
|
||||
@@ -34,7 +36,7 @@ namespace Umbraco.Web.Search
|
||||
try
|
||||
{
|
||||
var searcher = _index.GetSearcher();
|
||||
var result = searcher.Search("test");
|
||||
var result = searcher.CreateQuery().ManagedQuery("test").SelectFields(_idOnlyFieldSet).Execute(1);
|
||||
return Attempt<string>.Succeed(); //if we can search we'll assume it's healthy
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
29
src/Umbraco.Web/Search/IUmbracoTreeSearcherFields2.cs
Normal file
29
src/Umbraco.Web/Search/IUmbracoTreeSearcherFields2.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Umbraco.Web.Search
|
||||
{
|
||||
public interface IUmbracoTreeSearcherFields2 : IUmbracoTreeSearcherFields
|
||||
{
|
||||
/// <summary>
|
||||
/// Set of fields for all node types to be loaded
|
||||
/// </summary>
|
||||
ISet<string> GetBackOfficeFieldsToLoad();
|
||||
/// <summary>
|
||||
/// Set list of fields for Members to be loaded
|
||||
/// </summary>
|
||||
ISet<string> GetBackOfficeMembersFieldsToLoad();
|
||||
/// <summary>
|
||||
/// Set of fields for Media to be loaded
|
||||
/// </summary>
|
||||
ISet<string> GetBackOfficeMediaFieldsToLoad();
|
||||
|
||||
/// <summary>
|
||||
/// Set of fields for Documents to be loaded
|
||||
/// </summary>
|
||||
ISet<string> GetBackOfficeDocumentFieldsToLoad();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Examine;
|
||||
using Examine.Search;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Core.Models;
|
||||
@@ -82,6 +83,7 @@ namespace Umbraco.Web.Search
|
||||
string type;
|
||||
var indexName = Constants.UmbracoIndexes.InternalIndexName;
|
||||
var fields = _umbracoTreeSearcherFields.GetBackOfficeFields().ToList();
|
||||
ISet<string> fieldsToLoad = null;
|
||||
|
||||
// TODO: WE should try to allow passing in a lucene raw query, however we will still need to do some manual string
|
||||
// manipulation for things like start paths, member types, etc...
|
||||
@@ -102,6 +104,10 @@ namespace Umbraco.Web.Search
|
||||
indexName = Constants.UmbracoIndexes.MembersIndexName;
|
||||
type = "member";
|
||||
fields.AddRange(_umbracoTreeSearcherFields.GetBackOfficeMembersFields());
|
||||
if (_umbracoTreeSearcherFields is IUmbracoTreeSearcherFields2 umbracoTreeSearcherFieldMember)
|
||||
{
|
||||
fieldsToLoad = umbracoTreeSearcherFieldMember.GetBackOfficeMembersFieldsToLoad();
|
||||
}
|
||||
if (searchFrom != null && searchFrom != Constants.Conventions.MemberTypes.AllMembersListId && searchFrom.Trim() != "-1")
|
||||
{
|
||||
sb.Append("+__NodeTypeAlias:");
|
||||
@@ -112,12 +118,20 @@ namespace Umbraco.Web.Search
|
||||
case UmbracoEntityTypes.Media:
|
||||
type = "media";
|
||||
fields.AddRange(_umbracoTreeSearcherFields.GetBackOfficeMediaFields());
|
||||
if (_umbracoTreeSearcherFields is IUmbracoTreeSearcherFields2 umbracoTreeSearcherFieldsMedia)
|
||||
{
|
||||
fieldsToLoad = umbracoTreeSearcherFieldsMedia.GetBackOfficeMediaFieldsToLoad();
|
||||
}
|
||||
var allMediaStartNodes = _umbracoContext.Security.CurrentUser.CalculateMediaStartNodeIds(_entityService);
|
||||
AppendPath(sb, UmbracoObjectTypes.Media, allMediaStartNodes, searchFrom, ignoreUserStartNodes, _entityService);
|
||||
break;
|
||||
case UmbracoEntityTypes.Document:
|
||||
type = "content";
|
||||
fields.AddRange(_umbracoTreeSearcherFields.GetBackOfficeDocumentFields());
|
||||
if (_umbracoTreeSearcherFields is IUmbracoTreeSearcherFields2 umbracoTreeSearcherFieldsDocument)
|
||||
{
|
||||
fieldsToLoad = umbracoTreeSearcherFieldsDocument.GetBackOfficeDocumentFieldsToLoad();
|
||||
}
|
||||
var allContentStartNodes = _umbracoContext.Security.CurrentUser.CalculateContentStartNodeIds(_entityService);
|
||||
AppendPath(sb, UmbracoObjectTypes.Document, allContentStartNodes, searchFrom, ignoreUserStartNodes, _entityService);
|
||||
break;
|
||||
@@ -136,7 +150,7 @@ namespace Umbraco.Web.Search
|
||||
return Enumerable.Empty<SearchResultEntity>();
|
||||
}
|
||||
|
||||
var result = internalSearcher.CreateQuery().NativeQuery(sb.ToString())
|
||||
var result = internalSearcher.CreateQuery().NativeQuery(sb.ToString()).SelectFields(fieldsToLoad)
|
||||
//only return the number of items specified to read up to the amount of records to fill from 0 -> the number of items on the page requested
|
||||
.Execute(Convert.ToInt32(pageSize * (pageIndex + 1)));
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using Umbraco.Examine;
|
||||
|
||||
namespace Umbraco.Web.Search
|
||||
{
|
||||
public class UmbracoTreeSearcherFields : IUmbracoTreeSearcherFields
|
||||
public class UmbracoTreeSearcherFields : IUmbracoTreeSearcherFields2
|
||||
{
|
||||
private IReadOnlyList<string> _backOfficeFields = new List<string> {"id", "__NodeId", "__Key"};
|
||||
public IEnumerable<string> GetBackOfficeFields()
|
||||
@@ -27,5 +27,29 @@ namespace Umbraco.Web.Search
|
||||
{
|
||||
return Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
private readonly ISet<string> _backOfficeFieldsToLoad = new HashSet<string> { "id", "__NodeId", "__Key" };
|
||||
public ISet<string> GetBackOfficeFieldsToLoad()
|
||||
{
|
||||
return _backOfficeFieldsToLoad;
|
||||
}
|
||||
|
||||
private readonly ISet<string> _backOfficeMembersFieldsToLoad = new HashSet<string> { "id", "__NodeId", "__Key", "email", "loginName" };
|
||||
public ISet<string> GetBackOfficeMembersFieldsToLoad()
|
||||
{
|
||||
return _backOfficeMembersFieldsToLoad;
|
||||
}
|
||||
|
||||
private readonly ISet<string> _backOfficeMediaFieldsToLoad = new HashSet<string> { "id", "__NodeId", "__Key", UmbracoExamineIndex.UmbracoFileFieldName };
|
||||
public ISet<string> GetBackOfficeMediaFieldsToLoad()
|
||||
{
|
||||
return _backOfficeMediaFieldsToLoad;
|
||||
}
|
||||
private readonly ISet<string> _backOfficeDocumentFieldsToLoad = new HashSet<string> { "id", "__NodeId", "__Key" };
|
||||
|
||||
public ISet<string> GetBackOfficeDocumentFieldsToLoad()
|
||||
{
|
||||
return _backOfficeDocumentFieldsToLoad;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ClientDependency" Version="1.9.9" />
|
||||
<PackageReference Include="CSharpTest.Net.Collections" Version="14.906.1403.1082" />
|
||||
<PackageReference Include="Examine" Version="1.0.2" />
|
||||
<PackageReference Include="Examine" Version="1.1.0" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.8.14" />
|
||||
<PackageReference Include="HtmlSanitizer">
|
||||
<Version>4.0.217</Version>
|
||||
@@ -284,6 +284,7 @@
|
||||
<Compile Include="Search\ExamineFinalComposer.cs" />
|
||||
<Compile Include="Search\ExamineUserComponent.cs" />
|
||||
<Compile Include="Search\IUmbracoTreeSearcherFields.cs" />
|
||||
<Compile Include="Search\IUmbracoTreeSearcherFields2.cs" />
|
||||
<Compile Include="Search\UmbracoTreeSearcherFields.cs" />
|
||||
<Compile Include="Security\BackOfficeExternalLoginProviderErrorMiddlware.cs" />
|
||||
<Compile Include="Security\BackOfficeExternalLoginProviderErrors.cs" />
|
||||
|
||||
Reference in New Issue
Block a user