コード例 #1
0
 public ActionResult Search([FromQuery] Models.Requests.SearchRequest request)
 {
     if (String.IsNullOrEmpty(request.SearchQuery))
     {
         return(BadRequest(new { error = "search query must be non-empty string" }));
     }
     _searchUseCase.Handle(new SearchRequest(Regex.Replace(request.SearchQuery, @"\s+", " ").ToLower()), _searchPresenter);
     return(_searchPresenter.ContentResult);
 }
コード例 #2
0
        public async Task <SearchResponse> Get(Models.Requests.SearchRequest searchRequest)
        {
            var organizationKey = searchRequest.Filters?.FirstOrDefault(f => f.Name == "organizationKey")?.Value;
            var folderKey       = searchRequest.Filters?.FirstOrDefault(f => f.Name == "folderKey")?.Value;
            var pathKey         = searchRequest.Filters?.FirstOrDefault(f => f.Name == "pathKey")?.Value;
            var organization    = await Connection.Organization.GetAsync(
                new OrganizationIdentifier(organizationKey ?? Connection.UserIdentifier.OrganizationKey)
                );

            if (string.IsNullOrWhiteSpace(searchRequest.Keyword))
            {
                searchRequest.Keyword = "*";
            }

            searchRequest.Filters = searchRequest.Filters
                                    .Where(f => f.Name != "organizationKey")
                                    .Where(f => f.Name != "folderKey")
                                    .Where(f => f.Name != "pathKey")
                                    .ToList();

            if (pathKey != null)
            {
                var filters = searchRequest.Filters ?? new List <Models.Requests.SearchRequest.Filter>();

                filters.Add(new Models.Requests.SearchRequest.Filter
                {
                    Name  = "_path",
                    Value = pathKey
                });

                searchRequest.Filters = filters;
            }

            searchRequest.FolderIdentifier = new FolderIdentifier
            {
                OrganizationKey = organizationKey,
                FolderKey       = folderKey
            };

            return(await Search.SearchAsync(organization, searchRequest));
        }