Пример #1
0
        public void TransformLoadResult()
        {
            var station = new LearningStation
            {
                Code = "WKOMORE"
            };

            using (var documentStore = NewDocumentStore())
            {
                documentStore.ConfigureForNodaTime();
                new ContractSpotLineStationTransformer().Execute(documentStore);

                using (var session = documentStore.OpenSession())
                {
                    session.Store(station);

                    var spotLine = new LearningContractSpotLine
                    {
                        Month      = new LocalDate(2015, 02, 01),
                        StationIds = new[] { station.Id }
                    };

                    session.Store(spotLine);

                    session.SaveChanges();
                }

                using (var session = documentStore.OpenSession())
                {
                    var result = session.Load <ContractSpotLineStationTransformer, ContractSpotLineStationTransformer.ContractSpotLineStation>("contractspotlines/1");

                    Assert.Equal(result.Station, station.Code);
                }
            }
        }
        public void QueryFullTextStaticIndex()
        {
            using (var documentStore = NewDocumentStore())
            {
                documentStore.ConfigureForNodaTime();

                using (var session = documentStore.OpenSession())
                {
                    var spotLine = new LearningContractSpotLine
                    {
                        Month = new LocalDate(2015, 02, 01),
                        StationDescription = "WKO(MORE, ROCK, EDGE), AKL(MORE, ROCK, EDGE)",
                        Contract           = new LearningContract {
                            Code = "11223344", Id = "contracts/12345"
                        }
                    };
                    session.Store(spotLine);
                    session.SaveChanges();
                }

                // have to create the index in the embedded test database per test run...
                IndexCreation.CreateIndexes(typeof(SpotLines_ByStationDescription_FullText).Assembly, documentStore);

                using (var session = documentStore.OpenSession())
                {
                    var monthToQuery = new LocalDate(2015, 02, 01);

                    RavenQueryStatistics statistics;
                    //var linesForMonth = session.Advanced
                    //                            .LuceneQuery<ContractSpotLine>("SpotLines/ByStationDescription/FullText")
                    //                            .WaitForNonStaleResults(TimeSpan.FromSeconds(5))
                    //                            .Where("StationDescription:WKO -StationDescription:MCH")
                    //                            .Statistics(out statistics)
                    //                            .ToList();
                    // above is explicit use of LuceneQuery and is equivalent to:
                    var linesForMonth = session.Query <LearningContractSpotLine, SpotLines_ByStationDescription_FullText>()
                                        .Customize(q => q.WaitForNonStaleResults(TimeSpan.FromSeconds(5)))
                                        .Search(c => c.StationDescription, "WKO")
                                        .Search(c => c.StationDescription, "MCH", options: SearchOptions.And | SearchOptions.Not)
                                        .Statistics(out statistics)
                                        .ToList();

                    Assert.Equal("SpotLines/ByStationDescription/FullText", statistics.IndexName);
                    Assert.Equal(1, linesForMonth.Count);

                    //linesForMonth = session.Advanced
                    //                        .LuceneQuery<ContractSpotLine>("SpotLines/ByStationDescription/FullText")
                    //                        .Where("StationDescription:WKO AND StationDescription:MCH")
                    //                        .ToList();
                    linesForMonth = session.Query <LearningContractSpotLine, SpotLines_ByStationDescription_FullText>()
                                    .Search(c => c.StationDescription, "WKO")
                                    .Search(c => c.StationDescription, "MCH", options: SearchOptions.And)
                                    .ToList();

                    Assert.Equal(0, linesForMonth.Count);
                }
            }
        }
        public void QuerySimpleStaticIndex()
        {
            using (var documentStore = NewDocumentStore())
            {
                documentStore.ConfigureForNodaTime();

                using (var session = documentStore.OpenSession())
                {
                    var spotLine = new LearningContractSpotLine
                    {
                        Month    = new LocalDate(2015, 02, 01),
                        Contract = new LearningContract {
                            Code = "11223344", Id = "contracts/12345"
                        }
                    };
                    session.Store(spotLine);
                    session.SaveChanges();
                }

                // have to create the index in the embedded test database per test run...
                //IndexCreation.CreateIndexes(typeof(SpotLines_ByMonth).Assembly, documentStore);
                // just create the one index, not all in this assembly (as our assert checks the index used)
                new SpotLines_ByMonth().Execute(documentStore);

                using (var session = documentStore.OpenSession())
                {
                    var monthToQuery = new LocalDate(2015, 02, 01);
                    // the index to query can be explictly specified - more useful in the case of
                    // a more complex index/query
                    //var linesForMonth = session.Query<ContractSpotLine, SpotLines_ByMonth>()
                    //                            .Where(c => c.Month == monthToQuery)
                    //                            .ToList();

                    RavenQueryStatistics statistics;
                    var linesForMonth = session.Query <LearningContractSpotLine>()
                                        .Statistics(out statistics)
                                        .Customize(q => q.WaitForNonStaleResults(TimeSpan.FromSeconds(5)))
                                        .Where(c => c.Month == monthToQuery)
                                        .ToList();

                    Assert.Equal("SpotLines/ByMonth", statistics.IndexName);
                    Assert.Equal(1, linesForMonth.Count);
                }
            }
        }
