protected static string MakeLoadQueryString(ILoadCommand command)
        {
            IDictionary <string, string> qsParts = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(command.Query))
            {
                qsParts.Add("q", command.Query);
            }

            qsParts.Add("wt", Enum.GetName(typeof(FormatType), command.ResponseFormat).ToLowerInvariant());
            return(QueryStringFromDicionary(qsParts));
        }
Exemple #2
0
        /// <summary>
        /// Queries the core and returns a list of matching objects
        /// </summary>
        /// <param name="query">Solr query (q=)</param>
        /// <param name="startIndex">Result start index</param>
        /// <param name="maxRows">Maximum rows to be returned</param>
        /// <param name="getAll">If <c>true</c> returns all the rows from the results. maxRows will be ignored when this is set to true.</param>
        /// <returns>List of matching objects.</returns>
        public virtual IEnumerable <TData> Query(string query, long startIndex = 0, long maxRows = 1000, bool getAll = false)
        {
            ILoadCommand cmd = _client.DefaultCore.CreateLoadCommand();

            cmd.Query          = query;
            cmd.ResponseFormat = FormatType.JSON;
            cmd.StartIndex     = startIndex;
            cmd.MaxRows        = maxRows;
            cmd.GetAll         = getAll;

            return(_client.DefaultCore.Operations.Load <TData>(cmd, _serializer, null));
        }
        protected static string MakeRowCountQueryString(ILoadCommand command)
        {
            IDictionary <string, string> qsParts = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(command.Query))
            {
                qsParts.Add("q", command.Query);
            }
            qsParts.Add("rows", "0");
            qsParts.Add("wt", "XML");

            return(QueryStringFromDicionary(qsParts));
        }
        protected long GetRowCountForResults(ILoadCommand command)
        {
            string    qs          = MakeRowCountQueryString(command);
            Uri       rowCountUri = MakeUri(SelectUri, qs);
            string    results     = _httpHelper.Get(rowCountUri);
            XDocument resultsDoc  = XDocument.Parse(results);
            var       rootNode    = (from r in resultsDoc.Descendants() where r.Attribute("name").Name == "response" select r).First();
            long      rows        = 0;
            var       val         = rootNode.Attribute("numFound").Value;

            long.TryParse(val, out rows);

            return(rows);
        }
Exemple #5
0
        public override IEnumerable <TOutput> Load <TOutput>(ILoadCommand command, IDataSerializer <TOutput> serializer, IResponseFormatter <string> formatter)
        {
            if (command.GetAll)
            {
                command.MaxRows = GetRowCountForResults(command);
            }

            if (command.MaxRows > 100000)
            {
                System.Diagnostics.Debug.WriteLine("Too many rows. Try using concurrent library.");
            }

            string loadQS = MakeLoadQueryString(command);

            return(ExecuteLoad(loadQS, command.ResponseFormat, serializer, formatter));
        }
        public override IEnumerable <TOutput> Load <TOutput>(ILoadCommand command, IDataSerializer <TOutput> serializer, IResponseFormatter <string> formatter)
        {
            long maxRows = GetRowCountForResults(command);

            if (maxRows > _readSplitSize)
            {
                List <TOutput> results  = new List <TOutput>();
                List <string>  commands = new List <string>();

                for (long startIndex = command.StartIndex, batchNum = 0; startIndex < maxRows; startIndex += (batchNum * _readSplitSize), batchNum++)
                {
                    ILoadCommand copyCommand = command.Clone() as ILoadCommand;
                    copyCommand.GetAll     = false;
                    copyCommand.StartIndex = startIndex;
                    copyCommand.MaxRows    = _readSplitSize;

                    string batchCommand = MakeLoadQueryString(copyCommand);

                    commands.Add(batchCommand);
                }
                commands.AsParallel().ForAll(s =>
                {
                    var batchResults = ExecuteLoad(s, command.ResponseFormat, serializer, formatter);
                    lock (results)
                    {
                        results.AddRange(batchResults);
                    }
                });

                return(results);
            }
            else
            {
                //Downgrade to simple operations
                return(base.Load(command, serializer, formatter));
            }
        }
Exemple #7
0
 public BulkLoadCommand(ILoadCommand command, SqlConnection connection)
 {
     connectionString = connection.ConnectionString;
     tableName        = command.TableName;
     fileName         = command.FileName;
 }
 public abstract IEnumerable <TOutput> Load <TOutput>(ILoadCommand command, IDataSerializer <TOutput> serializer,
                                                      IResponseFormatter <string> formatter, out long start, out long numFound);
Exemple #9
0
 public BulkLoadCommand(ILoadCommand command)
 {
     connectionString = command.ConnectionString;
     tableName = command.TableName;
     fileName = command.FileName;
 }