Exemplo n.º 1
0
        public List <Entry> Post([FromBody] SearchPayload payload)
        {
            SearchEntriesContext context = HttpContext.RequestServices.GetService(typeof(SearchEntriesContext)) as SearchEntriesContext;
            var result = context.Search(payload);

            return(result);
        }
 /// <summary>
 /// Extension method used for validate search payload
 /// </summary>
 /// <param name="payload"> The search payload to validate </param>
 public static void Validate(this SearchPayload payload)
 {
     foreach (var term in payload.SearchTerm)
     {
         Validator.ValidateObject(term, new ValidationContext(term), true);
     }
 }
Exemplo n.º 3
0
        public DocumentSearchResult Search(string indexName, SearchPayload payload)
        {
            var indexClient = GetClient(indexName);
            var sp          = new SearchParameters();

            sp.Top  = payload.PageSize;
            sp.Skip = (payload.Page - 1) * payload.PageSize;
            if (payload.Filters != null)
            {
                sp.Filter = string.Join(" and ", payload.Filters.Select(x => $"{x.Key} eq '{x.Value}'").ToArray());
            }
            sp.OrderBy    = payload.OrderBy.Split(',');
            sp.QueryType  = "full".Equals(payload.QueryType)?QueryType.Full:QueryType.Simple;
            sp.SearchMode = payload.SearchMode;

            if (!string.IsNullOrEmpty(payload.ScoringProfile))
            {
                sp.ScoringProfile = payload.ScoringProfile;
            }
            sp.IncludeTotalResultCount = true;
            if (payload.IncludeFacets)
            {
                var appliedFilters = (payload.Filters ?? new Dictionary <string, string>()).Select(x => x.Key);
                //Asking for facets for applied filters is not really needed
                //The amount is actually the result count
                sp.Facets = payload.Facets.Except(appliedFilters).ToList();
            }
            return(indexClient.Documents.Search(payload.Text, sp));
        }
Exemplo n.º 4
0
        public IActionResult Search([FromBody] SearchPayload payload)
        {
            var threads = _threadService.FindBy(payload.SearchString, payload.TopicId, payload.Tags);

            var dto = _mapper.Map <List <ThreadDto> >(threads.ToList());

            return(Ok(dto));
        }
Exemplo n.º 5
0
        private static void TestPayload(SearchPayload payload)
        {
            var essentials = EssentialsResource.GetOrganization(payload);
            var result     = JsonDocument.Parse(essentials);

            result.RootElement.TryGetProperty("code", out var response);
            Assert.True(response.TryGetInt32(out int code));
            Assert.True(code == 200);

            Assert.NotNull(essentials);
        }
        public void ValidatorShouldFailForInvalidField()
        {
            var r = new SearchPayload()
            {
                SearchTerm = new[]
                {
                    new SearchTerm()
                    {
                        Field    = "Field",
                        Operator = (SearchOperator)100,
                        Value    = "value"
                    }
                }
            };

            Assert.Throws(typeof(ValidationException), () => r.Validate());
        }
        public void ValidatorShouldSuccessForValidField()
        {
            var r = new SearchPayload()
            {
                SearchTerm = new[]
                {
                    new SearchTerm()
                    {
                        Field    = "Field",
                        Operator = SearchOperator.EQ,
                        Value    = "value"
                    }
                }
            };

            r.Validate();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Search users
        /// </summary>
        /// <param name="payload">The request body to send</param>
        /// <returns>SearchResult Object</returns>
        public async Task <SearchResult?> SearchUsersAsync(SearchPayload payload)
        {
            var req = new HttpRequestMessage(HttpMethod.Post, new Uri($"{BaseAddress}/match/search"))
            {
                Content = new StringContent(JsonConvert.SerializeObject(payload))
            };
            var res = await this.Http.SendAsync(req).ConfigureAwait(false);

            var cont = await res.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (res.IsSuccessStatusCode)
            {
                return(JsonConvert.DeserializeObject <SearchResult>(cont));
            }
            else
            {
                return(null);
            }
        }
 public static string GetOrganization(SearchPayload form)
 {
     return(Get(BuildPostEssentialsRequest(form)));
 }
 private static Request BuildPostEssentialsRequest(SearchPayload payload)
 {
     return(BuildPostRequest(Domain.EssentialsV2, payload.ToJson()));
 }
 public static async Task <string> GetOrganizationAsync(SearchPayload form)
 {
     return(await GetAsync(BuildPostEssentialsRequest(form))
            .ConfigureAwait(false));
 }
 public async Task <string> Index(SearchPayload request)
 {
     return(await EssentialsResource.GetOrganizationAsync(request));
 }
Exemplo n.º 13
0
        public List <Entry> Get(SearchPayload payload)
        {
            EntryStoreContext context = HttpContext.RequestServices.GetService(typeof(EntryStoreContext)) as EntryStoreContext;

            return(context.GetBehavior(payload.Phrase));
        }
Exemplo n.º 14
0
 public IActionResult Search([FromBody] SearchPayload payload)
 {
     return(Json(_searchService.Search("users", payload)));
 }