コード例 #1
0
        public void testSearch()
        {
            Assert.IsNull(pc.findById(null));
            Assert.IsNull(pc.findById(""));
            Assert.IsNotNull(pc.findById(u.id));
            Assert.IsNotNull(pc.findById(t.id));

            Assert.IsTrue(pc.findByIds(null).Count == 0);
            Assert.AreEqual(3, pc.findByIds(new List<string> { u.id, u1.id, u2.id }).Count);

            Assert.IsTrue(pc.findNearby(null, null, 100, 1, 1).Count == 0);
            List<ParaObject> l1 = pc.findNearby(u.type, "*", 10, 40.60, -73.90);
            Assert.IsFalse(l1.Count == 0);

            Assert.IsTrue(pc.findNearby(null, null, 100, 1, 1).Count == 0);
            l1 = pc.findNearby(u.type, "*", 10, 40.60, -73.90);
            Assert.IsFalse(l1.Count == 0);

            Assert.IsTrue(pc.findPrefix(null, null, "").Count == 0);
            Assert.IsTrue(pc.findPrefix("", "null", "xx").Count == 0);
            Assert.IsFalse(pc.findPrefix(u.type, "name", "ann").Count == 0);

            Assert.IsFalse(pc.findQuery(null, null).Count == 0);
            Assert.IsFalse(pc.findQuery("", "*").Count == 0);
            Assert.AreEqual(2, pc.findQuery(a1.type, "country:US").Count);
            Assert.IsFalse(pc.findQuery(u.type, "ann").Count == 0);
            Assert.IsFalse(pc.findQuery(u.type, "Ann").Count == 0);
            Assert.IsTrue(pc.findQuery(null, "*").Count > 4);

            Pager p = new Pager();
            Assert.AreEqual(0, p.count);
            List<ParaObject> res = pc.findQuery(u.type, "*", p);
            Assert.AreEqual(res.Count, p.count);
            Assert.IsTrue(p.count > 0);

            Assert.IsTrue(pc.findSimilar(t.type, "", null, null).Count == 0);
            Assert.IsTrue(pc.findSimilar(t.type, "", new string[0], "").Count == 0);
            res = pc.findSimilar(s1.type, s1.id, new [] { "name" }, s1.name);
            Assert.IsFalse(res.Count == 0);
            Assert.AreEqual(s2.id, res[0].id);

            int i0 = pc.findTagged(u.type, null).Count;
            int i1 = pc.findTagged(u.type, new [] { "two" }).Count;
            int i2 = pc.findTagged(u.type, new [] { "one", "two" }).Count;
            int i3 = pc.findTagged(u.type, new [] { "three" }).Count;
            int i4 = pc.findTagged(u.type, new [] { "four", "three" }).Count;
            int i5 = pc.findTagged(u.type, new [] { "five", "three" }).Count;
            int i6 = pc.findTagged(t.type, new [] { "four", "three" }).Count;

            Assert.AreEqual(0, i0);
            Assert.AreEqual(2, i1);
            Assert.AreEqual(1, i2);
            Assert.AreEqual(3, i3);
            Assert.AreEqual(2, i4);
            Assert.AreEqual(1, i5);
            Assert.AreEqual(0, i6);

            Assert.IsFalse(pc.findTags(null).Count == 0);
            Assert.IsFalse(pc.findTags("").Count == 0);
            Assert.IsTrue(pc.findTags("unknown").Count == 0);
            Assert.IsTrue(pc.findTags((string)t["tag"]).Count >= 1);

            Assert.AreEqual(3, pc.findTermInList(u.type, "id",
                    new List<string> { u.id, u1.id, u2.id, "xxx", "yyy" }).Count);

            // many terms
            Dictionary<string, object> terms = new Dictionary<string, object>();
            //terms.put("type", u.type);
            terms["id"] = u.id;

            Dictionary<string, object> terms1 = new Dictionary<string, object>();
            terms1["type"] = null;
            terms1["id"] = " ";

            Dictionary<string, object> terms2 = new Dictionary<string, object>();
            terms2[" "] = "bad";
            terms2[""] = "";

            Assert.AreEqual(1, pc.findTerms(u.type, terms, true).Count);
            Assert.IsTrue(pc.findTerms(u.type, terms1, true).Count == 0);
            Assert.IsTrue(pc.findTerms(u.type, terms2, true).Count == 0);

            // single term
            Assert.IsTrue(pc.findTerms(null, null, true).Count == 0);
            Assert.IsTrue(pc.findTerms(u.type, new Dictionary<string, object> { { "", null } }, true).Count == 0);
            Assert.IsTrue(pc.findTerms(u.type, new Dictionary<string, object> { { "", "" } }, true).Count == 0);
            Assert.IsTrue(pc.findTerms(u.type, new Dictionary<string, object> { { "term", null } }, true).Count == 0);
            Assert.IsTrue(pc.findTerms(u.type, new Dictionary<string, object> { { "type", u.type } }, true).Count >= 2);

            Assert.IsTrue(pc.findWildcard(u.type, null, null).Count == 0);
            Assert.IsTrue(pc.findWildcard(u.type, "", "").Count == 0);
            Assert.IsFalse(pc.findWildcard(u.type, "name", "an*").Count == 0);

            Assert.IsTrue(pc.getCount(null) > 4);
            Assert.AreNotEqual(0, pc.getCount(""));
            Assert.AreEqual(0, pc.getCount("test"));
            Assert.IsTrue(pc.getCount(u.type) >= 3);

            Assert.AreEqual(0L, pc.getCount(null, null));
            Assert.AreEqual(0L, pc.getCount(u.type, new Dictionary<string, object> { { "id", " " } }));
            Assert.AreEqual(1L, pc.getCount(u.type, new Dictionary<string, object> { { "id", u.id } }));
            Assert.IsTrue(pc.getCount(null, new Dictionary<string, object> { { "type", u.type } }) > 1);
        }
