Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Greg 9 posts 79 karma points
    15 days ago
    Greg
    0

    Inconsitent results from Examine.

    I'm having some fun and games with Examine. I've packaged up a little query in a class and I'm injecting it into a couple of places. It's been working fine all day but has just starteded giving flaky results (maybe the last hour or so). As you can see below, there's barely anything to the query and I haven't changed anything since this morning, I'm working on the results page.

    Here's the query

    public class CategoryContentQuery : ICategoryContentQuery
    {
        private readonly IExamineManager _examineManager;
    
        public CategoryContentQuery(IExamineManager examineManager)
        {
            _examineManager = examineManager ?? throw new ArgumentNullException(nameof(examineManager));
        }
    
        public ISearchResults Execute(string searchTerm)
        {
            if (_examineManager.TryGetIndex(Constants.UmbracoIndexes.ExternalIndexName, out var index))
            {
                var searcher = index.GetSearcher();
                var results = searcher.CreateQuery().Field("parsedCategory", searchTerm)
                    .Execute();
                return results;
            }
    
            return null;
        }
    }
    

    I'm using this query in two places, in a ContentFinder, to check if the category exists (is there any content in the index with that category?), and then in the category page to actually show the content.

    The flakiness presents in two ways:

    1) When I call the query in the ContentFinder it returns zero results, in which case the ContentFinder returns 404. This happens about 20% of the time, but...

    2) ~80% of the time the ContentFinder will get results back and so display the category page. Then when I execute the query again in the controller I get zero results back and my listing is empty.

    Maybe about 1% of the time I'll get results in my page.

    Has anyone else experienced this kinds of flakiness with Examine?

    I've rebuilt the index, there's 281 documents and 53 fields in there. I can open the index using Luke and browse the documents, and query the index and get results, so the index seems fine.

    Any suggestions welcome!

  • Marc Goodson 1601 posts 10654 karma points MVP 6x c-trib
    1 week ago
    Marc Goodson
    0

    Hi Greg

    It sounds like it could be a race condition, and therefore perhaps the absence of a scope in the ContentFinder? (but I am totally guessing!)

    Have you tried wrapping your call inside the ContentFinder to use Examine inside a scope?

     using (_scopeProvider.CreateScope(autoComplete: true))
     {
             // Do your examine reading stuff here
     }
    

    There is an answer here that gives a bit of context:

    https://our.umbraco.com/forum/using-umbraco-and-getting-started/102676-triggering-index-rebuild-via-hangfire-causes-objectdisposedexception-in-nucache#comment-321129

    just made me think that at the ContentFinder stage you may not be sure of the existance of scope/cache etc...

    but apologies if it's wide of the mark!

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft