Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TotalItemCount property performance #324

Open
Sven883 opened this issue Dec 23, 2022 · 1 comment
Open

TotalItemCount property performance #324

Sven883 opened this issue Dec 23, 2022 · 1 comment
Labels

Comments

@Sven883
Copy link

Sven883 commented Dec 23, 2022

Hello!

We're using Umbraco v8.14.1 with Examine dll v1.2.2.0 & Lucene v3.0.3.
We're also using this package for our search functionality of the website: https://github.com/skttl/umbraco-fulltextsearch8
I've been debugging for a while using the Umbraco mini profiler and I've noticed one line of code slowing down the whole code by a lot.

First we get the results, no issues there with a maxResults of 12
var results = searcher.CreateQuery().NativeQuery(query.ToString()).Execute(_search.PageLength * _currentPage);

results type is 'Examine.ISearchResults'

The slow code:
result.TotalResults = results.TotalItemCount;

Our indexCreator:

public class NewsIndexCreator : LuceneIndexCreator
    {
        private readonly IProfilingLogger _profilingLogger;
        private readonly ILocalizationService _localizationService;
        private readonly IPublicAccessService _publicAccessService;


        public NewsIndexCreator(IProfilingLogger profilingLogger,
            ILocalizationService localizationService,
            IPublicAccessService publicAccessService
        )
        {
            _profilingLogger = profilingLogger;
            _localizationService = localizationService;
            _publicAccessService = publicAccessService;
        }

        public override IEnumerable<IIndex> Create()
        {

            var fieldDefinitionCollection = new FieldDefinitionCollection();

            foreach(var language in _localizationService.GetAllLanguages())
            {
                fieldDefinitionCollection.AddOrUpdate(new FieldDefinition($"updateDate_{language.CultureInfo}_sort", FieldDefinitionTypes.DateTime));
                fieldDefinitionCollection.AddOrUpdate(new FieldDefinition($"createDate_{language.CultureInfo}_sort", FieldDefinitionTypes.DateTime));
                fieldDefinitionCollection.AddOrUpdate(new FieldDefinition($"sortDate_{language.CultureInfo}_sort", FieldDefinitionTypes.DateTime));
            }

            var index = new UmbracoContentIndex("NewsIndex",
                CreateFileSystemLuceneDirectory("NewsIndex"),
                fieldDefinitionCollection,
                new StandardAnalyzer(Version.LUCENE_30),
                _profilingLogger,
                _localizationService,
                new ContentValueSetValidator(true, false, _publicAccessService, includeItemTypes: new string[] { "newsItem" }));
            return new[] { index };

        }
    }

Any ideas how we could fix this problem?
Thanks in advance and happy holidays!

@Shazwazza
Copy link
Owner

Hi, Examine will execute the Lucene query lazily one time when either TotalItemCount is resolved, or when the search results are enumerated. My gut feeling is that you are resolving TotalItemCount first which will seem to indicate the performance problem is reading that property, however what is most likely occurring is that it is executing the search at that time.

I'm not sure if you are doing paging correctly, here's an example: https://github.com/Shazwazza/Examine/blob/release/2.0/src/Examine.Test/Examine.Lucene/Search/FluentApiTests.cs#L2372

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants