コード例 #1
0
        /// <summary>
        /// A query that matches all documents. Maps to Lucene MatchAllDocsQuery.
        /// </summary>
        /// <param name="NormField">
        /// When indexing, a boost value can either be associated on the document level, or per field.
        /// The match all query does not take boosting into account by default. In order to take
        /// boosting into account, the norms_field needs to be provided in order to explicitly specify which
        /// field the boosting will be done on (Note, this will result in slower execution time).
        /// </param>
        public QueryContainer MatchAll(double?Boost = null, string NormField = null)
        {
            var query = new MatchAllQuery()
            {
                NormField = NormField
            };

            if (Boost.HasValue)
            {
                query.Boost = Boost.Value;
            }

            return(this.New(query, q => q.MatchAllQuery = query));
        }
コード例 #2
0
        public Task<ISearchResponse<Book>> SearchBookWithAggregation_Aync(string criteria = "", string searchField = "", List<string> refinements = null, int count = 10)
        {
            Task<ISearchResponse<Book>> tSearch = Task.Factory.StartNew(() =>
            {

                QueryContainer _query;

                if (String.IsNullOrEmpty(criteria))
                {
                    _query = new MatchAllQuery();
                }
                else
                {
                    if (String.IsNullOrEmpty(searchField))
                    {
                        searchField = "_all";

                        _query = new MatchQuery()
                        {
                            Field = searchField,
                            Query = criteria
                        };
                    }
                    else
                    {
                        _query = new TermQuery()
                        {
                            Field = searchField,
                            Value = criteria
                        };
                    }

                }

                SearchRequest searchRequest = new SearchRequest
                {
                    From = 0,
                    Size = count,
                    Query = _query
                };

                if (refinements != null && refinements.Count > 0)
                {
                    var _aggregations = new Dictionary<string, IAggregationContainer>();

                    foreach (var field in refinements)
                    {
                        _aggregations.Add(field, new AggregationContainer
                        {
                            Terms = new TermsAggregator
                            {
                                Field = field
                            }
                        });
                    }

                    searchRequest.Aggregations = _aggregations;

                }

                var qResult = esClient.Search<Book>(searchRequest);

                return qResult;
            });

            return tSearch;
        }
コード例 #3
0
        public ISearchResponse<Book> SearchBookWithAggregationFilters(string criteria = "", string searchField = "", 
            List<string> refinements = null,
            Dictionary<string,string> SearchFilters = null,
            int count = 10)
        {
            QueryContainer _query;

            if (String.IsNullOrEmpty(criteria))
            {
                _query = new MatchAllQuery();
            }
            else
            {
                if (String.IsNullOrEmpty(searchField))
                {
                    searchField = "_all";

                    _query = new MatchQuery()
                    {
                        Field = searchField,
                        Query = criteria
                    };
                }
                else
                {
                    _query = new TermQuery()
                    {
                        Field = searchField,
                        Value = criteria
                    };
                }

            }

            SearchRequest searchRequest = new SearchRequest
            {

                From = 0,
                Size = count,
                Query = _query
            };

            if (refinements != null && refinements.Count > 0)
            {
                var _aggregations = new Dictionary<string, IAggregationContainer>();

                foreach (var field in refinements)
                {
                    _aggregations.Add(field, new AggregationContainer
                    {
                        Terms = new TermsAggregator
                        {
                            Field = field
                        }
                    });
                }

                searchRequest.Aggregations = _aggregations;

            }

            if (SearchFilters != null && SearchFilters.Count > 0)
            {
                var searchFilterConfig = new FilterContainer();

                foreach(var sf in SearchFilters)
                {
                    searchFilterConfig = Filter<Book>.Term( sf.Key, sf.Value );
                }

                searchRequest.Filter = searchFilterConfig;
            }

            return esClient.Search<Book>(searchRequest);
        }