コード例 #1
0
        public async void CanVerifyNonExistentDocument()
        {
            var searchIndexer = new AzureSearchIndex(Configuration.SearchServiceName, Configuration.SearchAdminKey);
            var doesExist     = await searchIndexer.VerifyDocumentAvailable("123", 5);

            Assert.False(doesExist);
        }
コード例 #2
0
        public async void CanIndexPlainTextDocuments()
        {
            var documentId1   = rng.Next(1000, 10000).ToString();
            var textContent1  = "This is some special content to index again, even though you already did.";
            var documentId2   = rng.Next(1000, 10000).ToString();
            var textContent2  = "In other cases, you may want to look for content that isn't so special";
            var searchText    = "special content";
            var searchIndexer = new AzureSearchIndex(Configuration.SearchServiceName, Configuration.SearchAdminKey);

            try
            {
                await searchIndexer.IndexTextContentAsync(documentId1, textContent1);

                await searchIndexer.IndexTextContentAsync(documentId2, textContent2);

                await searchIndexer.VerifyDocumentAvailable(documentId1, 5);

                await searchIndexer.VerifyDocumentAvailable(documentId2, 5);

                var results = await searchIndexer.QuerySearchIndexAsync(searchText);

                Assert.Equal(2, results.Count);
            }
            finally
            {
                await searchIndexer.RemoveTextContentAsync(documentId1);

                await searchIndexer.RemoveTextContentAsync(documentId2);
            }
        }
コード例 #3
0
        public async void SupportProximitySearch(string searchText, int expectedResultCount)
        {
            var documentId    = rng.Next(1000, 10000).ToString();
            var textContent   = "This is a file that may contain a keyword such as police, discrimination, or abuse.";
            var searchIndexer = new AzureSearchIndex(Configuration.SearchServiceName, Configuration.SearchAdminKey);

            try
            {
                await searchIndexer.IndexTextContentAsync(documentId, textContent);

                await searchIndexer.VerifyDocumentAvailable(documentId, 5);

                var results = await searchIndexer.QueryDocumentAsync(documentId, searchText);

                Assert.Equal(expectedResultCount, results.Count);
            }
            finally
            {
                await searchIndexer.RemoveTextContentAsync(documentId);
            }
        }
コード例 #4
0
        public async void SupportMultipleCriteriaWithSingleQuery(string queryText, bool doesMatch)
        {
            var documentId    = rng.Next(1000, 10000).ToString();
            var textContent   = "This sentence will hit on one word, but the query contains multiple keywords.";
            var searchIndexer = new AzureSearchIndex(Configuration.SearchServiceName, Configuration.SearchAdminKey);

            try
            {
                await searchIndexer.IndexTextContentAsync(documentId, textContent);

                await searchIndexer.VerifyDocumentAvailable(documentId, 5);

                var results = await searchIndexer.QueryDocumentAsync(documentId, queryText, true);

                Assert.Equal(doesMatch, (results.Count == 1));
            }
            finally
            {
                await searchIndexer.RemoveTextContentAsync(documentId);
            }
        }
コード例 #5
0
        public async void SupportExclusionCriteria(string searchText, int expectedResultCount)
        {
            var documentId    = rng.Next(1000, 10000).ToString();
            var textContent   = "This phrase will contain WHISTLEBLOWER but not the secret word.";
            var searchIndexer = new AzureSearchIndex(Configuration.SearchServiceName, Configuration.SearchAdminKey);

            try
            {
                await searchIndexer.IndexTextContentAsync(documentId, textContent);

                await searchIndexer.VerifyDocumentAvailable(documentId, 5);

                var results = await searchIndexer.QueryDocumentAsync(documentId, searchText);

                Assert.Equal(expectedResultCount, results.Count);
            }
            finally
            {
                await searchIndexer.RemoveTextContentAsync(documentId);
            }
        }
コード例 #6
0
        public async Task ExecutesFullIntegrationPass()
        {
            var jobStatusStore = new JobStatusStore(Configuration.StorageConnectionString, Configuration.JobStatusContainerName);
            var blobReader     = new AzureBlobReader(Configuration.StorageConnectionString, Configuration.FileUploadContainerName);
            var extractor      = new TextFileContentExtractor();
            var searchIndex    = new AzureSearchIndex(Configuration.SearchServiceName, Configuration.SearchAdminKey);
            var docScorer      = new TextDocumentScorer(searchIndex);
            var workflow       = new ParsingWorkflow(jobStatusStore, blobReader, extractor, searchIndex, docScorer);

            var blobId  = Guid.NewGuid().ToString().Replace("-", String.Empty);
            var jobId   = Guid.NewGuid().ToString().Replace("-", String.Empty);
            var blobUri = String.Format("{0}/{1}", jobId, blobId);

            var blobDetails = new BlobDetails();

            blobDetails.ContainerName = Configuration.FileUploadContainerName;
            blobDetails.FullBlobPath  = blobUri;
            blobDetails.DocumentId    = blobId;
            blobDetails.JobId         = jobId;

            var job = new JobStatus();

            job.OriginalFileName = "not-real-file.txt";
            job.IsComplete       = false;
            job.JobStartTime     = DateTime.UtcNow;
            job.JobId            = jobId;

            await jobStatusStore.UpdateStatusAsync(job);

            await createSampleBlob(blobUri);

            await workflow.ExecuteAsync(blobDetails);

            job = await jobStatusStore.ReadStatusAsync(jobId);

            var categoryCount = job.Categories.Length;

            Assert.Equal(1, categoryCount);
            Assert.Equal("Heavy Hitter", job.Categories[0]);
        }
コード例 #7
0
        public async void CanSearchSingleDocument()
        {
            var documentId    = rng.Next(1000, 10000).ToString();
            var textContent   = "This is text for a single document, that may contain information about a police report.";
            var searchText    = "police report";
            var searchIndexer = new AzureSearchIndex(Configuration.SearchServiceName, Configuration.SearchAdminKey);

            try
            {
                await searchIndexer.IndexTextContentAsync(documentId, textContent);

                await searchIndexer.VerifyDocumentAvailable(documentId, 5);

                var results = await searchIndexer.QueryDocumentAsync(documentId, searchText);

                Assert.Equal(1, results.Count);
                Assert.Equal(documentId, results.Results.First().Document.DocumentId);
            }
            finally
            {
                await searchIndexer.RemoveTextContentAsync(documentId);
            }
        }
コード例 #8
0
 //[Fact]
 public async Task ClearSearchIndex()
 {
     var searchIndex = new AzureSearchIndex(Configuration.SearchServiceName, Configuration.SearchAdminKey);
     await searchIndex.ClearSearchIndex();
 }