Exemplo n.º 1
0
        private void CreateIndex()
        {
            var ind = (C4Indexer *)LiteCoreBridge.Check(err => Native.c4indexer_begin(Db,
                                                                                      new[] { _view }, err));
            var e = (C4DocEnumerator *)LiteCoreBridge.Check(err => Native.c4indexer_enumerateDocuments(ind, err));

            C4Document *doc;
            C4Error     error;

            while (null != (doc = Native.c4enum_nextDocument(e, &error)))
            {
                var body       = doc->selectedRev.body.CreateString();
                var components = body.Trim('(', ')').Split(',');
                var area       = new C4GeoArea();
                area.xmin = Double.Parse(components[0]);
                area.ymin = Double.Parse(components[1]);
                area.xmax = Double.Parse(components[2]);
                area.ymax = Double.Parse(components[3]);
                var keys   = new C4Key *[1];
                var values = new C4Slice[1];
                keys[0]   = Native.c4key_newGeoJSON("{\"geo\":true}", area);
                values[0] = C4Slice.Constant("1234");
                LiteCoreBridge.Check(err => Native.c4indexer_emit(ind, doc, 0, keys, values, err));
                Native.c4key_free(keys[0]);
                Native.c4doc_free(doc);
            }

            Native.c4enum_free(e);
            error.Code.Should().Be(0, "because otherwise an error occurred somewhere");
            LiteCoreBridge.Check(err => Native.c4indexer_end(ind, true, err));
        }
Exemplo n.º 2
0
        public void TestQuery()
        {
            const bool verbose = true;

            CreateDocs(100, verbose);
            CreateIndex();

            C4GeoArea          area = new C4GeoArea(10, 10, 60, 60);
            C4Error            error;
            C4QueryEnumerator *e = Native.c4view_geoQuery(_view, area, &error);

            Assert.IsTrue(e != null);

            int found = 0;

            foreach (var doc in new CBForestQueryEnumerator(e))
            {
                ++found;
                var a = doc.BoundingBox;
                Assert.IsTrue(doc.Value.Equals("1234"));
                Assert.IsTrue(a.xmin <= 60 && a.xmax >= 10 && a.ymin <= 60 && a.ymax >= 10);
                Assert.IsTrue(doc.GeoJSONRaw.Equals("{\"geo\":true}"));
            }

            Assert.AreEqual(0, error.code);
            Assert.AreEqual(5, found);
        }
Exemplo n.º 3
0
        public void TestQuery()
        {
            RunTestVariants(() => {
                CreateDocs(100);
                CreateIndex();

                var queryArea = new C4GeoArea {
                    xmin = 10,
                    ymin = 10,
                    xmax = 40,
                    ymax = 40
                };

                var e = (C4QueryEnumerator *)LiteCoreBridge.Check(err => Native.c4view_geoQuery(_view,
                                                                                                queryArea, err));

                uint found = 0;
                C4Error error;
                while (Native.c4queryenum_next(e, &error))
                {
                    ++found;
                    var a        = e->geoBBox;
                    var expected = C4Slice.Constant("1234");
                    e->value.Equals(expected).Should().BeTrue("because the value should be correct");
                    a.xmin.Should().BeLessOrEqualTo(40, "because otherwise it is outside the specified area");
                    a.xmax.Should().BeGreaterOrEqualTo(10, "because otherwise it is outside the specified area");
                    a.ymin.Should().BeLessOrEqualTo(40, "because otherwise it is outside the specified area");
                    a.ymax.Should().BeGreaterOrEqualTo(10, "because otherwise it is outside the specified area");

                    expected = C4Slice.Constant("{\"geo\":true}");
                    e->geoJSON.Equals(expected).Should().BeTrue("because the geo JSON should match what was stored");
                }

                Native.c4queryenum_free(e);
                error.Code.Should().Be(0, "because otherwise an error occurred somewhere");
                found.Should().Be(1, "because that is how many entries fall in the given area");
            });
        }