예제 #1
0
        /// <summary>按多个完全匹配条件搜索</summary>
        public virtual async Task <MatchResult[]> MatchManyAsync(MatchRequest[] requests)
        {
            var _provider = new SearchProvider <Metadata>();
            MultiSearchDescriptor multiSearchDescriptor = new MultiSearchDescriptor();

            for (int i = 0; i < requests.Length; i++)
            {
                var request     = requests[i];
                var filterQuery = _provider.BuildFilterQuery(request.Filter);
                var sort        = _provider.BuildSort(request.Sort);

                var fields = _provider.BuildFields(request.Fields);

                var from = 0;
                var size = request.Top;

                var searchDescriptor = _esAccess.BuildSearchDescriptor(filterQuery, sort, fields, null, from, size);
                multiSearchDescriptor.Search <Metadata>("search" + i, s => searchDescriptor);
            }

            List <MatchResult> result = new List <MatchResult>();
            var searchResponse        = await _esAccess.MultiSearch(multiSearchDescriptor);

            foreach (var responseItem in searchResponse.AllResponses)
            {
                var metadata = responseItem as ISearchResponse <Metadata>;
                if (metadata != null)
                {
                    result.Add(metadata.ToMetadataCollection <MatchResult>());
                }
                ;
            }
            return(await Task.FromResult(result.ToArray()));
        }
예제 #2
0
        /// <summary>按完全匹配条件搜索</summary>
        public virtual async Task <MatchResult> MatchAsync(MatchRequest request)
        {
            var _provider   = new SearchProvider <Metadata>();
            var filterQuery = _provider.BuildFilterQuery(request.Filter);
            var sort        = _provider.BuildSort(request.Sort);
            var fields      = _provider.BuildFields(request.Fields);

            var from           = 0;
            var size           = request.Top;
            var searchresponse = await _esAccess.PagingQueryAsync(filterQuery, sort, fields, null, from, size);

            var response = searchresponse.ToMetadataCollection <MatchResult>();

            return(await Task.FromResult(response));
        }
예제 #3
0
        /// <summary>按短语搜索</summary>
        public virtual async Task <SearchResult> SearchAsync(SearchRequest request)
        {
            var _provider   = new SearchProvider <Metadata>();
            var filterQuery = _provider.BuildFilterQuery(request.Filter);
            // var fulltextQuery = _provider.BuildFullTextQuery(request.Sentence, request.Ranks);
            var fulltextQuery = _provider.BuildCustomScoreQuery(request.Sentence, request.Boost);
            var query         = _provider.CombineMustQuery(filterQuery, fulltextQuery);
            var sort          = _provider.BuildSort(request.Sort);
            var aggs          = _provider.BuildAggs(request.Group);
            var fields        = _provider.BuildFields(request.Fields);

            var from = request.From;
            var size = request.Size;

            var searchresponse = await _esAccess.PagingQueryAsync(query, sort, fields, aggs, from, size);

            var response = searchresponse.ToMetadataCollection();

            if (searchresponse.Aggregations.Count <= 0)
            {
                return(await Task.FromResult(response));
            }

            var groups = new Dictionary <string, Dictionary <string, long?> >();

            foreach (var agg in searchresponse.Aggregations)
            {
                var aggregates = agg.Value.As <BucketAggregate>().Items;
                Dictionary <string, long?> dic = new Dictionary <string, long?>();
                foreach (var aggregate in aggregates)
                {
                    var keyedBucket = aggregate as Nest.KeyedBucket <object>;
                    if (keyedBucket != null)
                    {
                        dic.Add(keyedBucket.Key.ToString(), keyedBucket.DocCount);
                    }
                }
                groups.Add(agg.Key, dic);
            }

            response.Groups = groups;
            return(await Task.FromResult(response));
        }
예제 #4
0
        /// <summary>根据iiid数组搜索</summary>
        public virtual async Task <MetadataCollection> GetMetadatasAsync(SearchMetadatasRequest request)
        {
            var provider  = new SearchProvider <Metadata>();
            var termQuery = new TermsQuery {
                Field = "iiid.keyword", Terms = request.IIIds
            };
            var query = new BoolQuery()
            {
                Must = new List <QueryContainer> {
                    termQuery
                }
            };

            var fields = provider.BuildFields(request.Fields);

            var from = 0;
            var size = request.IIIds.Count;

            var searchresponse = await _esAccess.PagingQueryAsync(query, null, fields, null, from, size);

            var response = new MetadataCollection(searchresponse.Documents);

            return(await Task.FromResult(response));
        }
예제 #5
0
        /// <summary>根据iiid搜索</summary>
        public virtual async Task <Metadata> GetMetadataAsync(SearchMetadataRequest request)
        {
            var provider  = new SearchProvider <Metadata>();
            var termQuery = new TermQuery {
                Field = "iiid.keyword", Value = request.IIId
            };
            var query = new BoolQuery()
            {
                Must = new List <QueryContainer> {
                    termQuery
                }
            };

            var fields = provider.BuildFields(request.Fields);

            var from = 0;
            var size = 1;

            var searchresponse = await _esAccess.PagingQueryAsync(query, null, fields, null, from, size);

            var response = searchresponse.Documents.FirstOrDefault();

            return(await Task.FromResult(response));
        }