示例#1
0
        public async Task <IActionResult> Upload()
        {
            foreach (var formFile in Request.Form.Files)
            {
                if (formFile.Length > 0)
                {
                    BlobStorageConfig config = _storageConfig.Copy();
                    config.ContainerName = config.UploadContainerName;

                    await BlobStorageClient.UploadBlobAsync(config,
                                                            Path.GetFileNameWithoutExtension(formFile.FileName) + "/" + formFile.FileName,
                                                            formFile.OpenReadStream());

                    var telemetryDict = new Dictionary <string, string>
                    {
                        { "FileName", formFile.FileName },
                        { "StorageAccountName", _searchConfig.ServiceName },
                        { "ContainerName", _storageConfig.ContainerName }
                    };

                    _telemetryClient.TrackEvent("FileUpload", telemetryDict);
                }
            }
            //await _searchClient.RunIndexer();
            return(new JsonResult("ok"));
        }
        public async Task <IActionResult> FilterFacets(string facetname, FacetsFilteringRequest searchRequest)
        {
            // Calculate the response for each value.
            var response = new FacetsFilteringResponse();

            response.Values = new List <FacetRecord>();

            string[] commonList = new string[] { };
            string[] list       = new string[] { };
            try
            {
                BlobStorageConfig config = _storageConfig.Copy();
                config.ContainerName = config.FacetsFilteringContainerName;
                string s = await BlobStorageClient.ReadBlobAsync(config, "commonfilters.txt");

                commonList = s.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);

                s = await BlobStorageClient.ReadBlobAsync(config, string.Format("{0}.txt", facetname));

                list = s.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
            }
            catch (Exception)
            {
            }
            Trace.TraceInformation("facet: " + facetname);
            Trace.TraceInformation("number of values:" + searchRequest.Values.Count);
            foreach (var record in searchRequest.Values)
            {
                if (record == null || record.RecordId == null)
                {
                    continue;
                }

                FacetRecord responseRecord = new FacetRecord();
                responseRecord.RecordId = record.RecordId;

                try
                {
                    List <string> restrictionList = new List <string>(commonList);
                    restrictionList.AddRange(list);

                    var outputRecord = new FacetData();
                    outputRecord.Facets = new List <string>();
                    Trace.TraceInformation("number of facets:" + record.Data.Facets.Count);

                    // replace all non-alphbic characters before comparision
                    Regex rgx = new Regex("[^a-zA-Z0-9 ]");

                    for (int i = 0; i < restrictionList.Count; i++)
                    {
                        restrictionList[i] = rgx.Replace(restrictionList[i], "").ToLower();
                    }

                    foreach (string phrase in record.Data.Facets)
                    {
                        var str = rgx.Replace(phrase, "").ToLower();
                        if (!string.IsNullOrEmpty(str))
                        {
                            //lower case the first letter
                            //str = Char.ToLower(str[0]) + str.Substring(1);

                            if (!restrictionList.Contains(str))
                            {
                                outputRecord.Facets.Add(phrase);
                            }
                        }
                    }

                    //UpdateGraph(outputRecord.Facets, facetname);

                    responseRecord.Data = outputRecord;
                }
                catch (Exception e)
                {
                }
                finally
                {
                    response.Values.Add(responseRecord);
                }
            }


            return(new OkObjectResult(response));
        }