예제 #1
0
        private IList <Package> IndexAndSearch(IEnumerable <Package> packages, string searchTerm, string semVerLevel, string packageType = "")
        {
            Directory d = new RAMDirectory();

            var mockPackageSource = new Mock <IEntityRepository <Package> >();

            mockPackageSource
            .Setup(m => m.GetAll())
            .Returns(packages.AsQueryable());

            var luceneIndexingService = new LuceneIndexingService(
                mockPackageSource.Object,
                d,
                null,
                null,
                new LuceneDocumentFactory(Mock.Of <IIconUrlProvider>()));

            luceneIndexingService.UpdateIndex(forceRefresh: true);

            var luceneSearchService = new LuceneSearchService(d);
            var searchFilter        = new SearchFilter("Test")
            {
                Skip        = 0,
                Take        = 10,
                SearchTerm  = searchTerm,
                SemVerLevel = semVerLevel,
                PackageType = packageType
            };

            var results = luceneSearchService.Search(searchFilter).Result.Data.ToList();

            return(results);
        }
예제 #2
0
        static void TestSearch(string query, string expectedPackageId, int maxExpectedPosition)
        {
            var searchFilter = new SearchFilter
            {
                Skip       = 0,
                Take       = maxExpectedPosition,
                SearchTerm = query,
            };

            int totalHits;
            var results = luceneSearchService.Search(searchFilter, out totalHits).ToList();

            Assert.NotEqual(0, results.Count);
            Assert.Contains(expectedPackageId, results.Select(p => p.PackageRegistration.Id), StringComparer.InvariantCultureIgnoreCase);
            Assert.True(results.Count <= maxExpectedPosition);
        }
예제 #3
0
        private IList <Package> IndexAndSearch(Mock <IPackageSource> packageSource, string searchTerm)
        {
            Directory d = new RAMDirectory();
            var       luceneIndexingService = new LuceneIndexingService(packageSource.Object, d);

            luceneIndexingService.UpdateIndex(forceRefresh: true);

            var luceneSearchService = new LuceneSearchService(d);
            var searchFilter        = new SearchFilter
            {
                Skip       = 0,
                Take       = 10,
                SearchTerm = searchTerm,
            };

            int totalHits;
            var results = luceneSearchService.Search(searchFilter, out totalHits).ToList();

            return(results);
        }
예제 #4
0
        private IList <Package> IndexAndSearch(IEnumerable <Package> packages, string searchTerm, string semVerLevel)
        {
            Directory d = new RAMDirectory();

            var mockPackageSource = new Mock <IEntityRepository <Package> >();

            mockPackageSource
            .Setup(m => m.GetAll())
            .Returns(packages.AsQueryable());

            var mockCuratedPackageSource = new Mock <IEntityRepository <CuratedPackage> >();

            mockCuratedPackageSource
            .Setup(m => m.GetAll())
            .Returns(Enumerable.Empty <CuratedPackage>().AsQueryable());

            var luceneIndexingService = new LuceneIndexingService(
                mockPackageSource.Object,
                mockCuratedPackageSource.Object,
                d,
                null,
                null);

            luceneIndexingService.UpdateIndex(forceRefresh: true);

            var luceneSearchService = new LuceneSearchService(d);
            var searchFilter        = new SearchFilter("Test")
            {
                Skip        = 0,
                Take        = 10,
                SearchTerm  = searchTerm,
                SemVerLevel = semVerLevel
            };

            var results = luceneSearchService.Search(searchFilter).Result.Data.ToList();

            return(results);
        }
        private IList<Package> IndexAndSearch(IEnumerable<Package> packages, string searchTerm)
        {
            Directory d = new RAMDirectory();

            var mockPackageSource = new Mock<IEntityRepository<Package>>();
            mockPackageSource
                .Setup(m => m.GetAll())
                .Returns(packages.AsQueryable());

            var mockCuratedPackageSource = new Mock<IEntityRepository<CuratedPackage>>();
            mockCuratedPackageSource
                .Setup(m => m.GetAll())
                .Returns(Enumerable.Empty<CuratedPackage>().AsQueryable());

            var luceneIndexingService = new LuceneIndexingService(
                mockPackageSource.Object,
                mockCuratedPackageSource.Object,
                d,
                null);
            luceneIndexingService.UpdateIndex(forceRefresh: true);

            var luceneSearchService = new LuceneSearchService(d);
            var searchFilter = new SearchFilter
            {
                Skip = 0,
                Take = 10,
                SearchTerm = searchTerm,
            };

            int totalHits;
            var results = luceneSearchService.Search(searchFilter, out totalHits).ToList();

            return results;
        }
        private IList<Package> IndexAndSearch(Mock<IPackageSource> packageSource, string searchTerm)
        {
            Directory d = new RAMDirectory();
            var luceneIndexingService = new LuceneIndexingService(packageSource.Object, d);
            luceneIndexingService.UpdateIndex(forceRefresh: true);

            var luceneSearchService = new LuceneSearchService(d);
            int totalHits = 0;
            var searchFilter = new SearchFilter
            {
                Skip = 0,
                Take = 10,
                SearchTerm = searchTerm,
            };

            var results = luceneSearchService.Search(
                packageSource.Object.GetPackagesForIndexing(null),
                searchFilter,
                out totalHits).ToList();

            return results;
        }