Exemple #1
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);
        }
        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);
        }
Exemple #3
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);
        }
        public void CanExtractTermsFromRangedQuery()
        {
            create_dynamic_mapping_for_users_collection("Term:[0 TO 10]");

            var definition = _sut.CreateAutoIndexDefinition();

            Assert.Equal(1, definition.Collections.Length);
            Assert.Equal("Users", definition.Collections[0]);
            Assert.True(definition.ContainsField("Term"));
            Assert.Equal("Auto/Users/ByTerm", definition.Name);
        }
Exemple #5
0
        public void Map_all_fields()
        {
            create_dynamic_map_reduce_mapping_for_users_collection("", new[]
            {
                new DynamicMapReduceField
                {
                    Name      = "Location",
                    IsGroupBy = true
                },
                new DynamicMapReduceField
                {
                    Name          = "Count",
                    OperationType = FieldMapReduceOperation.Count
                }
            });

            var definition = _sut.CreateAutoIndexDefinition();

            Assert.Equal(1, definition.Collections.Length);
            Assert.Equal("Users", definition.Collections[0]);
            Assert.True(definition.ContainsField("Count"));
            Assert.Equal("Auto/Users/ByCountReducedByLocation", definition.Name);
        }
        public void CreateDefinitionForQueryWithRangeField()
        {
            _sut = DynamicQueryMapping.Create("Users", new IndexQueryServerSide
            {
                Query = "Age_Range:{Lx30 TO NULL}"
            });

            var definition = _sut.CreateAutoIndexDefinition();

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

            Assert.Equal(SortOptions.NumericDefault, nameField.SortOption);
        }
        public void DefinitionExtensionWontDuplicateFields()
        {
            _sut = DynamicQueryMapping.Create("Users", new IndexQueryServerSide
            {
                Query        = "FirstName:A* LastName:a*",
                SortedFields = new[]
                {
                    new SortedField("Count_Range"),
                },
            });

            var existingDefinition = _sut.CreateAutoIndexDefinition();

            _sut = DynamicQueryMapping.Create("Users", new IndexQueryServerSide
            {
                Query        = "FirstName:A* AddressId:addresses/1",
                SortedFields = new[]
                {
                    new SortedField("Age_Range"),
                    new SortedField("Count_Range")
                },
            });

            _sut.ExtendMappingBasedOn(existingDefinition);

            var definition = _sut.CreateAutoIndexDefinition();

            Assert.Equal(1, definition.Collections.Length);
            Assert.Equal("Users", definition.Collections[0]);
            Assert.True(definition.ContainsField("FirstName"));
            Assert.True(definition.ContainsField("LastName"));
            Assert.True(definition.ContainsField("AddressId"));
            Assert.True(definition.ContainsField("Age"));
            Assert.True(definition.ContainsField("Count"));
            Assert.Equal("Auto/Users/ByAddressIdAndAgeAndCountAndFirstNameAndLastNameSortByAgeCount", definition.Name);

            var ageField = definition.GetField("Age");

            Assert.Equal(SortOptions.NumericDefault, ageField.SortOption);

            var countField = definition.GetField("Count");

            Assert.Equal(SortOptions.NumericDefault, countField.SortOption);
        }
Exemple #8
0
        public void ExtendsMappingBasedOnExistingDefinition()
        {
            _sut = DynamicQueryMapping.Create(new IndexQueryServerSide("FROM Users WHERE StartsWith(FirstName, 'a') ORDER BY Count AS long"));

            var existingDefinition = _sut.CreateAutoIndexDefinition();

            _sut = DynamicQueryMapping.Create(new IndexQueryServerSide("FROM Users WHERE StartsWith(LastName, 'A') ORDER BY Age AS double"));

            _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.True(definition.ContainsField("LastName"));
            Assert.True(definition.ContainsField("Age"));
            Assert.True(definition.ContainsField("Count"));
            Assert.Equal("Auto/Users/ByAgeAndCountAndFirstNameAndLastName", definition.Name);
        }
