Example #1
0
 public void Test_mongo()
 {
     CardSearch search = 
         new CardSearch("name eq 'Giant Growth' and color eq green");
     List<IMongoQuery> queries = search.MongoQuery();
     Assert.Greater(queries.Count,1);
 }
Example #2
0
        public async Task <long> SearchTotal(string text, bool isComplex = false)
        {
            var client   = new MongoClient(Connection);
            var server   = client.GetServer();
            var database = server.GetDatabase("mtg");

            var collection = database.GetCollection <Card> ("cards");

            List <Card>        cards  = new List <Card> ();
            MongoCursor <Card> cursor = null;

            IMongoQuery query = null;

            if (isComplex)
            {
                CardSearch search = new CardSearch(text);
                query = Query.And(search.MongoQuery());
            }
            else
            {
                query = Query <Card> .Matches(e => e.SearchName,
                                              text.ToLower().Replace(" ", ""));
            }

            return(collection.Count(query));
        }
Example #3
0
 public void Test_search_verify()
 {
     CardSearch search = new CardSearch("name eq 'shit and shit' and type not creature");
     string[] elements = search.Verify();
     foreach(string s in elements)
     {
         System.Console.WriteLine(s);
     }
 }
Example #4
0
        /// <summary>
        /// Search the specified text.
        /// </summary>
        /// <param name="text">Text.</param>
        public async Task <Card[]> Search(string text,
                                          int start      = 0,
                                          int limit      = 0,
                                          bool isComplex = false)
        {
            var client   = new MongoClient(Connection);
            var server   = client.GetServer();
            var database = server.GetDatabase("mtg");

            var collection = database.GetCollection <Card> ("cards");

            List <Card>        cards  = new List <Card> ();
            MongoCursor <Card> cursor = null;

            IMongoQuery query = null;

            if (isComplex)
            {
                CardSearch search = new CardSearch(text);
                query = Query.And(search.MongoQuery());
            }
            else
            {
                query = Query <Card> .Matches(e => e.SearchName,
                                              text.ToLower().Replace(" ", ""));
            }

            cursor = collection.Find(query)
                     .SetSortOrder("_id")
                     .SetSkip(start)
                     .SetLimit(limit);

            foreach (Card card in cursor)
            {
                cards.Add(card);
            }

            return(cards.ToArray());
        }