Exemple #1
0
        public static IActionResult GetFacetGraphNodes([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, TraceWriter log, ExecutionContext executionContext)
        {
            string skillName = executionContext.FunctionName;

            if (!req.QueryString.HasValue)
            {
                return(new BadRequestObjectResult($"{skillName} - Requires a query string in the following format: q=oswald&f=entities"));
            }

            string searchServiceName   = GetAppSetting("SearchServiceName");
            string searchServiceApiKey = GetAppSetting("SearchServiceApiKey");
            string indexName           = String.IsNullOrEmpty(req.Headers["IndexName"]) ? Config.AZURE_SEARCH_INDEX_NAME : (string)req.Headers["IndexName"];

            if (String.IsNullOrEmpty(searchServiceName) || String.IsNullOrEmpty(searchServiceApiKey) || String.IsNullOrEmpty(indexName))
            {
                return(new BadRequestObjectResult($"{skillName} - Information for the search service is missing"));
            }
            SearchClientHelper searchClient = new SearchClientHelper(searchServiceName, searchServiceApiKey, indexName);

            FacetGraphGenerator facetGraphGenerator = new FacetGraphGenerator(searchClient);
            string  query      = string.IsNullOrEmpty(req.Query["q"].FirstOrDefault()) ? "*" : req.Query["q"].First();
            string  facet      = string.IsNullOrEmpty(req.Query["f"].FirstOrDefault()) ? "entities" : req.Query["f"].First();
            JObject facetGraph = facetGraphGenerator.GetFacetGraphNodes(query, facet);

            return((ActionResult) new OkObjectResult(facetGraph));
        }
Exemple #2
0
 public FacetGraphGenerator(SearchClientHelper searchClient)
 {
     _searchHelper = searchClient;
 }