public void TestMetaText()
        {
            if (LegacyTestConfiguration.Server.Primary.Supports(FeatureId.TextSearchQuery))
            {
                var collection = LegacyTestConfiguration.Database.GetCollection <BsonDocument>("test_meta_text");
                collection.Drop();
                collection.CreateIndex(IndexKeys.Text("textfield"));
                collection.Insert(new BsonDocument
                {
                    { "_id", 1 },
                    { "textfield", "The quick brown fox jumped" }
                });
                collection.Insert(new BsonDocument
                {
                    { "_id", 2 },
                    { "textfield", "over the lazy brown dog" }
                });
                var query  = Query.Text("fox");
                var result = collection.FindOneAs <BsonDocument>(query);
                Assert.Equal(2, result.ElementCount);
                Assert.False(result.Contains("relevance"));

                var fields = Fields.MetaTextScore("relevance");
                result = collection.FindOneAs <BsonDocument>(new FindOneArgs {
                    Query = query, Fields = fields
                });
                Assert.Equal(3, result.ElementCount);
                Assert.True(result.Contains("relevance"));
            }
        }
Exemple #2
0
        public void TestText()
        {
            var    key      = IndexKeys.Text("a");
            string expected = "{ \"a\" : \"text\" }";

            Assert.AreEqual(expected, key.ToJson());
        }
Exemple #3
0
        public void TestTextMultiple()
        {
            var    keys     = IndexKeys.Text("a", "b");
            string expected = "{ \"a\" : \"text\", \"b\" : \"text\" }";

            Assert.AreEqual(expected, keys.ToJson());
        }
Exemple #4
0
        public void TestTextCombination()
        {
            var    key      = IndexKeys.Text("a").Ascending("b");
            string expected = "{ \"a\" : \"text\", \"b\" : 1 }";

            Assert.AreEqual(expected, key.ToJson());
        }
Exemple #5
0
 public void TestText()
 {
     if (_primary.Supports(FeatureId.TextSearchQuery))
     {
         using (_server.RequestStart(null, _primary))
         {
             var collection = _database.GetCollection <BsonDocument>("test_text");
             collection.Drop();
             collection.CreateIndex(IndexKeys.Text("textfield"));
             collection.Insert(new BsonDocument
             {
                 { "_id", 1 },
                 { "textfield", "The quick brown fox" }
             });
             collection.Insert(new BsonDocument
             {
                 { "_id", 2 },
                 { "textfield", "over the lazy brown dog" }
             });
             var query   = Query.Text("fox");
             var results = collection.Find(query).ToArray();
             Assert.AreEqual(1, results.Length);
             Assert.AreEqual(1, results[0]["_id"].AsInt32);
         }
     }
 }
Exemple #6
0
        public void TestTextWithLanguage()
        {
            if (_primary.Supports(FeatureId.TextSearchQuery))
            {
                var collection = _database.GetCollection <BsonDocument>("test_text_spanish");
                collection.Drop();
                collection.CreateIndex(IndexKeys.Text("textfield"), IndexOptions.SetTextDefaultLanguage("spanish"));
                collection.Insert(new BsonDocument
                {
                    { "_id", 1 },
                    { "textfield", "este es mi tercer blog stemmed" }
                });
                collection.Insert(new BsonDocument
                {
                    { "_id", 2 },
                    { "textfield", "This stemmed blog is in english" },
                    { "language", "english" }
                });

                var query   = Query.Text("stemmed");
                var results = collection.Find(query).ToArray();
                Assert.AreEqual(1, results.Length);
                Assert.AreEqual(1, results[0]["_id"].AsInt32);

                query   = Query.Text("stemmed", "english");
                results = collection.Find(query).ToArray();
                Assert.AreEqual(1, results.Length);
                Assert.AreEqual(2, results[0]["_id"].AsInt32);
            }
        }
Exemple #7
0
        public void TestTextCombination()
        {
            var key = IndexKeys <Test> .Text(x => x.A).Ascending(x => x.B);

            string expected = "{ \"a\" : \"text\", \"b\" : 1 }";

            Assert.Equal(expected, key.ToJson());
        }