Пример #4
0
        public void ProjectFromStoredFields()
        {
            var station = new LearningStation
            {
                Code = "WKOMORE"
            };

            using (var documentStore = NewDocumentStore())
            {
                documentStore.ConfigureForNodaTime();
                new SpotLines_ByFirstStationStored().Execute(documentStore);

                using (var session = documentStore.OpenSession())
                {
                    session.Store(station);

                    var spotLine = new LearningContractSpotLine
                    {
                        Month = new LocalDate(2015, 02, 01),
                        StationDescription = "Temp Description - Store As Code In Index",
                        StationIds         = new[] { station.Id }
                    };

                    session.Store(spotLine);

                    session.SaveChanges();
                }

                using (var session = documentStore.OpenSession())
                {
                    // transform ContractSpotLine results to StationViewModel by pulling the available fields
                    // from equivalent index stored fields.
                    var stations = session.Query <LearningContractSpotLine, SpotLines_ByFirstStationStored>()
                                   .Customize(q => q.WaitForNonStaleResults(TimeSpan.FromSeconds(5)))
                                   .ProjectFromIndexFieldsInto <SpotLines_ByFirstStationStored.StationViewModel>()
                                   .ToList();

                    Assert.Equal(stations.FirstOrDefault().StationCode, station.Code);
                }
            }
        }
Пример #5
0
        public void TransformQueryResult()
        {
            var station = new LearningStation
            {
                Code = "WKOMORE"
            };

            using (var documentStore = NewDocumentStore())
            {
                documentStore.ConfigureForNodaTime();
                new ContractSpotLineStationTransformer().Execute(documentStore);

                using (var session = documentStore.OpenSession())
                {
                    session.Store(station);

                    var spotLine = new LearningContractSpotLine
                    {
                        Month      = new LocalDate(2015, 02, 01),
                        StationIds = new[] { station.Id }
                    };

                    session.Store(spotLine);

                    session.SaveChanges();
                }

                using (var session = documentStore.OpenSession())
                {
                    var results = session.Query <LearningContractSpotLine>()
                                  .TransformWith <ContractSpotLineStationTransformer, ContractSpotLineStationTransformer.ContractSpotLineStation>()
                                  .Customize(q => q.WaitForNonStaleResults(TimeSpan.FromSeconds(5)))
                                  .ToList();

                    Assert.Equal(results.FirstOrDefault().Station, station.Code);
                }
            }
        }
        public void QueryMapReduceStaticIndex()
        {
            using (var documentStore = NewDocumentStore())
            {
                documentStore.ConfigureForNodaTime();

                using (var session = documentStore.OpenSession())
                {
                    var spotLine = new LearningContractSpotLine
                    {
                        Month    = new LocalDate(2015, 02, 01),
                        Contract = new LearningContract {
                            Code = "11223344", Id = "contracts/12345"
                        }
                    };
                    session.Store(spotLine);
                    session.SaveChanges();
                }

                // have to create the index in the embedded test database per test run...
                IndexCreation.CreateIndexes(typeof(SpotLines_LineCountByMonth).Assembly, documentStore);

                using (var session = documentStore.OpenSession())
                {
                    var monthToQuery = new LocalDate(2015, 02, 01);

                    RavenQueryStatistics statistics;
                    var linesForMonth = session.Query <SpotLines_LineCountByMonth.ReduceResult, SpotLines_LineCountByMonth>()
                                        .Statistics(out statistics)
                                        .Customize(q => q.WaitForNonStaleResults(TimeSpan.FromSeconds(5)))
                                        .FirstOrDefault(c => c.Month == monthToQuery);

                    Assert.Equal("SpotLines/LineCountByMonth", statistics.IndexName);
                    Assert.Equal(1, linesForMonth.Count);
                }
            }
        }
        public void QueryAndUseSuggestsionsOfStaticIndex()
        {
            using (var documentStore = NewDocumentStore())
            {
                documentStore.ConfigureForNodaTime();

                using (var session = documentStore.OpenSession())
                {
                    var spotLine = new LearningContractSpotLine
                    {
                        Month = new LocalDate(2015, 02, 01),
                        StationDescription = "WKOO",
                        Contract           = new LearningContract {
                            Code = "11223344", Id = "contracts/12345"
                        }
                    };

                    session.Store(spotLine);

                    spotLine = new LearningContractSpotLine
                    {
                        Month = new LocalDate(2015, 02, 01),
                        StationDescription = "WKOMORE",
                        Contract           = new LearningContract {
                            Code = "11223344", Id = "contracts/12345"
                        }
                    };

                    session.Store(spotLine);

                    spotLine = new LearningContractSpotLine
                    {
                        Month = new LocalDate(2015, 02, 01),
                        StationDescription = "WKO",
                        Contract           = new LearningContract {
                            Code = "11223344", Id = "contracts/12345"
                        }
                    };

                    session.Store(spotLine);
                    session.SaveChanges();
                }

                // have to create the index in the embedded test database per test run...
                new SpotLines_ByStationDescription_FullText().Execute(documentStore);

                using (var session = documentStore.OpenSession())
                {
                    var monthToQuery = new LocalDate(2015, 02, 01);

                    RavenQueryStatistics statistics;
                    var linesForMonth = session.Query <LearningContractSpotLine, SpotLines_ByStationDescription_FullText>()
                                        .Customize(q => q.WaitForNonStaleResults(TimeSpan.FromSeconds(5)))
                                        .Statistics(out statistics)
                                        .Where(c => c.StationDescription == "wkoe");

                    var resultCount = linesForMonth.ToList().Count;
                    Assert.Equal("SpotLines/ByStationDescription/FullText", statistics.IndexName);
                    Assert.Equal(0, resultCount);

                    if (resultCount <= 0)
                    {
                        var suggestionResult = linesForMonth.Suggest();
                        foreach (var suggestion in suggestionResult.Suggestions)
                        {
                            Assert.NotNull(suggestion);
                        }
                    }
                }
            }
        }