private void create_dynamic_mapping_for_users_collection(string query)
 {
     _sut = DynamicQueryMapping.Create("Users", new IndexQueryServerSide
     {
         Query = query
     });
 }
        public void Partial_match_for_map_reduce_index_not_having_all_map_fields_defined_in_query()
        {
            var definition = new AutoMapReduceIndexDefinition("Users", new[]
            {
                new AutoIndexField
                {
                    Name        = "Count",
                    Storage     = FieldStorage.Yes,
                    Aggregation = AggregationOperation.Count,
                },
            },
                                                              new[]
            {
                new AutoIndexField
                {
                    Name    = "Location",
                    Storage = FieldStorage.Yes,
                }
            });

            add_index(definition);

            var dynamicQuery = DynamicQueryMapping.Create(new IndexQueryServerSide("FROM Users GROUP BY Location SELECT Location, count(), sum(Sum) "));

            var result = _sut.Match(dynamicQuery, null);

            Assert.Equal(DynamicQueryMatchType.Partial, result.MatchType);
            Assert.Equal(definition.Name, result.IndexName);
        }
        public void Complete_match_for_index_containing_all_fields()
        {
            var usersByName = new AutoMapIndexDefinition("Users", new[]
            {
                new AutoIndexField
                {
                    Name    = "Name",
                    Storage = FieldStorage.No
                },
            });

            var usersByNameAndAge = new AutoMapIndexDefinition("Users", new[]
            {
                new AutoIndexField
                {
                    Name    = "Name",
                    Storage = FieldStorage.No
                },
                new AutoIndexField
                {
                    Name    = "Age",
                    Storage = FieldStorage.No,
                }
            });

            add_index(usersByName);
            add_index(usersByNameAndAge);

            var dynamicQuery = DynamicQueryMapping.Create(new IndexQueryServerSide("FROM Users WHERE Name = 'Arek' AND Age = 29"));

            var result = _sut.Match(dynamicQuery, null);

            Assert.Equal(DynamicQueryMatchType.Complete, result.MatchType);
            Assert.Equal(usersByNameAndAge.Name, result.IndexName);
        }