Exemple #8
0
        public void TestTextMultiple()
        {
            var keys = IndexKeys <Test> .Text(x => x.A, x => x.B);

            string expected = "{ \"a\" : \"text\", \"b\" : \"text\" }";

            Assert.Equal(expected, keys.ToJson());
        }
Exemple #9
0
        public void TestText()
        {
            var key = IndexKeys <Test> .Text(x => x.A);

            string expected = "{ \"a\" : \"text\" }";

            Assert.Equal(expected, key.ToJson());
        }
Exemple #10
0
 protected Task On(SchemaCreated @event, EnvelopeHeaders headers)
 {
     return(ForSchemaIdAsync(@event.SchemaId.Id, async collection =>
     {
         await collection.Indexes.CreateOneAsync(IndexKeys.Ascending(x => x.IsPublished));
         await collection.Indexes.CreateOneAsync(IndexKeys.Text(x => x.Text));
     }));
 }
        public void TestTextArrayNonArrayFields2()
        {
            var keys = IndexKeys <Test> .Text(x => x.A).Text(x => x.E).Text(x => x.D).Text(x => x.B);

            string expected = "{ \"a\" : \"text\", \"e\" : \"text\", \"d\" : \"text\", \"b\" : \"text\" }";

            Assert.AreEqual(expected, keys.ToJson());
        }
        public void TestTextArrayField()
        {
            var keys = IndexKeys <Test> .Text(x => x.D);

            string expected = "{ \"d\" : \"text\" }";

            Assert.AreEqual(expected, keys.ToJson());
        }
Exemple #13
0
 public MongoIndexKeysWarpper Text(params string[] names)
 {
     if (MongoIndexKeys == null)
     {
         MongoIndexKeys = IndexKeys.Text(names);
     }
     else
     {
         MongoIndexKeys = MongoIndexKeys.Text(names);
     }
     return(this);
 }
Exemple #14
0
        public void TestMetaText()
        {
            var server  = Configuration.TestServer;
            var primary = server.Primary;

            if (primary.Supports(FeatureId.TextSearchQuery))
            {
                using (server.RequestStart(null, primary))
                {
                    var collection = Configuration.TestDatabase.GetCollection <Test>("test_meta_text_sort");
                    collection.Drop();
                    collection.CreateIndex(IndexKeys <Test> .Text(x => x.T));
                    collection.Insert(new Test
                    {
                        Id = 1,
                        T  = "The quick brown fox jumped",
                        z  = 1
                    });
                    collection.Insert(new Test
                    {
                        Id = 2,
                        T  = "over the lazy brown dog and brown cat",
                        z  = 2
                    });
                    collection.Insert(new Test
                    {
                        Id = 3,
                        T  = "over the lazy brown dog and brown cat",
                        z  = 4
                    });
                    collection.Insert(new Test
                    {
                        Id = 4,
                        T  = "over the lazy brown dog and brown cat",
                        z  = 3
                    });

                    var query  = Query.Text("brown");
                    var fields = Fields <Test> .MetaTextScore(y => y.R);

                    var sortBy = SortBy <Test> .MetaTextScore(y => y.R).Descending(y => y.z);

                    var cursor = collection.FindAs <BsonDocument>(query).SetFields(fields).SetSortOrder(sortBy);
                    var result = cursor.ToArray();
                    Assert.AreEqual(4, result.Length);
                    Assert.AreEqual(3, result[0]["_id"].AsInt32);
                    Assert.AreEqual(4, result[1]["_id"].AsInt32);
                    Assert.AreEqual(2, result[2]["_id"].AsInt32);
                    Assert.AreEqual(1, result[3]["_id"].AsInt32);
                }
            }
        }
