Exemple #1
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));
        }
Exemple #2
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);
 }
Exemple #3
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());
        }