コード例 #1
0
        public Task Terms()
        {
            var name      = GetQueryStringValueAndAssertIfSingleAndNotEmpty("name");
            var field     = GetQueryStringValueAndAssertIfSingleAndNotEmpty("field");
            var fromValue = GetStringQueryString("fromValue", required: false);

            using (var token = CreateTimeLimitedOperationToken())
                using (Database.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                    using (context.OpenReadTransaction())
                    {
                        var existingResultEtag = GetLongFromHeaders("If-None-Match");

                        var runner = new QueryRunner(Database, context);

                        var result = runner.ExecuteGetTermsQuery(name, field, fromValue, existingResultEtag, GetPageSize(), context, token);

                        if (result.NotModified)
                        {
                            HttpContext.Response.StatusCode = (int)HttpStatusCode.NotModified;
                            return(Task.CompletedTask);
                        }

                        HttpContext.Response.Headers[Constants.Headers.Etag] = CharExtensions.ToInvariantString(result.ResultEtag);

                        using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                        {
                            writer.WriteTermsQueryResult(context, result);
                        }

                        return(Task.CompletedTask);
                    }
        }
コード例 #2
0
ファイル: IndexHandler.cs プロジェクト: Danielle9897/ravendb
        public Task Terms()
        {
            var name      = GetQueryStringValueAndAssertIfSingleAndNotEmpty("name");
            var field     = GetQueryStringValueAndAssertIfSingleAndNotEmpty("field");
            var fromValue = GetStringQueryString("fromValue", required: false);

            DocumentsOperationContext context;

            using (var token = CreateTimeLimitedOperationToken())
                using (Database.DocumentsStorage.ContextPool.AllocateOperationContext(out context))
                    using (context.OpenReadTransaction())
                    {
                        var existingResultEtag = GetLongFromHeaders("If-None-Match");

                        var runner = new QueryRunner(Database, context);

                        var result = runner.ExecuteGetTermsQuery(name, field, fromValue, existingResultEtag, GetPageSize(Database.Configuration.Core.MaxPageSize), context, token);

                        if (result.NotModified)
                        {
                            HttpContext.Response.StatusCode = (int)HttpStatusCode.NotModified;
                            return(Task.CompletedTask);
                        }

                        HttpContext.Response.Headers[Constants.MetadataEtagField] = result.ResultEtag.ToInvariantString();

                        using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                        {
                            writer.WriteStartArray();
                            var isFirst = true;
                            foreach (var term in result.Terms)
                            {
                                if (isFirst == false)
                                {
                                    writer.WriteComma();
                                }

                                isFirst = false;

                                writer.WriteString((term));
                            }

                            writer.WriteEndArray();
                        }

                        return(Task.CompletedTask);
                    }
        }