Exemple #9
0
        public void Extends_mapping_based_on_existing_definition_if_group_by_fields_match()
        {
            _sut = DynamicQueryMapping.Create(
                new IndexQueryServerSide("FROM Users GROUP BY Location WHERE StartsWith(Location, 'A') ORDER BY Count SELECT Location, count() "));

            var existingDefinition = _sut.CreateAutoIndexDefinition();

            _sut = DynamicQueryMapping.Create(new IndexQueryServerSide(
                                                  "FROM Users GROUP BY Location WHERE StartsWith(Location, 'A') ORDER BY Age as long SELECT Location, count(), sum(Age) "));

            _sut.ExtendMappingBasedOn(existingDefinition);

            var definition = (AutoMapReduceIndexDefinition)_sut.CreateAutoIndexDefinition();

            Assert.Equal(1, definition.Collections.Count);
            Assert.Equal("Users", definition.Collections.Single());
            Assert.True(definition.ContainsField("Count"));
            Assert.True(definition.ContainsField("Age"));
            Assert.True(definition.GroupByFields.ContainsKey("Location"));

            Assert.Equal("Auto/Users/ByAgeAndCountReducedByLocation", definition.Name);
        }
Exemple #10
0
        public void CanExtractTermsFromRangedQuery()
        {
            create_dynamic_mapping("FROM Users WHERE Term BETWEEN 0 AND 10");

            var definition = _sut.CreateAutoIndexDefinition();

            Assert.Equal(1, definition.Collections.Count);
            Assert.Equal("Users", definition.Collections.Single());
            Assert.True(definition.ContainsField("Term"));
            Assert.Equal("Auto/Users/ByTerm", definition.Name);
        }
Exemple #11
0
        public void Extends_mapping_based_on_existing_definition_if_group_by_fields_match()
        {
            _sut = DynamicQueryMapping.Create("Users", new IndexQueryServerSide
            {
                Query = "Location:A*",
                DynamicMapReduceFields = new []
                {
                    new DynamicMapReduceField
                    {
                        Name          = "Count",
                        OperationType = FieldMapReduceOperation.Count
                    },
                    new DynamicMapReduceField
                    {
                        Name      = "Location",
                        IsGroupBy = true
                    }
                },
                SortedFields = new[]
                {
                    new SortedField("Count_Range"),
                }
            });

            var existingDefinition = _sut.CreateAutoIndexDefinition();

            _sut = DynamicQueryMapping.Create("Users", new IndexQueryServerSide
            {
                Query = "Location:A*",
                DynamicMapReduceFields = new[]
                {
                    new DynamicMapReduceField
                    {
                        Name          = "Count",
                        OperationType = FieldMapReduceOperation.Count,
                    },
                    new DynamicMapReduceField
                    {
                        Name          = "Age",
                        OperationType = FieldMapReduceOperation.Sum
                    },
                    new DynamicMapReduceField
                    {
                        Name      = "Location",
                        IsGroupBy = true
                    }
                },
                SortedFields = new []
                {
                    new SortedField("Age_Range"),
                }
            });

            _sut.ExtendMappingBasedOn(existingDefinition);

            var definition = (AutoMapReduceIndexDefinition)_sut.CreateAutoIndexDefinition();

            Assert.Equal(1, definition.Collections.Length);
            Assert.Equal("Users", definition.Collections[0]);
            Assert.True(definition.ContainsField("Count"));
            Assert.True(definition.ContainsField("Age"));
            Assert.True(definition.GroupByFields.ContainsKey("Location"));

            Assert.Equal(SortOptions.NumericDefault, definition.GetField("Count").SortOption);
            Assert.Equal(SortOptions.NumericDefault, definition.GetField("Age").SortOption);

            Assert.Equal("Auto/Users/ByAgeAndCountSortByAgeCountReducedByLocation", definition.Name);
        }