SDKits / ExamineX

Issue tracker for ExamineX
https://examinex.online
5 stars 0 forks source link

Create custom index without document result ExamineX 4.0.0-beta.2 Umbraco 10.1.0 #70

Closed sasetkaKmd closed 1 year ago

sasetkaKmd commented 2 years ago

My code that works on Examine and show documents, but on ExamineX I got exception

System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object. Source=ExamineX.AzureSearch.Umbraco StackTrace: at ExamineX.AzureSearch.Umbraco.UmbracoAzureSearchContentIndex.A(ValueSet ) at System.Linq.Lookup2.Create(IEnumerable1 source, Func2 keySelector, IEqualityComparer1 comparer) at System.Linq.GroupedEnumerable2.ToArray() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.OrderedEnumerable1.d__17.MoveNext() at ExamineX.AzureSearch.Umbraco.UmbracoAzureSearchContentIndex.PerformIndexItems(IEnumerable1 values, Action1 onComplete) at Umbraco.Core.Search.Indexes.CustomIndex.Examine.IIndex.IndexItems(IEnumerable1 values) in C:\Umbraco.Core\Search\Indexes\CustomIndex.cs:line 43 at Umbraco.Cms.Infrastructure.Examine.ContentIndexPopulator.IndexAllContent(Int32 contentParentId, Int32 pageIndex, Int32 pageSize, IReadOnlyList1 indexes) at Umbraco.Cms.Infrastructure.Examine.ContentIndexPopulator.PopulateIndexes(IReadOnlyList`1 indexes) at Umbraco.Cms.Infrastructure.Examine.IndexPopulator.Populate(IIndex[] indexes) at Umbraco.Cms.Infrastructure.Examine.ExamineIndexRebuilder.RebuildIndexes(Boolean onlyEmptyIndexes, TimeSpan delay, CancellationToken cancellationToken)

There should be 22 documents.

image


 public class CustomIndex : UmbracoAzureSearchContentIndex, IUmbracoContentIndex, IDisposable, IIndex
    {
        public CustomIndex(
             ILoggerFactory loggerFactory,
             string name,
             IOptions<ExamineXConfig> config,
             IOptionsMonitor<AzureSearchIndexOptions> indexOptions,
             ILicenseManager licenceManager,
             IServerRoleAccessor serverRoleAccessor) :
             base(loggerFactory, name, licenceManager, config, indexOptions,serverRoleAccessor )
        {
            loggerFactory.CreateLogger<CustomIndexDa>();

            AzureSearchIndexOptions namedOptions = indexOptions.Get(name);
            if (namedOptions == null)
            {
                throw new InvalidOperationException($"No named {typeof(AzureSearchIndexOptions)} options with name {name}");
            }

            if (namedOptions.Validator is IContentValueSetValidator contentValueSetValidator)
            {
                PublishedValuesOnly = contentValueSetValidator.PublishedValuesOnly;
            }
        }

      void IIndex.IndexItems(IEnumerable<ValueSet> values) => 
            PerformIndexItems(
                values.Where(v => v.ItemType == "contentPage") , OnIndexOperationComplete);
}

    public class IndexHelperComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder)
        {
            IServiceCollection services = builder.Services;

            services
                .AddExamineXAzureSearchIndex<CustomIndex>("CustomExamineIndex");
        }
    }
}

Could you help me with this?

Shazwazza commented 2 years ago

Why are you creating a custom index implementation? Why not just filter items that are not "contentPage" with events or validators?

hallojoe commented 1 year ago

@Shazwazza We got things running.

We need a custom index for virtual pages(pages powered by external content with no content node). I would like for virtual pages to go into ExternalIndex, but I lack knowledge about how to go on about that.

Shazwazza commented 1 year ago

@hallojoe I see. In that case you must have a mechanism for keeping the external content in-sync with the index? - I hope you aren't rebuilding the index each time just to keep it in sync? The Examine API that is used to push data to the index is IIndex.IndexItems. I assume this is what you are using for your custom index but in that case, you can just push this data to the External index but will need to make sure that the document ID doesn't overlap with an existing Umbraco INT Id.

Shazwazza commented 1 year ago

Hi @hallojoe, can I go ahead and close this ticket? Can you describe how you got it working and what the underlying issue was?

hallojoe commented 1 year ago

@Shazwazza This can be closed. I cannot point out the exact problem related to this issue. I believe that @sasetkaKmd ran into the issue of "no analyzer set by default" as described in #71. We needed a custom content index for virtual pages, and I managed to write code to do so. Looking forward to trying out 4.0 RTM.