Beispiel #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);
        }
Beispiel #2
0
 protected virtual QueryContainer[] GetSearchPostFilters(SearchTextQuery query)
 {
     return(new[]
     {
         GetSearchableTypeQueryContainers(query.SearchableTypeIds),
         GetOnlyPinnedQueryContainer(query.OnlyPinned)
     });
 }
 protected virtual void ApplyAggregations <T>(SearchDescriptor <T> searchDescriptor, SearchTextQuery query) where T : class
 {
     searchDescriptor.Aggregations(agg => agg
                                   .Global(SearchConstants.SearchFacetNames.Types, g => g
                                           .Aggregations(a => a
                                                         .Filter(SearchConstants.SearchFacetNames.GlobalFilter, ss => ss
                                                                 .Filter(fi => fi
                                                                         .Bool(b => b
                                                                               .Should(GetQueryContainers(query.Text))
                                                                               .Must(GetSearchableTypeQueryContainers(query.SearchableTypeIds))
                                                                               .Must(GetOnlyPinnedQueryContainer(query.OnlyPinned))
                                                                               ))
                                                                 .Aggregations(
                                                                     ia =>
                                                                     ia.Terms(SearchConstants.SearchFacetNames.Types,
                                                                              f => f.Field("type").Size(ElasticHelpers.MaxAggregationSize)))))));
 }
 protected virtual void ApplyPaging <T>(SearchDescriptor <T> searchDescriptor, SearchTextQuery query) where T : class
 {
     searchDescriptor.Take(query.Take);
 }