コード例 #2
0
 /// <summary>
 /// Counts indexed objects.
 /// </summary>
 /// <param name="type">the type of object to search for.</param>
 /// <returns>the number of results found</returns>
 public long getCount(string type)
 {
     var paramz = new Dictionary<string, object>();
     paramz["type"] = type;
     var pager = new Pager();
     getItems(find("count", paramz), pager);
     return pager.count;
 }
コード例 #3
0
 /// <summary>
 /// Counts indexed objects matching a set of terms/values.
 /// </summary>
 /// <param name="type">the type of object to search for.</param>
 /// <param name="terms">a list of terms (property values)</param>
 /// <returns>the number of results found</returns>
 public long getCount(string type, Dictionary<string, object> terms)
 {
     if (terms == null)
     {
         return 0L;
     }
     var paramz = new Dictionary<string, object>();
     var termz = new List<string>();
     foreach (var term in terms)
     {
         string key = term.Key;
         object value = term.Value;
         if (value != null)
         {
             termz.Add(key + SEPARATOR + value);
         }
     }
     if (terms.Count > 0)
     {
         paramz["terms"] = termz;
     }
     paramz["type"] = type;
     paramz["count"] = "true";
     var pager = new Pager();
     getItems(find("terms", paramz), pager);
     return pager.count;
 }
コード例 #4
0
 /////////////////////////////////////////////
 //                 LINKS
 /////////////////////////////////////////////
 /// <summary>
 /// Count the total number of links between this object and another type of object.
 /// </summary>
 /// <param name="obj">the object to execute this method on</param>
 /// <param name="type2">the other type of object</param>
 /// <returns>the number of links for the given object</returns>
 public long countLinks(ParaObject obj, string type2)
 {
     if (obj == null || obj.id == null || type2 == null)
     {
         return 0L;
     }
     var paramz = new Dictionary<string, object>();
     paramz["count"] = "true";
     var pager = new Pager();
     string url = obj.getObjectURI() + "/links/" + type2;
     getItems(getEntity(invokeGet(url, paramz), true), pager);
     return pager.count;
 }