public async Task InvokeAsync(HttpContext context)
        {
            // Extract criteria from query string
            var currentCriteria =
                new SearchCurrentCriteria
            {
                Term  = context.Request.Query["q"],
                Limit = context.Request.Query["ps"].ParseInt()
            };

            var queryDefinition = new SearchQuery();

            if (currentCriteria.Limit.HasValue)
            {
                queryDefinition = queryDefinition.Limit(currentCriteria.Limit.Value);
            }

            if (!string.IsNullOrEmpty(currentCriteria.Term))
            {
                queryDefinition = queryDefinition.TermQuery("text", currentCriteria.Term);
            }

            // Do search
            var result = await searchIndex.SearchAsync(queryDefinition);

            result.CurrentCriteria = currentCriteria;

            context.AddSearchResult(result);

            // Call the next delegate/middleware in the pipeline
            await _next(context);
        }