Exemple #15
0
        public void TestMetaText()
        {
            var server  = Configuration.TestServer;
            var primary = server.Primary;

            if (primary.Supports(FeatureId.TextSearchQuery))
            {
                using (server.RequestStart(null, primary))
                {
                    var collection = Configuration.TestDatabase.GetCollection <BsonDocument>("test_meta_text_sort");
                    collection.Drop();
                    collection.CreateIndex(IndexKeys.Text("textfield"));
                    collection.Insert(new BsonDocument
                    {
                        { "_id", 1 },
                        { "textfield", "The quick brown fox jumped" },
                        { "z", 1 }
                    });
                    collection.Insert(new BsonDocument
                    {
                        { "_id", 2 },
                        { "textfield", "over the lazy brown dog and brown cat" },
                        { "z", 2 }
                    });
                    collection.Insert(new BsonDocument
                    {
                        { "_id", 3 },
                        { "textfield", "over the lazy brown dog and brown cat" },
                        { "z", 4 }
                    });
                    collection.Insert(new BsonDocument
                    {
                        { "_id", 4 },
                        { "textfield", "over the lazy brown dog and brown cat" },
                        { "z", 3 }
                    });

                    var query  = Query.Text("brown");
                    var fields = Fields.MetaTextScore("relevance");
                    var sortBy = SortBy.MetaTextScore("relevance").Descending("z");
                    var cursor = collection.FindAs <BsonDocument>(query).SetFields(fields).SetSortOrder(sortBy);
                    var result = cursor.ToArray();
                    Assert.AreEqual(4, result.Length);
                    Assert.AreEqual(3, result[0]["_id"].AsInt32);
                    Assert.AreEqual(4, result[1]["_id"].AsInt32);
                    Assert.AreEqual(2, result[2]["_id"].AsInt32);
                    Assert.AreEqual(1, result[3]["_id"].AsInt32);
                }
            }
        }
Exemple #16
0
        public void TestTextIndexCreation()
        {
            RequireServer.Check().VersionGreaterThanOrEqualTo("2.6.0").ClusterTypes(ClusterType.Standalone, ClusterType.ReplicaSet);
            var collection = _database.GetCollection <BsonDocument>("test_text");

            collection.Drop();
            collection.CreateIndex(IndexKeys.Text("a", "b").Ascending("c"), IndexOptions.SetTextLanguageOverride("idioma").SetName("custom").SetTextDefaultLanguage("spanish"));
            var indexes = collection.GetIndexes();
            var index   = indexes.RawDocuments.Single(i => i["name"].AsString == "custom");

            Assert.Equal("idioma", index["language_override"].AsString);
            Assert.Equal("spanish", index["default_language"].AsString);
            Assert.Equal(1, index["key"]["c"].AsInt32);
        }
Exemple #17
0
 public void TestTextIndexCreation()
 {
     if (_primary.InstanceType != MongoServerInstanceType.ShardRouter)
     {
         if (_primary.Supports(FeatureId.TextSearchCommand))
         {
             var collection = _database.GetCollection <BsonDocument>("test_text");
             collection.Drop();
             collection.CreateIndex(IndexKeys.Text("a", "b").Ascending("c"), IndexOptions.SetTextLanguageOverride("idioma").SetName("custom").SetTextDefaultLanguage("spanish"));
             var indexes = collection.GetIndexes();
             var index   = indexes.RawDocuments.Single(i => i["name"].AsString == "custom");
             Assert.AreEqual("idioma", index["language_override"].AsString);
             Assert.AreEqual("spanish", index["default_language"].AsString);
             Assert.AreEqual(1, index["key"]["c"].AsInt32);
         }
     }
 }
