Skip to content

Random Examine index failure #413

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

Closed
gordonsaxby opened this issue Apr 8, 2025 · 1 comment
Closed

Random Examine index failure #413

gordonsaxby opened this issue Apr 8, 2025 · 1 comment

Comments

@gordonsaxby
Copy link

Umbraco v10.8.8, hosted on Azure

It appears to be random, but we sometimes get this error.

System.NullReferenceException: Object reference not set to an instance of an object.
   at Lucene.Net.QueryParsers.Classic.QueryParser.Jj_add_error_token(Int32 kind, Int32 pos)
   at Lucene.Net.QueryParsers.Classic.QueryParser.Jj_scan_token(Int32 kind)
   at Lucene.Net.QueryParsers.Classic.QueryParser.Jj_3R_3()
   at Lucene.Net.QueryParsers.Classic.QueryParser.Jj_rescan_token()
   at Lucene.Net.QueryParsers.Classic.QueryParser.GenerateParseException()
   at Lucene.Net.QueryParsers.Classic.QueryParser.Jj_consume_token(Int32 kind)
   at Lucene.Net.QueryParsers.Classic.QueryParser.Clause(String field)
   at Lucene.Net.QueryParsers.Classic.QueryParser.Query(String field)
   at Lucene.Net.QueryParsers.Classic.QueryParser.TopLevelQuery(String field)
   at Lucene.Net.QueryParsers.Classic.QueryParserBase.Parse(String query)
   at Examine.Lucene.Search.LuceneSearchQueryBase.GetFieldInternalQuery(String fieldName, IExamineValue fieldValue, Boolean useQueryParser)
   at Examine.Lucene.Search.LuceneSearchQuery.Search(QueryOptions options)
   at Examine.Lucene.Search.LuceneBooleanOperation.Execute(QueryOptions options)

The only way to solve it is to manually delete the Examine folders and restart the website.

The code is below and it fails on "query.Execute":

        try
        {
            var events = new List<IPublishedContent?>();
            totalEvents = 0;

            startDate = startDate ?? DateTime.Now.Date;
            endDate = endDate ?? DateTime.MaxValue;

            if (_examineManager.TryGetIndex(AppConstants.Events.IndexName, out var index))
            {
                var searcher = index.Searcher;
                var query = searcher
                    .CreateQuery(IndexTypes.Content)
                    .NodeTypeAlias(EventPage.ModelTypeAlias)
                    .And()
                    .Field("pathSearchable", rootNodeId.ToString());

                query = query
                    .And()
                    .RangeQuery(new[] { AppConstants.Events.InstanceSearchableField }, startDate, endDate);

                if (categories?.Any() == true)
                {
                    query = query
                        .And()
                        .GroupedOr(new[] { AppConstants.Events.CategorySearchableField }, categories);
                }

                query.OrderBy(new SortableField(AppConstants.Events.FirstInstanceSearchableField, SortType.Long));

                var results = query.Execute(new QueryOptions(pageSize * (pageIndex - 1), pageSize));

                if (_umbracoContextAccessor.TryGetUmbracoContext(out var umbracoContext))
                {
                    foreach (var result in results)
                    {
                        var publishedContent = umbracoContext.Content?.GetById(int.Parse(result.Id));
                        if (publishedContent == null)
                            continue;

                        events.Add(publishedContent);
                    }

                    totalEvents = (int)results.TotalItemCount;
                }
            }

            return events;
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, $"EventsService:GetPagedBlogPosts failed - {ex}");

            totalEvents = 0;
            return new List<IPublishedContent>();
        }

@Shazwazza
Copy link
Owner

Sorry for the delay but this is fixed in later Examine versions, just make sure you're on the latest. Problem is because of concurrent access to a QueryParser which shouldn't be done.

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

No branches or pull requests

2 participants