// POST api/<controller>
        public SearchResult[] Post()
        {
            var httpPostedFile = HttpContext.Current.Request.Files["file"];

            if (httpPostedFile == null)
            {
                ThowError("No file uploaded.");
                return(null);
            }

            string baseFileName = System.IO.Path.GetFileName(httpPostedFile.FileName);

            byte[] fileBytes = PdfHelper.ReadFully(httpPostedFile.InputStream);
            string content   = PdfHelper.GetTextFromPdfBytes(fileBytes);

            if (string.IsNullOrEmpty(content))
            {
                ThowError("No content found for file: " + baseFileName);
                return(null);
            }

            // Save original file
            string fileUrl = AzureStorageHelper.UploadBlob(fileBytes, baseFileName);

            if (string.IsNullOrEmpty(fileUrl))
            {
                ThowError("Could not upload file to azure.");
                return(null);
            }

            // Add to index
            SearchDocument document = new SearchDocument
            {
                DocId       = Guid.NewGuid().ToString(),
                Content     = content,
                DocFileName = baseFileName,
                DocUrl      = fileUrl,
                InsertDate  = DateTime.UtcNow
            };

            if (!AzureSearchHelper.InsertDocument(document))
            {
                ThowError("Could not add document to the index. If this is the first time you are using the index you need to click on the 'Delete all documents and rebuild index button' first.");
            }

            return(AzureSearchHelper.CategorizeDocument(document.DocId));
        }
예제 #2
0
 public SearchResult[] Recategorize(string docId)
 {
     // Recategorize doc
     return(AzureSearchHelper.CategorizeDocument(docId));
 }