Exemple #18
0
        public void TestMetaText()
        {
            var server  = Configuration.TestServer;
            var primary = server.Primary;

            if (primary.Supports(FeatureId.TextSearchQuery))
            {
                using (server.RequestStart(null, primary))
                {
                    var collection = Configuration.TestDatabase.GetCollection <TestClass>("test_meta_text");
                    collection.Drop();
                    collection.CreateIndex(IndexKeys <TestClass> .Text(x => x.textfield));
                    collection.Insert(new TestClass
                    {
                        _id       = 1,
                        textfield = "The quick brown fox jumped",
                        x         = 1
                    });
                    collection.Insert(new TestClass
                    {
                        _id       = 2,
                        textfield = "over the lazy brown dog",
                        x         = 1
                    });

                    var query  = Query.Text("fox");
                    var result = collection.FindOneAs <BsonDocument>(query);
                    Assert.AreEqual(1, result["_id"].AsInt32);
                    Assert.IsFalse(result.Contains("relevance"));
                    Assert.IsTrue(result.Contains("x"));

                    var fields = Fields <TestClass> .MetaTextScore(y => y.relevance).Exclude(y => y.x);

                    result = collection.FindOneAs <BsonDocument>(new FindOneArgs()
                    {
                        Query = query, Fields = fields
                    });
                    Assert.AreEqual(1, result["_id"].AsInt32);
                    Assert.IsTrue(result.Contains("relevance"));
                    Assert.IsFalse(result.Contains("x"));
                }
            }
        }
Exemple #19
0
 public void TestTextIndexCreation()
 {
     if (_primary.InstanceType != MongoServerInstanceType.ShardRouter)
     {
         if (_primary.Supports(FeatureId.TextSearchCommand))
         {
             using (_server.RequestStart(null, _primary))
             {
                 var collection = _database.GetCollection <Test>("test_text");
                 collection.Drop();
                 collection.CreateIndex(IndexKeys <Test> .Text(x => x.A, x => x.B).Ascending(x => x.C), IndexOptions.SetTextLanguageOverride("idioma").SetName("custom").SetTextDefaultLanguage("spanish"));
                 var indexCollection = _database.GetCollection("system.indexes");
                 var result          = indexCollection.FindOne(Query.EQ("name", "custom"));
                 Assert.AreEqual("custom", result["name"].AsString);
                 Assert.AreEqual("idioma", result["language_override"].AsString);
                 Assert.AreEqual("spanish", result["default_language"].AsString);
                 Assert.AreEqual(1, result["key"]["c"].AsInt32);
             }
         }
     }
 }
        public void TestText()
        {
            var collection = _database.GetCollection <BsonDocument>("test_text");

            collection.Drop();
            collection.CreateIndex(IndexKeys.Text("textfield"));
            collection.Insert(new BsonDocument
            {
                { "_id", 1 },
                { "textfield", "The quick brown fox" }
            });
            collection.Insert(new BsonDocument
            {
                { "_id", 2 },
                { "textfield", "over the lazy brown dog" }
            });
            var query   = Query.Text("fox");
            var results = collection.Find(query).ToArray();

            Assert.Equal(1, results.Length);
            Assert.Equal(1, results[0]["_id"].AsInt32);
        }
        public void TestMetaText()
        {
            var collection = LegacyTestConfiguration.Database.GetCollection <TestClass>("test_meta_text");

            collection.Drop();
            collection.CreateIndex(IndexKeys <TestClass> .Text(x => x.textfield));
            collection.Insert(new TestClass
            {
                _id       = 1,
                textfield = "The quick brown fox jumped",
                x         = 1
            });
            collection.Insert(new TestClass
            {
                _id       = 2,
                textfield = "over the lazy brown dog",
                x         = 1
            });

            var query  = Query.Text("fox");
            var result = collection.FindOneAs <BsonDocument>(query);

            Assert.Equal(1, result["_id"].AsInt32);
            Assert.False(result.Contains("relevance"));
            Assert.True(result.Contains("x"));

            var fields = Fields <TestClass> .MetaTextScore(y => y.relevance).Exclude(y => y.x);

            result = collection.FindOneAs <BsonDocument>(new FindOneArgs()
            {
                Query = query, Fields = fields
            });
            Assert.Equal(1, result["_id"].AsInt32);
            Assert.True(result.Contains("relevance"));
            Assert.False(result.Contains("x"));
        }
 public async Task CreateIndexes()
 {
     var definition = IndexKeys.Text(recipe => recipe.Name).Text(recipe => recipe.Tags);
     await Recipes.Indexes.CreateOneAsync(new CreateIndexModel <Recipe>(definition));
 }
