Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        public void TestTextDefaultLanguage()
        {
            var    options  = IndexOptions.SetTextDefaultLanguage("spanish");
            string expected = "{ \"default_language\" : \"spanish\" }";

            Assert.AreEqual(expected, options.ToJson());
        }