Esempio n. 1
0
        public void query_gemini_records()
        {
            IDocumentStore store = new DocumentStore {
                Url = RavenUrl
            }.Initialize();

            RavenUtility.WaitForIndexing(store);

            string peakDistrictBbox = BoundingBoxUtility.ToWkt(new BoundingBox
            {
                North = 53.6m,
                South = 53.0m,
                East  = -1.52m,
                West  = -2.14m
            });

            Stopwatch watch = Stopwatch.StartNew();

            using (IDocumentSession db = store.OpenSession())
            {
                List <Record> results = db.Query <Record, RecordSpatialIndex>()
                                        .Customize(x => x.RelatesToShape(FieldNames.Spatial, peakDistrictBbox, SpatialRelation.Intersects))
                                        .Where(i => i.Gemini.Title.StartsWith("GA"))
                                        //.Take(10)
                                        .ToList();

                //results.Count().Should().Be(10);
                Console.WriteLine(results.Count);
            }

            Console.WriteLine(watch.ElapsedMilliseconds);
        }
Esempio n. 2
0
        public void should_count_records_with_duplicate_titles()
        {
            var service = new RecordService(Db, new RecordValidator());

            var record1 = new Record().With(r =>
            {
                r.Id     = new Guid("7ce85158-f6f9-491d-902e-b3f2c8bb5264");
                r.Path   = @"X:\path\to\duplicate\record\1";
                r.Gemini = new Metadata().With(m =>
                {
                    m.Title = "This is a duplicate record";
                    m.Keywords.Add(new MetadataKeyword {
                        Vocab = "http://vocab.jncc.gov.uk/jncc-domain", Value = "Marine"
                    });
                    m.Keywords.Add(new MetadataKeyword {
                        Vocab = "http://vocab.jncc.gov.uk/jncc-category", Value = "Example"
                    });
                });
            });
            var record2 = new Record().With(r =>
            {
                r.Id     = new Guid("afb4ebbf-4286-47ed-b09f-a4d40af139e1");
                r.Path   = @"X:\path\to\duplicate\record\2";
                r.Gemini = new Metadata().With(m =>
                {
                    m.Title = "This is a duplicate record";
                    m.Keywords.Add(new MetadataKeyword {
                        Vocab = "http://vocab.jncc.gov.uk/jncc-domain", Value = "Marine"
                    });
                    m.Keywords.Add(new MetadataKeyword {
                        Vocab = "http://vocab.jncc.gov.uk/jncc-category", Value = "Example"
                    });
                });
            });

            service.Insert(record1, TestUser);
            service.Insert(record2, TestUser);

            Db.SaveChanges();
            RavenUtility.WaitForIndexing(Db);

            var results = Db.Query <RecordsWithDuplicateTitleCheckerIndex.Result, RecordsWithDuplicateTitleCheckerIndex>()
                          .Where(x => x.Count > 1)
                          .Take(100)
                          .ToList();

            // looks like we have some duplicates created by the seeder!
            results.Count.Should().BeInRange(1, 10); // perhaps prevent more duplicate titles being seeded in the future!
            results.Should().Contain(r => r.Title == "This is a duplicate record");
        }
        public void highlighting_should_work_with_wildcard_queries()
        {
            var store = new EmbeddableDocumentStore {
                RunInMemory = true
            };

            store.Initialize();

            using (IDocumentSession db = store.OpenSession())
            {
                db.Store(new Item
                {
                    Title =
                        "On the 9th. William Findley and David Redick--deputed by the Committee of Safety (as it is designated) which met on the 2d. of this month at Parkinson Ferry arrived in Camp with the Resolutions of the said Committee; and to give information of the State of things in the four Western Counties of Pennsylvania to wit--Washington Fayette Westd. & Alligany in order to see if it would prevent the March of the Army into them."
                });
                db.Store(new Item
                {
                    Title =
                        "At 10 oclock I had a meeting with these persons in presence of Govr. Howell (of New Jersey) the Secretary of the Treasury, Colo. Hamilton, & Mr. Dandridge: Govr. Mifflin was invited to be present, but excused himself on acct. of business."
                });
                db.Store(new Item
                {
                    Title =
                        "Mr. Findley began. He confined his information to such parts of the four Counties as he was best acquainted with; referring to Mr. Reddick for a recital of what fell within his knowledge, in the other parts of these Counties"
                });
                db.SaveChanges();
            }

            new SearchIndex().Execute(store);
            RavenUtility.WaitForIndexing(store);

            using (IDocumentSession db = store.OpenSession())
            {
                Func <string, FieldHighlightings> execute = q =>
                {
                    FieldHighlightings lites;
                    db.Advanced.DocumentQuery <Item>("SearchIndex")
                    .WaitForNonStaleResultsAsOfNow()
                    .Highlight("Title", 128, 2, out lites)
                    .Search("Title", q)
                    .ToList();
                    return(lites);
                };

                execute("committee").ResultIndents.Should().NotBeEmpty();  // succeeds
                execute("committee*").ResultIndents.Should().NotBeEmpty(); // fails
            }
        }
        public void ShouldGetRightResults()
        {
            var documentStore = DatabaseFactory.InMemory(8889);

            new RecordIndex().Execute(documentStore);

            using (var db = documentStore.OpenSession())
            {
                new[] { "foo", "foo (bar)" }.Select(MakeRecord).ForEach(db.Store);

                db.SaveChanges();
            }

            RavenUtility.WaitForIndexing(documentStore);

            using (var db = documentStore.OpenSession())
            {
                Action <string, int> testCase = (k, n) =>
                {
//                    var query = db.Query<MyIndex.Result, MyIndex>()
//                        .Where(r => r.Keywords.Contains(k));
//                    var results = query.As<Record>().Take(10).ToList();
//                    results.Count.Should().Be(n);

                    var input  = EmptyQuery().With(q => q.F.Keywords = new[] { k });
                    var output = new RecordQueryer(db).Search(input);
                    output.Total.Should().Be(n);
                };

                // todo how to deal with empty keyword?
//                testCase("", 0);
                testCase("http://vocab/xxx", 0);
//                testCase("http://vocab/foo", 1);
//                testCase("http://vocab/foo (xxx)", 0);
//                testCase("http://vocab/foo (bar)", 1);
//                testCase("http://vocab/foo - (xxx)", 0);
            }
        }