Exemple #23
0
        public void SetMasterData()
        {
            //insert these flags before hand for now.
            List <FlagSetting> lstFlagSetting = new List <FlagSetting>()
            {
                new FlagSetting {
                    Name = "bUseElasticSearchEngine", Description = "enable product search on ElasticSearch engine", FlagValue = "false", IsPermanent = false
                },
                new FlagSetting {
                    Name = "bShowLoadTime", Description = "Show load timings. This is used for identifying the bottle necks", FlagValue = "true", IsPermanent = true
                },
            };

            _cRepository.Insert <FlagSetting>(lstFlagSetting);

            List <ProgrammingRating> lstProgrammingRating = new List <ProgrammingRating>()
            {
                new ProgrammingRating {
                    Name = "Expert", Code = "EX"
                },
                new ProgrammingRating {
                    Name = "Good", Code = "GD"
                },
                new ProgrammingRating {
                    Name = "Average", Code = "AVG"
                },
                new ProgrammingRating {
                    Name = "Beginner", Code = "B"
                },
                new ProgrammingRating {
                    Name = "Hopeless", Code = "HL"
                },
            };

            _bRepository.Insert <ProgrammingRating>(lstProgrammingRating);

            List <Gender> lstGender = new List <Gender>()
            {
                new Gender {
                    Name = "Male", Code = "M"
                },
                new Gender {
                    Name = "Female", Code = "F"
                },
            };

            _bRepository.Insert <Gender>(lstGender);

            List <Skill> lstSkill = new List <Skill>()
            {
                new Skill {
                    Name = "Ruby On Rails", Code = "RR"
                },
                new Skill {
                    Name = "Core Java", Code = "J"
                },
                new Skill {
                    Name = "Java EE", Code = "J"
                },
                new Skill {
                    Name = "Scala"
                },
                new Skill {
                    Name = "Play Framework"
                },
                new Skill {
                    Name = "Python"
                },
                new Skill {
                    Name = "ASP.Net MVC"
                },
            };

            _bRepository.Insert <Skill>(lstSkill);

            List <ClientType> lstClientType = new List <ClientType>()
            {
                new ClientType {
                    Name = "Information Technology-1"
                },
                new ClientType {
                    Name = "Information Technology-2"
                },
                new ClientType {
                    Name = "Information Technology-3"
                },
                new ClientType {
                    Name = "Information Technology-4"
                },
                new ClientType {
                    Name = "Energy Sector-1"
                },
                new ClientType {
                    Name = "Energy Sector-2"
                },
                new ClientType {
                    Name = "Energy Sector-3"
                },
            };

            _bRepository.Insert <ClientType>(lstClientType);

            List <Author> lstAuthor = new List <Author>()
            {
                new Author {
                    Name = "Paulo Coelho"
                },
                new Author {
                    Name = "Amit Kumar"
                },
                new Author {
                    Name = "David Schwartz"
                },
                new Author {
                    Name = "Max Payne"
                },
                new Author {
                    Name = "Michael Hartl"
                },
            };

            _pcRepository.Insert <Author>(lstAuthor);

            List <BookCategory> lstBookCategory = new List <BookCategory>()
            {
                new BookCategory {
                    Name = "Python"
                },
                new BookCategory {
                    Name = "Java"
                },
                new BookCategory {
                    Name = "Inspiration, Motivation"
                },
                new BookCategory {
                    Name = "Fiction"
                },
                new BookCategory {
                    Name = "Ruby On Rails"
                },
            };

            _pcRepository.Insert <BookCategory>(lstBookCategory);

            //Create a text index on Book collection, this required for free text searching actually.
            var collection = _pcRepository.DbContext.GetCollection <Book>("Book");

            if (!collection.IndexExistsByName("book_text"))
            {
                collection.CreateIndex(IndexKeys.Text("nm", "au.nm", "ct.nm"), IndexOptions.SetName("book_text").SetWeight("nm", 4).SetWeight("au.nm", 3));
            }
        }