public void Can_use_the_same_index_writer_for_multiple_index_operations()
        {
            var repo = new Repository();

            var writer = new MemoryIndexWriter(true);
            var indexService = new IndexService(writer);

            var p1p5 = repo.Products.Skip(0).Take(5);
            var result = indexService.IndexEntities(p1p5, new ProductIndexDefinition());
            Assert.AreEqual(5, result.Count);

            var p6p10 = repo.Products.Skip(5).Take(5);
            var result2 = indexService.IndexEntities(p6p10, new ProductIndexDefinition());
            Assert.AreEqual(5,result2.Count);

            var searcher = new MemoryIndexSearcher(writer.Directory, true);

            var searchResult = new SearchService(searcher).SearchIndex(new TermQuery(new Term("type", "product")));

            Assert.AreEqual(0, searchResult.Documents.Count(), "Index writer has not yet been committed so should return 0");
            // commits writer
            indexService.Dispose();

            searchResult = new SearchService(searcher).SearchIndex(new TermQuery(new Term("type", "product")));
            Assert.AreEqual(10, searchResult.Documents.Count());
        }
        public void Can_use_the_same_index_writer_for_multiple_index_operations()
        {
            var repo = new Repository();

            var writer       = new MemoryIndexWriter(true);
            var indexService = new IndexService(writer);

            var p1p5   = repo.Products.Skip(0).Take(5);
            var result = indexService.IndexEntities(p1p5, new ProductIndexDefinition());

            Assert.AreEqual(5, result.Count);

            var p6p10   = repo.Products.Skip(5).Take(5);
            var result2 = indexService.IndexEntities(p6p10, new ProductIndexDefinition());

            Assert.AreEqual(5, result2.Count);

            var searcher = new MemoryIndexSearcher(writer.Directory, true);

            var searchResult = new SearchService(searcher).SearchIndex(new TermQuery(new Term("type", "product")));

            Assert.AreEqual(0, searchResult.Documents.Count(), "Index writer has not yet been committed so should return 0");
            // commits writer
            indexService.Dispose();

            searchResult = new SearchService(searcher).SearchIndex(new TermQuery(new Term("type", "product")));
            Assert.AreEqual(10, searchResult.Documents.Count());
        }
        public void Can_search_index()
        {
            var indexSearcher = new MemoryIndexSearcher(directory, true);
            var searchService = new SearchService(indexSearcher);

            var result = searchService.SearchIndex(new ProductQuery().WithId(5).Query);
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Documents.Count());
        }
        public void Can_search_index()
        {
            var indexSearcher = new MemoryIndexSearcher(directory, true);
            var searchService = new SearchService(indexSearcher);

            var result = searchService.SearchIndex(new ProductQuery().WithId(5).Query);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Documents.Count());
        }
        public void Can_transform_results_with_result_definition()
        {
            var indexSearcher = new MemoryIndexSearcher(directory, true);
            var searchService = new SearchService(indexSearcher);

            var result = searchService.SearchIndex(
                new TermQuery(new Term("type", "product")),
                new ProductResultDefinition()
                );

            Assert.IsNotNull(result);
            Assert.AreEqual(10, result.Results.Count());
        }
        public void Can_transform_results_with_result_definition()
        {
            var indexSearcher = new MemoryIndexSearcher(directory, true);
            var searchService = new SearchService(indexSearcher);

            var result = searchService.SearchIndex(
                new TermQuery(new Term("type", "product")),
                new ProductResultDefinition()
            );

            Assert.IsNotNull(result);
            Assert.AreEqual(10, result.Results.Count());
        }
        public void Can_transform_results_with_delegate_definition()
        {
            var indexSearcher = new MemoryIndexSearcher(directory, true);
            var searchService = new SearchService(indexSearcher);

            var result = searchService.SearchIndex(
                new TermQuery(new Term("id", "1")),
                doc => {
                    return new Product { Name = doc.Get("name") };
                });

            Assert.AreEqual(result.Results.Count(), 1);
            Assert.AreEqual(result.Results.First().Name, "Football");
        }
        public void Can_transform_results_with_delegate_definition()
        {
            var indexSearcher = new MemoryIndexSearcher(directory, true);
            var searchService = new SearchService(indexSearcher);

            var result = searchService.SearchIndex(
                new TermQuery(new Term("id", "1")),
                doc => {
                return(new Product {
                    Name = doc.Get("name")
                });
            });

            Assert.AreEqual(result.Results.Count(), 1);
            Assert.AreEqual(result.Results.First().Name, "Football");
        }