Beispiel #4
0
        public void Complete_match_for_single_matching_index_with_default_string_sort_option()
        {
            var definition = new AutoMapIndexDefinition("Users", new[]
            {
                new IndexField
                {
                    Name        = "Name",
                    Highlighted = false,
                    Storage     = FieldStorage.No
                },
            });

            add_index(definition);

            var dynamicQuery = DynamicQueryMapping.Create("Users", new IndexQueryServerSide
            {
                Query        = "Name:Arek",
                SortedFields = new[] { new SortedField("Name") },
            });

            var result = _sut.Match(dynamicQuery);

            Assert.Equal(DynamicQueryMatchType.Complete, result.MatchType);
            Assert.Equal(definition.Name, result.IndexName);
        }
        public void Partial_match_if_exact_is_required_on_group_by_field()
        {
            using (var db = CreateDocumentDatabase())
            {
                var mapping = DynamicQueryMapping.Create(new IndexQueryServerSide(@"
from Users
group by Name
where Name = 'arek'
select Name, count()"));

                db.IndexStore.CreateIndex(mapping.CreateAutoIndexDefinition()).Wait();

                mapping = DynamicQueryMapping.Create(new IndexQueryServerSide(@"
from Users
group by Name
where exact(Name = 'arek')
select Name, count()"));

                var matcher = new DynamicQueryToIndexMatcher(db.IndexStore);

                var result = matcher.Match(mapping, null);

                Assert.Equal(DynamicQueryMatchType.Partial, result.MatchType);
            }
        }
Beispiel #6
0
        public async Task Complete_but_idle_match_if_auto_map_reduce_index_is_idle()
        {
            using (var database = CreateDocumentDatabase())
            {
                var matcher = new DynamicQueryToIndexMatcher(database.IndexStore);

                var autoIndex = await database.IndexStore.CreateIndex(new AutoMapReduceIndexDefinition("Users", new[]
                {
                    new AutoIndexField
                    {
                        Name = "Count",
                        Aggregation = AggregationOperation.Count
                    }
                },
                                                                                                       new[]
                {
                    new AutoIndexField
                    {
                        Name = "Location",
                    }
                }));

                autoIndex.SetState(IndexState.Idle);

                var dynamicQuery = DynamicQueryMapping.Create(new IndexQueryServerSide("from Users group by Location select count()"));

                var result = matcher.Match(dynamicQuery, null);

                Assert.Equal(DynamicQueryMatchType.CompleteButIdle, result.MatchType);
            }
        }
        public void CreateDefinitionForQueryWithNestedFieldsAndNumberSortingSet()
        {
            _sut = DynamicQueryMapping.Create("Users", new IndexQueryServerSide
            {
                Query        = "Name:A*",
                SortedFields = new[]
                {
                    new SortedField("Address.ZipCode_Range"),
                },
            });

            var definition = _sut.CreateAutoIndexDefinition();

            Assert.Equal(1, definition.Collections.Length);
            Assert.Equal("Users", definition.Collections[0]);
            Assert.True(definition.ContainsField("Name"));
            Assert.True(definition.ContainsField("Address.ZipCode"));
            Assert.Equal("Auto/Users/ByAddress_ZipCodeAndNameSortByAddress_ZipCode", definition.Name);
            var nameField = definition.GetField("Name");

            Assert.Null(nameField.SortOption);
            var ageField = definition.GetField("Address.ZipCode");

            Assert.Equal(SortOptions.NumericDefault, ageField.SortOption);
        }
Beispiel #8
0
        public void Partial_match_when_highlighting_is_required()
        {
            Initialize();
            using (var db = CreateDocumentDatabase())
            {
                var mapping = DynamicQueryMapping.Create(new IndexQueryServerSide(@"from Users
where search(Name, 'arek')"));

                var definition = mapping.CreateAutoIndexDefinition();
                db.IndexStore.CreateIndex(definition, Guid.NewGuid().ToString()).Wait();

                mapping = DynamicQueryMapping.Create(new IndexQueryServerSide(@"from Users
where search(Name, 'arek')
include highlight(Name, 18, 2)
"));

                var matcher = new DynamicQueryToIndexMatcher(db.IndexStore);

                var result = matcher.Match(mapping, null);

                Assert.Equal(DynamicQueryMatchType.Partial, result.MatchType);

                mapping.ExtendMappingBasedOn(definition);

                definition = mapping.CreateAutoIndexDefinition();
                db.IndexStore.CreateIndex(definition, Guid.NewGuid().ToString()).Wait();

                result = matcher.Match(mapping, null);

                Assert.Equal(DynamicQueryMatchType.Complete, result.MatchType);
            }
        }
Beispiel #9
0
        public void Complete_match_for_single_matching_index_with_numeric_sort_option_for_nested_field()
        {
            var definition = new AutoMapIndexDefinition("Users", new[]
            {
                new IndexField
                {
                    Name        = "Address.ZipCode",
                    Highlighted = false,
                    Storage     = FieldStorage.No,
                    SortOption  = SortOptions.NumericDefault
                },
            });

            add_index(definition);

            var dynamicQuery = DynamicQueryMapping.Create("Users", new IndexQueryServerSide
            {
                SortedFields = new[] { new SortedField("Address.ZipCode_Range") },
            });

            var result = _sut.Match(dynamicQuery);

            Assert.Equal(DynamicQueryMatchType.Complete, result.MatchType);
            Assert.Equal(definition.Name, result.IndexName);
        }
Beispiel #10
0
        public void Partial_match_when_sort_field_is_not_mapped()
        {
            var definition = new AutoMapIndexDefinition("Users", new[]
            {
                new IndexField
                {
                    Name        = "Name",
                    Highlighted = false,
                    Storage     = FieldStorage.No
                },
            });

            add_index(definition);

            var dynamicQuery = DynamicQueryMapping.Create("Users", new IndexQueryServerSide
            {
                Query        = "Name:Arek",
                SortedFields = new[] { new SortedField("Weight") },
            });

            var result = _sut.Match(dynamicQuery);

            Assert.Equal(DynamicQueryMatchType.Partial, result.MatchType);
            Assert.Equal(definition.Name, result.IndexName);
        }
Beispiel #11
0
        public void Complete_match_for_single_matching_index_with_mapping_nested_fields()
        {
            var definition = new AutoMapIndexDefinition("Users", new[]
            {
                new IndexField
                {
                    Name        = "Name",
                    Highlighted = false,
                    Storage     = FieldStorage.No
                },
                new IndexField
                {
                    Name        = "Address.Street",
                    Highlighted = false,
                    Storage     = FieldStorage.No
                },
                new IndexField
                {
                    Name        = "Friends,Name",
                    Highlighted = false,
                    Storage     = FieldStorage.No
                },
            });

            add_index(definition);

            var dynamicQuery = DynamicQueryMapping.Create("Users", new IndexQueryServerSide {
                Query = "Name:Arek AND Address.Street:1stAvenue AND Friends,Name:Jon"
            });

            var result = _sut.Match(dynamicQuery);

            Assert.Equal(DynamicQueryMatchType.Complete, result.MatchType);
            Assert.Equal(definition.Name, result.IndexName);
        }
Beispiel #12
0
        public void ExtendsIndexingOptionsOfTheSameField()
        {
            _sut = DynamicQueryMapping.Create(new IndexQueryServerSide("FROM Users WHERE FirstName = 'a'"));

            var existingDefinition = _sut.CreateAutoIndexDefinition();

            _sut = DynamicQueryMapping.Create(new IndexQueryServerSide("FROM Users WHERE search(FirstName, 'A')"));

            _sut.ExtendMappingBasedOn(existingDefinition);

            var definition = _sut.CreateAutoIndexDefinition();

            Assert.Equal(1, definition.Collections.Count);
            Assert.Equal("Users", definition.Collections.Single());
            Assert.True(definition.ContainsField("FirstName"));
            Assert.Equal(AutoFieldIndexing.Default | AutoFieldIndexing.Search, definition.MapFields["FirstName"].As <AutoIndexField>().Indexing);
            Assert.Equal("Auto/Users/BySearch(FirstName)", definition.Name);


            _sut = DynamicQueryMapping.Create(new IndexQueryServerSide("FROM Users WHERE exact(FirstName = 'A')"));

            _sut.ExtendMappingBasedOn(definition);

            definition = _sut.CreateAutoIndexDefinition();

            Assert.Equal(1, definition.Collections.Count);
            Assert.Equal("Users", definition.Collections.Single());
            Assert.True(definition.ContainsField("FirstName"));
            Assert.Equal(AutoFieldIndexing.Default | AutoFieldIndexing.Search | AutoFieldIndexing.Exact, definition.MapFields["FirstName"].As <AutoIndexField>().Indexing);
            Assert.Equal("Auto/Users/BySearch(FirstName)AndExact(FirstName)", definition.Name);
        }
Beispiel #13
0
        public void Should_match_auto_map_reduce_index_if_analyzed_field_isnt_used_in_where()
        {
            using (var db = CreateDocumentDatabase())
            {
                var mapping = DynamicQueryMapping.Create(new IndexQueryServerSide(@"
from LastFms
group by Artist
where search(Artist, ""Rapper"")
order by Count as long desc
select count() as Count, Artist"));

                db.IndexStore.CreateIndex(mapping.CreateAutoIndexDefinition(), Guid.NewGuid().ToString()).Wait();

                mapping = DynamicQueryMapping.Create(new IndexQueryServerSide(@"
from LastFms
group by Artist
where Count > 100
order by Count as long desc
select count() as Count, Artist"));

                var matcher = new DynamicQueryToIndexMatcher(db.IndexStore);

                var result = matcher.Match(mapping, null);

                Assert.Equal(DynamicQueryMatchType.Complete, result.MatchType);
            }
        }
        public void Complete_match_for_single_matching_index_with_mapping_nested_fields()
        {
            var definition = new AutoMapIndexDefinition("Users", new[]
            {
                new AutoIndexField
                {
                    Name    = "Name",
                    Storage = FieldStorage.No
                },
                new AutoIndexField
                {
                    Name    = "Address.Street",
                    Storage = FieldStorage.No
                },
                new AutoIndexField
                {
                    Name    = "Friends[].Name",
                    Storage = FieldStorage.No
                },
            });

            add_index(definition);

            var dynamicQuery = DynamicQueryMapping.Create(new IndexQueryServerSide("FROM Users WHERE Name = 'Arek' AND Address.Street ='1stAvenue' AND Friends[].Name = 'Jon'"));

            var result = _sut.Match(dynamicQuery, null);

            Assert.Equal(DynamicQueryMatchType.Complete, result.MatchType);
            Assert.Equal(definition.Name, result.IndexName);
        }
        public void Complete_match_query_sort_is_default_and_definition_doesn_not_specify_sorting_at_all()
        {
            var definition = new AutoMapIndexDefinition("Users", new[]
            {
                new AutoIndexField
                {
                    Name    = "Age",
                    Storage = FieldStorage.No,
                },
            });

            add_index(definition);

            var dynamicQueryWithStringSorting = DynamicQueryMapping.Create(new IndexQueryServerSide("FROM Users WHERE Age > 9 ORDER BY Age AS long"));

            var result = _sut.Match(dynamicQueryWithStringSorting, null);

            Assert.Equal(DynamicQueryMatchType.Complete, result.MatchType);
            Assert.Equal(definition.Name, result.IndexName);

            var dynamicQueryWithNoneSorting = DynamicQueryMapping.Create(new IndexQueryServerSide("FROM Users WHERE Age = 31 ORDER BY Age AS double"));

            result = _sut.Match(dynamicQueryWithNoneSorting, null);

            Assert.Equal(DynamicQueryMatchType.Complete, result.MatchType);
            Assert.Equal(definition.Name, result.IndexName);
        }
Beispiel #16
0
        public void Failure_when_sort_options_do_not_match()
        {
            var definition = new AutoMapReduceIndexDefinition(new [] { "LineItems" }, new[]
            {
                new IndexField
                {
                    Name               = "Price",
                    Highlighted        = false,
                    Storage            = FieldStorage.Yes,
                    MapReduceOperation = FieldMapReduceOperation.Sum,
                    SortOption         = SortOptions.String
                },
            }, new []
            {
                new IndexField
                {
                    Name    = "Name",
                    Storage = FieldStorage.Yes
                }
            });

            add_index(definition);

            var dynamicQuery = DynamicQueryMapping.Create("LineItems", new IndexQueryServerSide
            {
                Query        = "Price:70",
                SortedFields = new[] { new SortedField("Price_Range") },
            });

            var result = _sut.Match(dynamicQuery);

            Assert.Equal(DynamicQueryMatchType.Failure, result.MatchType);
        }
        public void Complete_match_for_single_matching_index_with_sort_options()
        {
            var definition = new AutoMapReduceIndexDefinition("Users", new[]
            {
                new AutoIndexField
                {
                    Name        = "Count",
                    Storage     = FieldStorage.Yes,
                    Aggregation = AggregationOperation.Count,
                },
            },
                                                              new[]
            {
                new AutoIndexField
                {
                    Name    = "Location",
                    Storage = FieldStorage.Yes,
                }
            });

            add_index(definition);

            var dynamicQuery = DynamicQueryMapping.Create(new IndexQueryServerSide(
                                                              "FROM Users GROUP BY Location WHERE Location = 'Poland' ORDER BY Count AS long ASC, Location ASC SELECT Location, count() "));

            var result = _sut.Match(dynamicQuery, null);

            Assert.Equal(DynamicQueryMatchType.Complete, result.MatchType);
            Assert.Equal(definition.Name, result.IndexName);
        }
Beispiel #18
0
        public void Failure_match_for_map_index_containing_the_same_field_names()
        {
            Initialize();

            var definition = new AutoMapIndexDefinition("Users", new[]
            {
                new AutoIndexField
                {
                    Name    = "Count",
                    Storage = FieldStorage.Yes,
                },
                new AutoIndexField
                {
                    Name    = "Location",
                    Storage = FieldStorage.Yes,
                }
            });

            add_index(definition);

            var dynamicQuery = DynamicQueryMapping.Create(new IndexQueryServerSide("FROM Users GROUP BY Location WHERE Location = 'Poland' SELECT Location, count() "));

            var result = _sut.Match(dynamicQuery, null);

            Assert.Equal(DynamicQueryMatchType.Failure, result.MatchType);
        }
        public void Failure_match_for_map_reduce_index_having_different_aggregation_function()
        {
            var definition = new AutoMapReduceIndexDefinition("Users", new[]
            {
                new AutoIndexField
                {
                    Name        = "Count",
                    Storage     = FieldStorage.Yes,
                    Aggregation = AggregationOperation.Count
                },
            },
                                                              new[]
            {
                new AutoIndexField
                {
                    Name    = "Location",
                    Storage = FieldStorage.Yes,
                }
            });

            add_index(definition);

            var dynamicQuery = DynamicQueryMapping.Create(new IndexQueryServerSide("FROM Users GROUP BY Location SELECT Location, sum(Count) "));

            var result = _sut.Match(dynamicQuery, null);

            Assert.Equal(DynamicQueryMatchType.Failure, result.MatchType);
        }
        public async Task Partial_match_if_analyzer_is_required_on_group_by_field()
        {
            Initialize();

            using (var db = CreateDocumentDatabase())
            {
                var mapping = DynamicQueryMapping.Create(new IndexQueryServerSide(@"
from Users
group by Name
where Name = 'arek'
select Name, count()"));

                await db.IndexStore.CreateIndex(mapping.CreateAutoIndexDefinition(), Guid.NewGuid().ToString());

                mapping = DynamicQueryMapping.Create(new IndexQueryServerSide(@"
from Users
group by Name
where search(Name, 'arek')
select Name, count()"));

                var matcher = new DynamicQueryToIndexMatcher(db.IndexStore);

                var result = matcher.Match(mapping, null);

                Assert.Equal(DynamicQueryMatchType.Partial, result.MatchType);
            }
        }
        public void Failure_match_if_there_is_no_index()
        {
            var dynamicQuery = DynamicQueryMapping.Create(new IndexQueryServerSide("FROM Users GROUP BY Location SELECT Location, count() "));

            var result = _sut.Match(dynamicQuery, null);

            Assert.Equal(DynamicQueryMatchType.Failure, result.MatchType);
        }
        public void Failure_if_there_is_no_index()
        {
            var dynamicQuery = DynamicQueryMapping.Create(new IndexQueryServerSide("FROM Users WHERE Name = 'Arek'"));

            var result = _sut.Match(dynamicQuery, null);

            Assert.Equal(DynamicQueryMatchType.Failure, result.MatchType);
        }
Beispiel #23
0
 private void create_dynamic_map_reduce_mapping_for_users_collection(string query, DynamicMapReduceField[] mapReduceFields)
 {
     _sut = DynamicQueryMapping.Create("Users", new IndexQueryServerSide
     {
         Query = query,
         DynamicMapReduceFields = mapReduceFields
     });
 }
Beispiel #24
0
        public void Complete_match_and_surpassed_map_reduce_index_is_choosen()
        {
            Initialize();

            var usersByCountGroupedByLocation = new AutoMapReduceIndexDefinition("Users", new[]
            {
                new AutoIndexField
                {
                    Name        = "Count",
                    Storage     = FieldStorage.Yes,
                    Aggregation = AggregationOperation.Count,
                },
            },
                                                                                 new[]
            {
                new AutoIndexField
                {
                    Name    = "Location",
                    Storage = FieldStorage.Yes,
                }
            });

            var usersByCountAndTotalAgeGroupedByLocation = new AutoMapReduceIndexDefinition("Users", new[]
            {
                new AutoIndexField
                {
                    Name        = "Count",
                    Storage     = FieldStorage.Yes,
                    Aggregation = AggregationOperation.Count,
                },
                new AutoIndexField
                {
                    Name        = "TotalAge",
                    Storage     = FieldStorage.Yes,
                    Aggregation = AggregationOperation.Sum
                },
            },
                                                                                            new[]
            {
                new AutoIndexField
                {
                    Name    = "Location",
                    Storage = FieldStorage.Yes,
                }
            });

            add_index(usersByCountGroupedByLocation);
            add_index(usersByCountAndTotalAgeGroupedByLocation);

            var dynamicQuery = DynamicQueryMapping.Create(new IndexQueryServerSide("FROM Users GROUP BY Location WHERE Location = 'Poland' SELECT Location, count() "));

            var result = _sut.Match(dynamicQuery, null);

            Assert.Equal(DynamicQueryMatchType.Complete, result.MatchType);
            Assert.Equal(usersByCountAndTotalAgeGroupedByLocation.Name, result.IndexName);
        }
Beispiel #25
0
        public void Failure_if_there_is_no_index()
        {
            var dynamicQuery = DynamicQueryMapping.Create("Users", new IndexQueryServerSide {
                Query = "Name:Arek"
            });

            var result = _sut.Match(dynamicQuery);

            Assert.Equal(DynamicQueryMatchType.Failure, result.MatchType);
        }
Beispiel #26
0
        public void Map_all_fields()
        {
            _sut = DynamicQueryMapping.Create(new IndexQueryServerSide("FROM Users GROUP BY Location SELECT Location, count() "));

            var definition = _sut.CreateAutoIndexDefinition();

            Assert.Equal(1, definition.Collections.Count);
            Assert.Equal("Users", definition.Collections.Single());
            Assert.True(definition.ContainsField("Count"));
            Assert.Equal("Auto/Users/ByCountReducedByLocation", definition.Name);
        }
Beispiel #27
0
        public void Failure_if_matching_index_has_lot_of_errors()
        {
            var definition = new AutoMapReduceIndexDefinition(new[] { "Users" }, new[]
            {
                new IndexField
                {
                    Name               = "Count",
                    Storage            = FieldStorage.Yes,
                    MapReduceOperation = FieldMapReduceOperation.Count,
                },
            },
                                                              new[]
            {
                new IndexField
                {
                    Name    = "Location",
                    Storage = FieldStorage.Yes,
                }
            });

            add_index(definition);

            get_index(definition.Name)._indexStorage.UpdateStats(SystemTime.UtcNow, new IndexingRunStats
            {
                MapAttempts    = 1000,
                MapSuccesses   = 1000,
                ReduceAttempts = 1000,
                ReduceErrors   = 900
            });

            var dynamicQuery = DynamicQueryMapping.Create("Users", new IndexQueryServerSide
            {
                Query = "",
                DynamicMapReduceFields = new[]
                {
                    new DynamicMapReduceField
                    {
                        Name          = "Count",
                        OperationType = FieldMapReduceOperation.Count
                    },
                    new DynamicMapReduceField
                    {
                        Name      = "Location",
                        IsGroupBy = true
                    }
                }
            });

            var result = _sut.Match(dynamicQuery);

            Assert.Equal(DynamicQueryMatchType.Failure, result.MatchType);
        }
Beispiel #28
0
        public void Complete_match_for_single_matching_index_with_sort_options()
        {
            var definition = new AutoMapReduceIndexDefinition(new[] { "Users" }, new[]
            {
                new IndexField
                {
                    Name               = "Count",
                    Storage            = FieldStorage.Yes,
                    MapReduceOperation = FieldMapReduceOperation.Count,
                    SortOption         = SortOptions.NumericDefault
                },
            },
                                                              new[]
            {
                new IndexField
                {
                    Name       = "Location",
                    Storage    = FieldStorage.Yes,
                    SortOption = SortOptions.String
                }
            });

            add_index(definition);

            var dynamicQuery = DynamicQueryMapping.Create("Users", new IndexQueryServerSide
            {
                Query = "Location:Poland",
                DynamicMapReduceFields = new[]
                {
                    new DynamicMapReduceField
                    {
                        Name          = "Count",
                        OperationType = FieldMapReduceOperation.Count
                    },
                    new DynamicMapReduceField
                    {
                        Name      = "Location",
                        IsGroupBy = true
                    }
                },
                SortedFields = new []
                {
                    new SortedField("Count_Range"),
                    new SortedField("Location"),
                }
            });

            var result = _sut.Match(dynamicQuery);

            Assert.Equal(DynamicQueryMatchType.Complete, result.MatchType);
            Assert.Equal(definition.Name, result.IndexName);
        }
Beispiel #29
0
        public QueryResult ExecuteDynamicQuery(string entityName, IndexQuery query)
        {
            // Create the map
            var map = DynamicQueryMapping.Create(documentDatabase, query, entityName);

            var touchTemporaryIndexResult = GetAppropriateIndexToQuery(entityName, query, map);

            map.IndexName = touchTemporaryIndexResult.Item1;
            // Re-write the query
            string realQuery = map.Items.Aggregate(query.Query,
                                                   (current, mapItem) => current.Replace(mapItem.QueryFrom, mapItem.To));

            return(ExecuteActualQuery(query, map, touchTemporaryIndexResult, realQuery));
        }
Beispiel #30
0
        public void Partial_match_for_map_reduce_index_not_having_all_map_fields_defined_in_query()
        {
            var definition = new AutoMapReduceIndexDefinition(new[] { "Users" }, new[]
            {
                new IndexField
                {
                    Name               = "Count",
                    Storage            = FieldStorage.Yes,
                    MapReduceOperation = FieldMapReduceOperation.Count
                },
            },
                                                              new[]
            {
                new IndexField
                {
                    Name    = "Location",
                    Storage = FieldStorage.Yes,
                }
            });

            add_index(definition);

            var dynamicQuery = DynamicQueryMapping.Create("Users", new IndexQueryServerSide
            {
                Query = "Location:Poland",
                DynamicMapReduceFields = new[]
                {
                    new DynamicMapReduceField
                    {
                        Name          = "Count",
                        OperationType = FieldMapReduceOperation.Count
                    },
                    new DynamicMapReduceField
                    {
                        Name          = "Sum",
                        OperationType = FieldMapReduceOperation.Sum
                    },
                    new DynamicMapReduceField
                    {
                        Name      = "Location",
                        IsGroupBy = true
                    }
                }
            });

            var result = _sut.Match(dynamicQuery);

            Assert.Equal(DynamicQueryMatchType.Partial, result.MatchType);
            Assert.Equal(definition.Name, result.IndexName);
        }