Example #1
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);
        }
        protected override QueryContainer[] GetQueryContainers(string query)
        {
            var containers = base.GetQueryContainers(query).ToList();

            containers.Add(GetTagNames <SearchableUintraActivity>(query));
            containers.Add(GetTagNames <SearchableMember>(query));
            containers.Add(GetTagsDescriptor(query));
            containers.AddRange(_memberSearchDescriptorBuilder.GetMemberDescriptors(query));
            return(containers.ToArray());
        }
 protected virtual QueryContainer GetDefaultMemberQueryContainer(MemberSearchQuery query)
 {
     return(new QueryContainerDescriptor <T>()
            .Bool(b => b.Should(_memberSearchDescriptorBuilder.GetMemberDescriptors(query.Text))));
 }