コード例 #1
0
        private SearchResults <TDocument> ExecuteGetResults <TDocument>(AzureQuery query, AzureSearchResults <TDocument> processedResults, DocumentSearchResult results)
        {
            var searchHits = processedResults.GetSearchHits();

            Sitecore.ContentSearch.Linq.FacetResults facets = null;
            if (query.FacetQueries != null && query.FacetQueries.Count > 0)
            {
                facets = ExecuteGetFacets(query);
            }
            return(new SearchResults <TDocument>(searchHits, (int)results.Count, facets));
        }
コード例 #2
0
        private TResult ApplyScalarMethods <TResult, TDocument>(AzureQuery query, AzureSearchResults <TDocument> processedResults, DocumentSearchResult results)
        {
            var    queryMethod = query.Methods.FirstOrDefault();
            object obj;

            switch (queryMethod.MethodType)
            {
            case QueryMethodType.All:
                obj = true;
                //Check for CustomMethod
                var customMethod = queryMethod as CustomMethod;
                if (customMethod != null)
                {
                    switch (customMethod.CustomMethodType)
                    {
                    case Linq.Nodes.CustomQueryMethodTypes.GetHightlights:
                        obj = ExecuteGetHighlightResults(query);
                        break;
                    }
                }
                break;

            case QueryMethodType.Any:
                obj = (processedResults.Any() ? 1 : 0);
                break;

            case QueryMethodType.Count:
                obj = query.Methods.Any(m =>
                {
                    if (m.MethodType != QueryMethodType.Skip)
                    {
                        return(m.MethodType == QueryMethodType.Take);
                    }
                    return(true);
                }) ? processedResults.Count() : results.Count;
                break;

            case QueryMethodType.ElementAt:
                obj = !((ElementAtMethod)queryMethod).AllowDefaultValue ? processedResults.ElementAt(((ElementAtMethod)queryMethod).Index) : processedResults.ElementAtOrDefault(((ElementAtMethod)queryMethod).Index);
                break;

            case QueryMethodType.First:
                obj = !((FirstMethod)queryMethod).AllowDefaultValue ? processedResults.First() : processedResults.FirstOrDefault();
                break;

            case QueryMethodType.Last:
                obj = !((LastMethod)queryMethod).AllowDefaultValue ? processedResults.Last() : processedResults.LastOrDefault();
                break;

            case QueryMethodType.Single:
                obj = !((SingleMethod)queryMethod).AllowDefaultValue ? processedResults.Single() : processedResults.SingleOrDefault();
                break;

            case QueryMethodType.GetResults:
                obj = ExecuteGetResults <TDocument>(query, processedResults, results);
                break;

            case QueryMethodType.GetFacets:
                obj = ExecuteGetFacets(query);
                break;

            default:
                throw new InvalidOperationException("Invalid query method: " + queryMethod.MethodType);
            }
            return((TResult)Convert.ChangeType(obj, typeof(TResult)));
        }