示例#1
0
        public QueryResult <Product> Search(Query query)
        {
            var options = new QueryOptions();

            AbstractSolrQuery q = new SolrQuery(!string.IsNullOrEmpty(query.SearchText) ? query.SearchText : "*");

            options.ExtraParams = new[] { new KeyValuePair <string, string>("df", "description") };

            options.Rows          = query.NumToReturn ?? DefaultSettings.DefaultNumToReturn;
            options.StartOrCursor = OffsetConverter.GetOffsetFromCurrentPage(query.Page);

            options.OrderBy = SortOrderConverter.GetSortOrder(query);

            string facetToExclude;

            options.FilterQueries = FilterConverter.GetSolrNetFilters(query, out facetToExclude);

            options.Facet = FacetConverter.GetSolrNetFacetParameters(query, facetToExclude);

            options.Highlight = HighlightConverter.GetSolrNetHighlightingParameters(query.SearchText);

            var results = SolrOperations.Query(q, options);

            var convertedResults = ResultConverter.GetQueryResult(results);

            if (convertedResults == null)
            {
                convertedResults.ErrorMessages = new[] { "An error occured communicating with the solr instance" };
            }

            return(convertedResults);
        }