Exemplo n.º 1
0
        /// <summary>
        /// Create new instance of <see cref="ElasticsearchQueryBuilder"/>
        /// </summary>
        /// <returns>ISearchQueryBuilder of <see cref="ElasticsearchSearchEngine"/></returns>
        public static ISearchQueryBuilder <ElasticsearchQueryContainer <TEntity> > Create()
        {
            var instance = new ElasticsearchQueryBuilder <TEntity>();

            instance.SetDelegateExecutor();
            return(instance);
        }
Exemplo n.º 2
0
        public SearchResult <TEntity> FullTextSearch(SearchQueryItem queryItem)
        {
            int from = ((queryItem.Pagination.Page - 1) * queryItem.Pagination.PageSize);

            ElasticsearchQueryContainer <TEntity> query = ElasticsearchQueryBuilder <TEntity> .Create().Build(queryItem);

            SortDescriptor <TEntity> sort = new SortDescriptor <TEntity>();

            ISearchResponse <TEntity> response = this.client.Search <TEntity>(i => i.Index(this.aliasName ?? this.currentIndex)
                                                                              .Type(this.currentType)
                                                                              .Source(d => queryItem.Select != null? d.Includes(cc => cc.Fields(queryItem.Select)) : d)
                                                                              .Size(queryItem.Pagination.PageSize)
                                                                              .Query(q => query.Query)
                                                                              .Sort(s => sort)
                                                                              .Aggregations(agg => query.Aggregation)
                                                                              .Highlight(h => h.Fields(ff => ff.Field("*")
                                                                                                       .Type(HighlighterType.Plain))
                                                                                         .PreTags("<span class='highlight'>")
                                                                                         .PostTags("</span>")
                                                                                         .RequireFieldMatch(false)));

            SearchResult <TEntity> result = this.GetElasticSearchResult(response);

            return(result);
        }