public SelectResponseParser(
     ISolrDocumentResponseParser <TOld> inner,
     ISolrDocumentResponseParser <Dictionary <string, object> > dictionaryParser,
     MethodCallExpression selectCall,
     SelectExpressionsCollection selectState) : base(inner, dictionaryParser)
 {
     _selectCall  = selectCall ?? throw new ArgumentNullException(nameof(selectCall));
     _selectState = selectState ?? throw new ArgumentNullException(nameof(selectState));
 }
Exemple #2
0
 public SelectFieldsVisitor(MemberContext context, SelectExpressionsCollection selectContext)
 {
     _context       = context ?? throw new ArgumentNullException(nameof(context));
     _selectContext = selectContext ?? throw new ArgumentNullException(nameof(selectContext));
 }
        public static IExecuter <TNew> ChangeType <TNew, TOld>(
            this IExecuter <TOld> executer,
            MethodCallExpression expression,
            SelectExpressionsCollection selectExpressionsCollection)
        {
            if (executer == null)
            {
                throw new ArgumentNullException(nameof(executer));
            }
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }
            if (selectExpressionsCollection == null)
            {
                throw new ArgumentNullException(nameof(selectExpressionsCollection));
            }

            try
            {
                SolrQueryExecuter <TOld> oldExecuter = executer.Executer;

                ISolrConnection           connection           = oldExecuter.GetFieldRecursive <ISolrConnection>();
                ISolrQuerySerializer      serializer           = oldExecuter.GetFieldRecursive <ISolrQuerySerializer>();
                ISolrFacetQuerySerializer facetQuerySerializer = oldExecuter.GetFieldRecursive <ISolrFacetQuerySerializer>();

                ISolrDocumentResponseParser <TOld> oldParser =
                    oldExecuter.GetFieldRecursive <ISolrDocumentResponseParser <TOld> >();

                ISolrFieldParser fieldParser = oldParser.GetFieldRecursive <ISolrFieldParser>();
                SolrDictionaryDocumentResponseParser dictionaryParser = new SolrDictionaryDocumentResponseParser(fieldParser);

                ISolrDocumentResponseParser <TNew> docParser;

                if (expression.Method.DeclaringType == typeof(Queryable) && expression.Method.Name == nameof(Queryable.Cast))
                {
                    docParser = new CastResponseParser <TNew, TOld>(oldParser, dictionaryParser);
                }
                else if (expression.Method.DeclaringType == typeof(Queryable) && expression.Method.Name == nameof(Queryable.Select))
                {
                    docParser = new SelectResponseParser <TNew, TOld>(oldParser,
                                                                      dictionaryParser, expression,
                                                                      selectExpressionsCollection);
                }
                else
                {
                    throw new InvalidOperationException(
                              $"Unable to change query type from {typeof(TOld).Name} to {typeof(TNew).Name}. Method {expression.Method.Name} not supported");
                }

                ISolrAbstractResponseParser <TNew> parser = new DefaultResponseParser <TNew>(docParser);

                SolrQueryExecuter <TNew> newExecuter = new SolrQueryExecuter <TNew>(parser, connection, serializer,
                                                                                    facetQuerySerializer,
                                                                                    new SolrMoreLikeThisHandlerQueryResultsParser <TNew>(Enumerable.Repeat(parser, 1)));

                newExecuter.DefaultHandler      = oldExecuter.DefaultHandler;
                newExecuter.DefaultRows         = oldExecuter.DefaultRows;
                newExecuter.MoreLikeThisHandler = oldExecuter.MoreLikeThisHandler;

                return(new SelectQueryExecutor <TNew>(newExecuter));
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(
                          $"Unable to change solr query executer from {typeof(TOld)} to {typeof(TNew)}.", e);
            }
        }
 public ReplaceCalculatedVisitor(SelectExpressionsCollection collection, Dictionary <string, object> dictionary)
 {
     _collection = collection ?? throw new ArgumentNullException(nameof(collection));
     _dictionary = dictionary ?? throw new ArgumentNullException(nameof(dictionary));
 }