Example #1
0
        public virtual SearchResult <SearchableBase> Search(SearchTextQuery query)
        {
            var searchRequest = GetSearchDescriptor()
                                .Query(q =>
                                       q.Bool(b => b
                                              .Should(GetQueryContainers(query.Text))
                                              .MinimumShouldMatch(MinimumShouldMatch.Fixed(MinimumShouldMatches))))
                                .PostFilter(pf => pf.Bool(b => b.Must(GetSearchPostFilters(query))));

            ApplyAggregations(searchRequest, query);

            _searchSorting.Apply(searchRequest, query);

            _searchPagingHelper.Apply(searchRequest, query);

            if (query.ApplyHighlights)
            {
                ApplyHighlight(searchRequest);
            }

            var queryResult  = _elasticSearchRepository.SearchByIndex(searchRequest);
            var searchResult = ParseResults(queryResult);

            return(searchResult);
        }
Example #2
0
        public virtual SearchResult <T> Search(MemberSearchQuery query)
        {
            var shouldDescriptor = new QueryContainerDescriptor <SearchableMember>()
                                   .Bool(b => b.Should(_memberSearchDescriptorBuilder.GetMemberDescriptors(query.Text)));

            QueryContainer allDescriptors = null;

            if (!query.GroupId.HasValue)
            {
                allDescriptors = new QueryContainerDescriptor <T>()
                                 .Bool(b => b
                                       .Must(shouldDescriptor));
            }
            else
            {
                if (query.MembersOfGroup)
                {
                    allDescriptors = new QueryContainerDescriptor <T>()
                                     .Bool(b => b
                                           .Must(shouldDescriptor, _memberSearchDescriptorBuilder.GetMemberInGroupDescriptor(query.GroupId)));
                }
            }

            var searchRequest = GetSearchDescriptor()
                                .Query(q =>
                                       q.Bool(b => b
                                              .Should(allDescriptors)
                                              .MinimumShouldMatch(MinimumShouldMatch.Fixed(MinimumShouldMatches))));

            if (query.GroupId.HasValue && !query.MembersOfGroup)
            {
                searchRequest = GetSearchDescriptor()
                                .Query(q =>
                                       q.Bool(b => b
                                              .Should(_memberSearchDescriptorBuilder.GetMemberDescriptors(query.Text))
                                              .MinimumShouldMatch(MinimumShouldMatch.Fixed(MinimumShouldMatches))))
                                .PostFilter(pf => pf
                                            .Bool(b => b
                                                  .MustNot(_memberSearchDescriptorBuilder.GetMemberInGroupDescriptor(query.GroupId))));
            }

            SortByMemberGroupRights(searchRequest, query);

            _searchPagingHelper.Apply(searchRequest, query);

            var queryResult  = _elasticSearchRepository.SearchByIndex(searchRequest);
            var searchResult = ParseResults(queryResult);

            return(searchResult);
        }