public void ASearchCanOrderByMultipleFields()
        {
            SearchableContextProvider <TestDbContext> searchProvider = new SearchableContextProvider <TestDbContext>();
            LuceneIndexerOptions options = new LuceneIndexerOptions(null, null, true);

            User jc = new User()
            {
                FirstName = "John",
                Surname   = "Chapman",
                JobTitle  = "Test Engineer",
                IndexId   = Guid.NewGuid(),
                Email     = "*****@*****.**"
            };

            searchProvider.Initialize(options, context);

            context.Users.Add(jc);
            context.SaveChanges();

            searchProvider.CreateIndex();

            SearchOptions search = new SearchOptions("John", "FirstName", 1000, null, null, "Surname,JobTitle");

            var results = searchProvider.ScoredSearch <User>(search);

            var topResult    = results.Results[0];
            var secondResult = results.Results[1];

            Assert.AreEqual("Sales Associate", topResult.Entity.JobTitle);
            Assert.AreEqual("Test Engineer", secondResult.Entity.JobTitle);

            searchProvider.DeleteIndex();
        }
Exemplo n.º 2
0
        public void SkipAndTakeWorkWhenSearchingUsingAContextProvider()
        {
            InitializeContext();
            SearchableContextProvider <TestDbContext> searchProvider = new SearchableContextProvider <TestDbContext>();
            LuceneIndexerOptions options = new LuceneIndexerOptions {
                UseRamDirectory = true
            };

            searchProvider.Initialize(options, context);

            searchProvider.CreateIndex();

            SearchOptions searchOptions = new SearchOptions("John", "FirstName");

            // test
            var initialResults = searchProvider.ScoredSearch <User>(searchOptions);
            int lastId         = initialResults.Results[4].Entity.Id;

            Assert.Equal(5, initialResults.TotalHits);
            Assert.Equal(5, initialResults.Results.Count());

            searchOptions.Skip = 4;
            searchOptions.Take = 1;
            var subResults = searchProvider.ScoredSearch <User>(searchOptions);

            Assert.Equal(5, subResults.TotalHits);
            Assert.Equal(1, subResults.Results.Count());
            Assert.Equal(lastId, subResults.Results.First().Entity.Id);

            // cleanup
            searchProvider.DeleteIndex();
        }
Exemplo n.º 3
0
        public void AScoredSearchWillOrderByRelevence()
        {
            InitializeContext();
            SearchableContextProvider <TestDbContext> searchProvider = new SearchableContextProvider <TestDbContext>();
            LuceneIndexerOptions options = new LuceneIndexerOptions {
                UseRamDirectory = true
            };

            searchProvider.Initialize(options, context);

            searchProvider.CreateIndex();

            SearchOptions searchOptions = new SearchOptions("Jeremy Burns", "FirstName,Surname");

            var results = searchProvider.ScoredSearch <User>(searchOptions);

            var first   = results.Results.First().Entity;
            var highest = results.Results.First().Score;
            var lowest  = results.Results.Last().Score;

            Assert.True(highest > lowest);
            Assert.Equal("Jeremy", first.FirstName);
            Assert.Equal("Burns", first.Surname);

            searchProvider.DeleteIndex();
        }
        public void AContextProviderCanIndexADatabase()
        {
            SearchableContextProvider <TestDbContext> searchProvider = new SearchableContextProvider <TestDbContext>();
            LuceneIndexerOptions options = new LuceneIndexerOptions(null, null, true);

            searchProvider.Initialize(options, context);

            searchProvider.CreateIndex();

            Assert.AreEqual(2000, searchProvider.IndexCount);

            // cleanup
            searchProvider.DeleteIndex();
        }
Exemplo n.º 5
0
        public void AContextProviderCanIndexADatabase()
        {
            InitializeContext();
            SearchableContextProvider <TestDbContext> searchProvider = new SearchableContextProvider <TestDbContext>();
            LuceneIndexerOptions options = new LuceneIndexerOptions {
                UseRamDirectory = true
            };

            searchProvider.Initialize(options, context);

            searchProvider.CreateIndex();

            Assert.Equal(2000, searchProvider.IndexCount);

            // cleanup
            searchProvider.DeleteIndex();
        }
        public void AContextCanBeSearchedUsingAContextProvider()
        {
            SearchableContextProvider <TestDbContext> searchProvider = new SearchableContextProvider <TestDbContext>();
            LuceneIndexerOptions options = new LuceneIndexerOptions(null, null, true);

            searchProvider.Initialize(options, context);

            searchProvider.CreateIndex();

            SearchOptions searchOptions = new SearchOptions("John", "FirstName");

            // test
            var results = searchProvider.ScoredSearch <User>(searchOptions);

            Assert.AreEqual(5, results.TotalHits);

            // cleanup
            searchProvider.DeleteIndex();
        }
        public void ASearchWillReturnTheSameResultsAsAScoredSearch()
        {
            SearchableContextProvider <TestDbContext> searchProvider = new SearchableContextProvider <TestDbContext>();
            LuceneIndexerOptions options = new LuceneIndexerOptions(null, null, true);

            searchProvider.Initialize(options, context);

            searchProvider.CreateIndex();

            SearchOptions searchOptions = new SearchOptions("Joh*", "FirstName");

            // test
            var results = searchProvider.Search <User>(searchOptions);

            Assert.AreEqual(10, results.TotalHits);

            // cleanup
            searchProvider.DeleteIndex();
        }
        public void ASearchWillStillOrderByRelevence()
        {
            SearchableContextProvider <TestDbContext> searchProvider = new SearchableContextProvider <TestDbContext>();
            LuceneIndexerOptions options = new LuceneIndexerOptions(null, null, true);

            searchProvider.Initialize(options, context);

            searchProvider.CreateIndex();

            SearchOptions searchOptions = new SearchOptions("Jeremy Burns", "FirstName,Surname");

            var results = searchProvider.Search <User>(searchOptions);

            var first = results.Results.First();

            Assert.AreEqual("Jeremy", first.FirstName);
            Assert.AreEqual("Burns", first.Surname);

            searchProvider.DeleteIndex();
        }
Exemplo n.º 9
0
        public void AContextCanBeSearchedUsingAWildCard()
        {
            InitializeContext();
            SearchableContextProvider <TestDbContext> searchProvider = new SearchableContextProvider <TestDbContext>();
            LuceneIndexerOptions options = new LuceneIndexerOptions {
                UseRamDirectory = true
            };

            searchProvider.Initialize(options, context);

            searchProvider.CreateIndex();

            SearchOptions searchOptions = new SearchOptions("Joh*", "FirstName");

            // test
            var results = searchProvider.ScoredSearch <User>(searchOptions);

            PrintResult(results);

            Assert.Equal(10, results.TotalHits);

            // cleanup
            searchProvider.DeleteIndex();
        }