Пример #1
0
        public IActionResult GetDocuments(VolumeQuery volumeQuery, [FromQuery] int?start = 0, [FromQuery] int?count = 50)
        {
            if (!TryGetSession(User, out Session session))
            {
                return(Unauthorized());
            }

            if (volumeQuery == null)
            {
                return(BadRequest(Resources.ErrorEmptyRequest));
            }

            VolumeState volumeState = new VolumeState(
                volumeQuery.VolumeName,
                volumeQuery.FilterQuery,
                volumeQuery.SortOrder,
                volumeQuery.Search
                );

            DocumentsResult docsResult = session.GetDocuments(volumeState, start ?? 0, count ?? 50);

            return(Ok(docsResult));
        }
Пример #2
0
        public override void LoadModelParameters(string parameters)
        {
            var urlParser = new UrlParser(parameters);

            ClearCurrentQuery();

            if (urlParser.GetQueryParam("mode") == "dynamic")
            {
                var collection = urlParser.GetQueryParam("collection");

                IsDynamicQuery = true;
                DatabaseCommands.GetTermsAsync("Raven/DocumentsByEntityName", "Tag", "", 100)
                .ContinueOnSuccessInTheUIThread(collections =>
                {
                    DynamicOptions.Match(new[] { "AllDocs" }.Concat(collections).ToArray());

                    string selectedOption = null;
                    if (!string.IsNullOrEmpty(collection))
                    {
                        selectedOption = DynamicOptions.FirstOrDefault(s => s.Equals(collection));
                    }

                    if (selectedOption == null)
                    {
                        selectedOption = DynamicOptions[0];
                    }

                    DynamicSelectedOption = selectedOption;
                    DocumentsResult.SetChangesObservable(null);
                });

                return;
            }

            IsDynamicQuery = false;
            IndexName      = urlParser.Path.Trim('/');

            DatabaseCommands.GetIndexAsync(IndexName)
            .ContinueOnUIThread(task =>
            {
                if (task.IsFaulted || task.Result == null)
                {
                    IndexDefinitionModel.HandleIndexNotFound(IndexName);
                    return;
                }
                var fields             = task.Result.Fields;
                QueryIndexAutoComplete = new QueryIndexAutoComplete(fields, IndexName, QueryDocument);

                const string spatialindexGenerateLegacy = "SpatialIndex.Generate";
                const string spatialindexGenerate       = "SpatialGenerate";

                IsSpatialQuerySupported =
                    task.Result.Maps.Any(x => x.Contains(spatialindexGenerate) || x.Contains(spatialindexGenerateLegacy)) ||
                    (task.Result.Reduce != null && (task.Result.Reduce.Contains(spatialindexGenerate) || task.Result.Reduce.Contains(spatialindexGenerateLegacy)));
                HasTransform = !string.IsNullOrEmpty(task.Result.TransformResults);

                DocumentsResult.SetChangesObservable(
                    d => d.IndexChanges
                    .Where(n => n.Name.Equals(indexName, StringComparison.InvariantCulture))
                    .Select(m => Unit.Default));

                SetSortByOptions(fields);
                RestoreHistory();
            }).Catch();
        }
Пример #3
0
        public override void LoadModelParameters(string parameters)
        {
            var urlParser = new UrlParser(parameters);

            UpdateAvailableIndexes();
            ClearCurrentQuery();

            if (urlParser.GetQueryParam("mode") == "dynamic")
            {
                var collection = urlParser.GetQueryParam("collection");

                IsDynamicQuery = true;
                DatabaseCommands.GetTermsAsync("Raven/DocumentsByEntityName", "Tag", "", 100)
                .ContinueOnSuccessInTheUIThread(collections =>
                {
                    DynamicOptions.Match(new[] { "AllDocs" }.Concat(collections).ToArray());

                    string selectedOption = null;
                    if (!string.IsNullOrEmpty(collection))
                    {
                        selectedOption = DynamicOptions.FirstOrDefault(s => s.Equals(collection));
                    }

                    if (selectedOption == null)
                    {
                        selectedOption = DynamicOptions[0];
                    }

                    DynamicSelectedOption = selectedOption;
                    DocumentsResult.SetChangesObservable(null);
                });

                return;
            }

            IsDynamicQuery = false;
            var newIndexName = urlParser.Path.Trim('/');

            if (string.IsNullOrEmpty(newIndexName))
            {
                if (AvailableIndexes.Any())
                {
                    NavigateToIndexQuery(AvailableIndexes.FirstOrDefault());
                    return;
                }
            }

            IndexName = newIndexName;

            DatabaseCommands.GetIndexAsync(IndexName)
            .ContinueOnUIThread(task =>
            {
                if (task.IsFaulted || task.Result == null)
                {
                    if (AvailableIndexes.Any())
                    {
                        NavigateToIndexQuery(AvailableIndexes.FirstOrDefault());
                    }
                    else
                    {
                        NavigateToIndexesList();
                    }
                    return;
                }

                var fields             = task.Result.Fields;
                QueryIndexAutoComplete = new QueryIndexAutoComplete(fields, IndexName, QueryDocument);

                var regex1 = new Regex(@"(?:SpatialIndex\.Generate|SpatialGenerate)");
                var regex2 = new Regex(@"(?:SpatialIndex\.Generate|SpatialGenerate)\(@?\""([^\""]+)\""");

                var strs = task.Result.Maps.ToList();
                if (task.Result.Reduce != null)
                {
                    strs.Add(task.Result.Reduce);
                }

                var legacyFields = new HashSet <string>();
                foreach (var map in task.Result.Maps)
                {
                    var count   = regex1.Matches(map).Count;
                    var matches = regex2.Matches(map).Cast <Match>().Select(x => x.Groups[1].Value).ToList();
                    if (matches.Count < count)
                    {
                        legacyFields.Add(Constants.DefaultSpatialFieldName);
                    }

                    matches.ForEach(x => legacyFields.Add(x));
                }

                var spatialFields = task.Result.SpatialIndexes
                                    .Select(x => new SpatialQueryField
                {
                    Name           = x.Key,
                    IsGeographical = x.Value.Type == SpatialFieldType.Geography,
                    Units          = x.Value.Units
                })
                                    .ToList();

                legacyFields.ForEach(x => spatialFields.Add(new SpatialQueryField
                {
                    Name           = x,
                    IsGeographical = true,
                    Units          = SpatialUnits.Kilometers
                }));

                UpdateSpatialFields(spatialFields);

                HasTransform = !string.IsNullOrEmpty(task.Result.TransformResults);

                DocumentsResult.SetChangesObservable(
                    d => d.IndexChanges
                    .Where(n => n.Name.Equals(indexName, StringComparison.InvariantCulture))
                    .Select(m => Unit.Default));

                SetSortByOptions(fields);
                RestoreHistory();
            }).Catch();
        }