/// <summary> Performs a basic metadata search over the entire citation, given a search condition, and returns one page of results </summary>
        /// <param name="Search_Condition"> Search condition string to be run against the databasse </param>
        /// <param name="Include_Private_Items"> Flag indicates whether to include private items in the result set </param>
        /// <param name="AggregationCode"> Code for the aggregation of interest ( or empty string to search all aggregations )</param>
        /// <param name="DateRange_Start"> If this search includes a date range search, start of the date range, or -1</param>
        /// <param name="DateRange_End"> If this search includes a date range search, end of the date range, or -1</param>
        /// <param name="ResultsPerPage"> Number of results to return per "page" of results </param>
        /// <param name="ResultsPage"> Which page of results to return ( one-based, so the first page is page number of one )</param>
        /// <param name="Sort"> Current sort to use ( 0 = default by search or browse, 1 = title, 10 = date asc, 11 = date desc )</param>
        /// <param name="Include_Facets"> Flag indicates whether to include facets in the result set </param>
        /// <param name="Facet_Types"> Primary key for the metadata types to include as facets (up to eight)</param>
        /// <param name="Return_Search_Statistics"> Flag indicates whether to create and return statistics about the overall search results, generally set to TRUE for the first page requested and subsequently set to FALSE </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param>
        /// <returns> Small arguments object which contains the page of results and optionally statistics about results for the entire search, including complete counts and facet information </returns>
        /// <remarks> This calls the 'SobekCM_Metadata_Basic_Search_Paged' stored procedure </remarks>
        public static Multiple_Paged_Results_Args Perform_Metadata_Search_Paged( string Search_Condition, bool Include_Private_Items, string AggregationCode, long DateRange_Start, long DateRange_End, int ResultsPerPage, int ResultsPage, int Sort, bool Include_Facets, List<short> Facet_Types, bool Return_Search_Statistics, Custom_Tracer Tracer)
        {
            if (Tracer != null)
            {
                Tracer.Add_Trace("SobekCM_Database.Perform_Basic_Search_Paged", "Performing basic search in database");
            }

            Multiple_Paged_Results_Args returnArgs;

            // Create the connection
            using (SqlConnection connect = new SqlConnection(connectionString + "Connection Timeout=45"))
            {

                // Create the command
                SqlCommand executeCommand = new SqlCommand("SobekCM_Metadata_Basic_Search_Paged2", connect)
                                                {CommandTimeout = 45, CommandType = CommandType.StoredProcedure};

                executeCommand.Parameters.AddWithValue("@searchcondition", Search_Condition.Replace("''","'"));
                executeCommand.Parameters.AddWithValue("@include_private", Include_Private_Items);
                if (AggregationCode.ToUpper() == "ALL")
                    AggregationCode = String.Empty;
                executeCommand.Parameters.AddWithValue("@aggregationcode", AggregationCode);
                executeCommand.Parameters.AddWithValue("@daterange_start", DateRange_Start);
                executeCommand.Parameters.AddWithValue("@daterange_end", DateRange_End);
                executeCommand.Parameters.AddWithValue("@pagesize", ResultsPerPage);
                executeCommand.Parameters.AddWithValue("@pagenumber", ResultsPage);
                executeCommand.Parameters.AddWithValue("@sort", Sort);

                // If this is for more than 100 results, don't look ahead
                if (ResultsPerPage > 100)
                {
                    executeCommand.Parameters.AddWithValue("@minpagelookahead", 1);
                    executeCommand.Parameters.AddWithValue("@maxpagelookahead", 1);
                    executeCommand.Parameters.AddWithValue("@lookahead_factor", LOOKAHEAD_FACTOR);
                }
                else
                {
                    executeCommand.Parameters.AddWithValue("@minpagelookahead", MIN_PAGE_LOOKAHEAD);
                    executeCommand.Parameters.AddWithValue("@maxpagelookahead", MAX_PAGE_LOOKAHEAD);
                    executeCommand.Parameters.AddWithValue("@lookahead_factor", LOOKAHEAD_FACTOR);
                }

                if ((Include_Facets) && (Facet_Types != null) && ( Facet_Types.Count > 0 ) && (Return_Search_Statistics))
                {
                    executeCommand.Parameters.AddWithValue("@include_facets", true);
                    if (Facet_Types.Count > 0)
                        executeCommand.Parameters.AddWithValue("@facettype1", Facet_Types[0]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype1", -1);
                    if (Facet_Types.Count > 1)
                        executeCommand.Parameters.AddWithValue("@facettype2", Facet_Types[1]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype2", -1);
                    if (Facet_Types.Count > 2)
                        executeCommand.Parameters.AddWithValue("@facettype3", Facet_Types[2]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype3", -1);
                    if (Facet_Types.Count > 3)
                        executeCommand.Parameters.AddWithValue("@facettype4", Facet_Types[3]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype4", -1);
                    if (Facet_Types.Count > 4)
                        executeCommand.Parameters.AddWithValue("@facettype5", Facet_Types[4]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype5", -1);
                    if (Facet_Types.Count > 5)
                        executeCommand.Parameters.AddWithValue("@facettype6", Facet_Types[5]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype6", -1);
                    if (Facet_Types.Count > 6)
                        executeCommand.Parameters.AddWithValue("@facettype7", Facet_Types[6]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype7", -1);
                    if (Facet_Types.Count > 7)
                        executeCommand.Parameters.AddWithValue("@facettype8", Facet_Types[7]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype8", -1);
                }
                else
                {
                    executeCommand.Parameters.AddWithValue("@include_facets", false);
                    executeCommand.Parameters.AddWithValue("@facettype1", -1);
                    executeCommand.Parameters.AddWithValue("@facettype2", -1);
                    executeCommand.Parameters.AddWithValue("@facettype3", -1);
                    executeCommand.Parameters.AddWithValue("@facettype4", -1);
                    executeCommand.Parameters.AddWithValue("@facettype5", -1);
                    executeCommand.Parameters.AddWithValue("@facettype6", -1);
                    executeCommand.Parameters.AddWithValue("@facettype7", -1);
                    executeCommand.Parameters.AddWithValue("@facettype8", -1);
                }

                // Add parameters for total items and total titles
                SqlParameter totalItemsParameter = executeCommand.Parameters.AddWithValue("@total_items", 0);
                totalItemsParameter.Direction = ParameterDirection.InputOutput;

                SqlParameter totalTitlesParameter = executeCommand.Parameters.AddWithValue("@total_titles", 0);
                totalTitlesParameter.Direction = ParameterDirection.InputOutput;

                // Add parameters for items and titles if this search is expanded to include all aggregations
                SqlParameter expandedItemsParameter = executeCommand.Parameters.AddWithValue("@all_collections_items", 0);
                expandedItemsParameter.Direction = ParameterDirection.InputOutput;

                SqlParameter expandedTitlesParameter = executeCommand.Parameters.AddWithValue("@all_collections_titles", 0);
                expandedTitlesParameter.Direction = ParameterDirection.InputOutput;

                // Create the data reader
                connect.Open();
                using (SqlDataReader reader = executeCommand.ExecuteReader())
                {
                    // Create the return argument object
                    List<string> metadataLabels = new List<string>();
                    returnArgs = new Multiple_Paged_Results_Args
                                     {Paged_Results = DataReader_To_Result_List_With_LookAhead2(reader, ResultsPerPage, metadataLabels)};

                    // Create the overall search statistics?
                    if (Return_Search_Statistics)
                    {
                        Search_Results_Statistics stats = new Search_Results_Statistics(reader, Facet_Types, metadataLabels);
                        returnArgs.Statistics = stats;
                        reader.Close();
                        stats.Total_Items = Convert.ToInt32(totalItemsParameter.Value);
                        stats.Total_Titles = Convert.ToInt32(totalTitlesParameter.Value);
                        stats.All_Collections_Items = Convert.ToInt32(expandedItemsParameter.Value);
                        stats.All_Collections_Titles = Convert.ToInt32(expandedTitlesParameter.Value);
                    }
                    else
                    {
                        reader.Close();
                    }
                }
                connect.Close();
            }

            // Return the built result arguments
            return returnArgs;
        }
        /// <summary> Gets the collection of all (public) items linked to an item aggregation </summary>
        /// <param name="AggregationCode"> Code for the item aggregation of interest </param>
        /// <param name="Since_Date"> Date from which to pull the data </param>
        /// <param name="Include_Private_Items"> Flag indicates whether to include private items in the result set </param>
        /// <param name="ResultsPerPage"> Number of results to return per "page" of results </param>
        /// <param name="ResultsPage"> Which page of results to return ( one-based, so the first page is page number of one )</param>
        /// <param name="Sort"> Current sort to use ( 0 = default by search or browse, 1 = title, 10 = date asc, 11 = date desc )</param>
        /// <param name="Include_Facets"> Flag indicates if facets should be included in the final result set</param>
        /// <param name="Facet_Types"> Primary key for the metadata types to include as facets (up to eight)</param>
        /// <param name="Return_Search_Statistics"> Flag indicates whether to create and return statistics about the overall search results, generally set to TRUE for the first page requested and subsequently set to FALSE </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param>
        /// <returns> Table with all of the item and item group information </returns>
        /// <remarks> This calls the 'SobekCM_Get_Aggregation_Browse_Paged' stored procedure </remarks>
        public static Multiple_Paged_Results_Args Get_Item_Aggregation_Browse_Paged(string AggregationCode, string Since_Date, bool Include_Private_Items, int ResultsPerPage, int ResultsPage, int Sort, bool Include_Facets, List<short> Facet_Types, bool Return_Search_Statistics, Custom_Tracer Tracer)
        {
            if (Tracer != null)
            {
                Tracer.Add_Trace("SobekCM_Database.Get_Item_Aggregation_Browse_Paged", "Pulling browse from database");
            }

            Multiple_Paged_Results_Args returnArgs;

            // Create the connection
            using (SqlConnection connect = new SqlConnection(connectionString + "Connection Timeout=45"))
            {

                // Create the command
                SqlCommand executeCommand = new SqlCommand("SobekCM_Get_Aggregation_Browse_Paged2", connect)
                                                {CommandTimeout = 45, CommandType = CommandType.StoredProcedure};

                executeCommand.Parameters.AddWithValue("@code", AggregationCode);
                executeCommand.Parameters.AddWithValue("@date", Since_Date);
                executeCommand.Parameters.AddWithValue("@include_private", Include_Private_Items);
                executeCommand.Parameters.AddWithValue("@pagesize", ResultsPerPage);
                executeCommand.Parameters.AddWithValue("@pagenumber", ResultsPage);
                executeCommand.Parameters.AddWithValue("@sort", Sort);

                if (ResultsPerPage > 100)
                {
                    executeCommand.Parameters.AddWithValue("@minpagelookahead", 1);
                    executeCommand.Parameters.AddWithValue("@maxpagelookahead", 1);
                    executeCommand.Parameters.AddWithValue("@lookahead_factor", LOOKAHEAD_FACTOR);
                }
                else
                {
                    executeCommand.Parameters.AddWithValue("@minpagelookahead", MIN_PAGE_LOOKAHEAD);
                    executeCommand.Parameters.AddWithValue("@maxpagelookahead", MAX_PAGE_LOOKAHEAD);
                    executeCommand.Parameters.AddWithValue("@lookahead_factor", LOOKAHEAD_FACTOR);
                }

                if ((Include_Facets) && (Facet_Types != null))
                {
                    executeCommand.Parameters.AddWithValue("@include_facets", true);
                    if (Facet_Types.Count > 0)
                        executeCommand.Parameters.AddWithValue("@facettype1", Facet_Types[0]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype1", -1);
                    if (Facet_Types.Count > 1)
                        executeCommand.Parameters.AddWithValue("@facettype2", Facet_Types[1]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype2", -1);
                    if (Facet_Types.Count > 2)
                        executeCommand.Parameters.AddWithValue("@facettype3", Facet_Types[2]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype3", -1);
                    if (Facet_Types.Count > 3)
                        executeCommand.Parameters.AddWithValue("@facettype4", Facet_Types[3]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype4", -1);
                    if (Facet_Types.Count > 4)
                        executeCommand.Parameters.AddWithValue("@facettype5", Facet_Types[4]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype5", -1);
                    if (Facet_Types.Count > 5)
                        executeCommand.Parameters.AddWithValue("@facettype6", Facet_Types[5]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype6", -1);
                    if (Facet_Types.Count > 6)
                        executeCommand.Parameters.AddWithValue("@facettype7", Facet_Types[6]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype7", -1);
                    if (Facet_Types.Count > 7)
                        executeCommand.Parameters.AddWithValue("@facettype8", Facet_Types[7]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype8", -1);
                }
                else
                {
                    executeCommand.Parameters.AddWithValue("@include_facets", false);
                    executeCommand.Parameters.AddWithValue("@facettype1", -1);
                    executeCommand.Parameters.AddWithValue("@facettype2", -1);
                    executeCommand.Parameters.AddWithValue("@facettype3", -1);
                    executeCommand.Parameters.AddWithValue("@facettype4", -1);
                    executeCommand.Parameters.AddWithValue("@facettype5", -1);
                    executeCommand.Parameters.AddWithValue("@facettype6", -1);
                    executeCommand.Parameters.AddWithValue("@facettype7", -1);
                    executeCommand.Parameters.AddWithValue("@facettype8", -1);
                }
                executeCommand.Parameters.AddWithValue("@item_count_to_use_cached", 1000);

                // Add parameters for total items and total titles
                SqlParameter totalItemsParameter = executeCommand.Parameters.AddWithValue("@total_items", 0);
                totalItemsParameter.Direction = ParameterDirection.InputOutput;

                SqlParameter totalTitlesParameter = executeCommand.Parameters.AddWithValue("@total_titles", 0);
                totalTitlesParameter.Direction = ParameterDirection.InputOutput;

                // Create the data reader
                connect.Open();
                using (SqlDataReader reader = executeCommand.ExecuteReader())
                {

                    // Create the return argument object
                    List<string> metadataLabels = new List<string>();
                    returnArgs = new Multiple_Paged_Results_Args { Paged_Results = DataReader_To_Result_List_With_LookAhead2(reader, ResultsPerPage, metadataLabels) };

                    // Create the overall search statistics?
                    if (Return_Search_Statistics)
                    {
                        Search_Results_Statistics stats = new Search_Results_Statistics(reader, Facet_Types, metadataLabels);
                        returnArgs.Statistics = stats;
                        reader.Close();
                        stats.Total_Items = Convert.ToInt32(totalItemsParameter.Value);
                        stats.Total_Titles = Convert.ToInt32(totalTitlesParameter.Value);
                    }
                    else
                    {
                        reader.Close();
                    }
                }
                connect.Close();
            }

            // Return the built result arguments
            return returnArgs;
        }
        /// <summary> Returns the list of all items/titles which match a given OCLC number </summary>
        /// <param name="OCLC_Number"> OCLC number to look for matching items </param>
        /// <param name="Include_Private_Items"> Flag indicates whether to include private items in the result set </param>
        /// <param name="ResultsPerPage"> Number of results to return per "page" of results </param>
        /// <param name="Sort"> Current sort to use ( 0 = default by search or browse, 1 = title, 10 = date asc, 11 = date desc )</param>
        /// <param name="Return_Search_Statistics"> Flag indicates whether to create and return statistics about the overall search results, generally set to TRUE for the first page requested and subsequently set to FALSE </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param>
        /// <returns> Table with all of the item and item group information which matches the OCLC number </returns>
        /// <remarks> This calls the 'SobekCM_Items_By_OCLC' stored procedure </remarks>
        public static Multiple_Paged_Results_Args Items_By_OCLC_Number(long OCLC_Number, bool Include_Private_Items, int ResultsPerPage, int Sort, bool Return_Search_Statistics, Custom_Tracer Tracer)
        {
            if (Tracer != null)
            {
                Tracer.Add_Trace("SobekCM_Database.Items_By_OCLC_Number", "Searching by OCLC in the database");
            }

            // Build the parameter list
            SqlParameter[] paramList = new SqlParameter[5];
            paramList[0] = new SqlParameter("@oclc_number", OCLC_Number);
            paramList[1] = new SqlParameter("@include_private", Include_Private_Items);
            paramList[2] = new SqlParameter("@sort", Sort);
            paramList[3] = new SqlParameter("@total_items", 0) {Direction = ParameterDirection.InputOutput};
            paramList[4] = new SqlParameter("@total_titles", 0) {Direction = ParameterDirection.InputOutput};

            // Get the matching reader
            Multiple_Paged_Results_Args returnArgs;
            using (SqlDataReader reader = SqlHelper.ExecuteReader(connectionString, CommandType.StoredProcedure, "SobekCM_Items_By_OCLC", paramList))
            {
                List<string>  metadataFields = new List<string>();

                // Create the return argument object
                returnArgs = new Multiple_Paged_Results_Args { Paged_Results = DataReader_To_Result_List_With_LookAhead2(reader, ResultsPerPage, metadataFields) };

                // Create the overall search statistics?
                if (Return_Search_Statistics)
                {
                    Search_Results_Statistics stats = new Search_Results_Statistics(reader, null, metadataFields);
                    returnArgs.Statistics = stats;
                    reader.Close();
                    stats.Total_Items = Convert.ToInt32(paramList[3].Value);
                    stats.Total_Titles = Convert.ToInt32(paramList[4].Value);
                }
                else
                {
                    reader.Close();
                }
            }

            // Return the built results
            return returnArgs;
        }
        /// <summary> Perform a metadata search against items in the database and return one page of results </summary>
        /// <param name="Term1"> First search term for this metadata search </param>
        /// <param name="Field1"> Field number to search for (or -1 to search all fields)</param>
        /// <param name="Link2"> Link between the first and second terms ( 0=AND, 1=OR, 2=AND NOT )</param>
        /// <param name="Term2"> Second search term for this metadata search </param>
        /// <param name="Field2"> Field number to search for (or -1 to search all fields)</param>
        /// <param name="Link3">Link between the second and third search terms ( 0=AND, 1=OR, 2=AND NOT )</param>
        /// <param name="Term3"> Third search term for this metadata search </param>
        /// <param name="Field3"> Field number to search for (or -1 to search all fields)</param>
        /// <param name="Link4">Link between the third and fourth search terms ( 0=AND, 1=OR, 2=AND NOT )</param>
        /// <param name="Term4"> Fourth search term for this metadata search </param>
        /// <param name="Field4"> Field number to search for (or -1 to search all fields)</param>
        /// <param name="Link5">Link between the fourth and fifth search terms ( 0=AND, 1=OR, 2=AND NOT )</param>
        /// <param name="Term5"> Fifth search term for this metadata search </param>
        /// <param name="Field5"> Field number to search for (or -1 to search all fields)</param>
        /// <param name="Link6">Link between the fifth and sixth search terms ( 0=AND, 1=OR, 2=AND NOT )</param>
        /// <param name="Term6"> Sixth search term for this metadata search </param>
        /// <param name="Field6"> Field number to search for (or -1 to search all fields)</param>
        /// <param name="Link7">Link between the sixth and seventh search terms ( 0=AND, 1=OR, 2=AND NOT )</param>
        /// <param name="Term7"> Seventh search term for this metadata search </param>
        /// <param name="Field7"> Field number to search for (or -1 to search all fields)</param>
        /// <param name="Link8">Link between the seventh and eighth search terms ( 0=AND, 1=OR, 2=AND NOT )</param>
        /// <param name="Term8"> Eighth search term for this metadata search </param>
        /// <param name="Field8"> Field number to search for (or -1 to search all fields)</param>
        /// <param name="Link9">Link between the eighth and ninth search terms ( 0=AND, 1=OR, 2=AND NOT )</param>
        /// <param name="Term9"> Ninth search term for this metadata search </param>
        /// <param name="Field9"> FIeld number to search for (or -1 to search all fields)</param>
        /// <param name="Link10">Link between the ninth and tenth search terms ( 0=AND, 1=OR, 2=AND NOT )</param>
        /// <param name="Term10"> Tenth search term for this metadata search </param>
        /// <param name="Field10"> Field number to search for (or -1 to search all fields)</param>
        /// <param name="Include_Private_Items"> Flag indicates whether to include private items in the result set </param>
        /// <param name="ResultsPerPage"> Number of results to return per "page" of results </param>
        /// <param name="ResultsPage"> Which page of results to return ( one-based, so the first page is page number of one )</param>
        /// <param name="Sort"> Current sort to use ( 0 = default by search or browse, 1 = title, 10 = date asc, 11 = date desc )</param>
        /// <param name="AggregationCode"> Code for the aggregation of interest ( or empty string to search all aggregations )</param>
        /// <param name="Include_Facets"> Flag indicates whether to include facets </param>
        /// <param name="Facet_Types"> Primary key for the metadata types to include as facets (up to eight)</param>
        /// <param name="Return_Search_Statistics"> Flag indicates whether to create and return statistics about the overall search results, generally set to TRUE for the first page requested and subsequently set to FALSE </param>
        /// <param name="tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param>
        /// <returns> Small arguments object which contains the page of results and optionally statistics about results for the entire search, including complete counts and facet information </returns>
        /// <remarks> This calls the 'SobekCM_Metadata_Search_Paged' stored procedure </remarks>
        public static Multiple_Paged_Results_Args Perform_Metadata_Search_Paged(string Term1, int Field1,
																				int Link2, string Term2, int Field2, int Link3, string Term3, int Field3, int Link4, string Term4, int Field4,
																				int Link5, string Term5, int Field5, int Link6, string Term6, int Field6, int Link7, string Term7, int Field7,
																				int Link8, string Term8, int Field8, int Link9, string Term9, int Field9, int Link10, string Term10, int Field10,
																				bool Include_Private_Items, string AggregationCode, int ResultsPerPage, int ResultsPage, int Sort, bool Include_Facets, 
																				List<short> Facet_Types, bool Return_Search_Statistics, Custom_Tracer tracer)
        {
            if (tracer != null)
            {
                tracer.Add_Trace("SobekCM_Database.Perform_Metadata_Search_Paged", "Performing search in database");
            }

            Multiple_Paged_Results_Args returnArgs;

            // Create the connection
            using (SqlConnection connect = new SqlConnection(connectionString + "Connection Timeout=45"))
            {

                // Create the command
                SqlCommand executeCommand = new SqlCommand("SobekCM_Metadata_Search_Paged", connect)
                                                {CommandTimeout = 45, CommandType = CommandType.StoredProcedure};

                executeCommand.Parameters.AddWithValue("@term1", Term1);
                executeCommand.Parameters.AddWithValue("@field1", Field1);
                executeCommand.Parameters.AddWithValue("@link2", Link2);
                executeCommand.Parameters.AddWithValue("@term2", Term2);
                executeCommand.Parameters.AddWithValue("@field2", Field2);
                executeCommand.Parameters.AddWithValue("@link3", Link3);
                executeCommand.Parameters.AddWithValue("@term3", Term3);
                executeCommand.Parameters.AddWithValue("@field3", Field3);
                executeCommand.Parameters.AddWithValue("@link4", Link4);
                executeCommand.Parameters.AddWithValue("@term4", Term4);
                executeCommand.Parameters.AddWithValue("@field4", Field4);
                executeCommand.Parameters.AddWithValue("@link5", Link5);
                executeCommand.Parameters.AddWithValue("@term5", Term5);
                executeCommand.Parameters.AddWithValue("@field5", Field5);
                executeCommand.Parameters.AddWithValue("@link6", Link6);
                executeCommand.Parameters.AddWithValue("@term6", Term6);
                executeCommand.Parameters.AddWithValue("@field6", Field6);
                executeCommand.Parameters.AddWithValue("@link7", Link7);
                executeCommand.Parameters.AddWithValue("@term7", Term7);
                executeCommand.Parameters.AddWithValue("@field7", Field7);
                executeCommand.Parameters.AddWithValue("@link8", Link8);
                executeCommand.Parameters.AddWithValue("@term8", Term8);
                executeCommand.Parameters.AddWithValue("@field8", Field8);
                executeCommand.Parameters.AddWithValue("@link9", Link9);
                executeCommand.Parameters.AddWithValue("@term9", Term9);
                executeCommand.Parameters.AddWithValue("@field9", Field9);
                executeCommand.Parameters.AddWithValue("@link10", Link10);
                executeCommand.Parameters.AddWithValue("@term10", Term10);
                executeCommand.Parameters.AddWithValue("@field10", Field10);
                executeCommand.Parameters.AddWithValue("@include_private", Include_Private_Items);
                if (AggregationCode.ToUpper() == "ALL")
                    AggregationCode = String.Empty;
                executeCommand.Parameters.AddWithValue("@aggregationcode", AggregationCode);
                executeCommand.Parameters.AddWithValue("@pagesize", ResultsPerPage);
                executeCommand.Parameters.AddWithValue("@pagenumber", ResultsPage);
                executeCommand.Parameters.AddWithValue("@sort", Sort);

                // If this is for more than 100 results, don't look ahead
                if (ResultsPerPage > 100)
                {
                    executeCommand.Parameters.AddWithValue("@minpagelookahead", 1);
                    executeCommand.Parameters.AddWithValue("@maxpagelookahead", 1);
                    executeCommand.Parameters.AddWithValue("@lookahead_factor", LOOKAHEAD_FACTOR);
                }
                else
                {
                    executeCommand.Parameters.AddWithValue("@minpagelookahead", MIN_PAGE_LOOKAHEAD);
                    executeCommand.Parameters.AddWithValue("@maxpagelookahead", MAX_PAGE_LOOKAHEAD);
                    executeCommand.Parameters.AddWithValue("@lookahead_factor", LOOKAHEAD_FACTOR);
                }

                if ((Include_Facets) && (Facet_Types != null) && ( Facet_Types.Count > 0 ) && (Return_Search_Statistics))
                {
                    executeCommand.Parameters.AddWithValue("@include_facets", Include_Facets);
                    if (Facet_Types.Count > 0)
                        executeCommand.Parameters.AddWithValue("@facettype1", Facet_Types[0]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype1", -1);
                    if (Facet_Types.Count > 1)
                        executeCommand.Parameters.AddWithValue("@facettype2", Facet_Types[1]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype2", -1);
                    if (Facet_Types.Count > 2)
                        executeCommand.Parameters.AddWithValue("@facettype3", Facet_Types[2]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype3", -1);
                    if (Facet_Types.Count > 3)
                        executeCommand.Parameters.AddWithValue("@facettype4", Facet_Types[3]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype4", -1);
                    if (Facet_Types.Count > 4)
                        executeCommand.Parameters.AddWithValue("@facettype5", Facet_Types[4]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype5", -1);
                    if (Facet_Types.Count > 5)
                        executeCommand.Parameters.AddWithValue("@facettype6", Facet_Types[5]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype6", -1);
                    if (Facet_Types.Count > 6)
                        executeCommand.Parameters.AddWithValue("@facettype7", Facet_Types[6]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype7", -1);
                    if (Facet_Types.Count > 7)
                        executeCommand.Parameters.AddWithValue("@facettype8", Facet_Types[7]);
                    else
                        executeCommand.Parameters.AddWithValue("@facettype8", -1);
                }
                else
                {
                    executeCommand.Parameters.AddWithValue("@include_facets", false);
                    executeCommand.Parameters.AddWithValue("@facettype1", -1);
                    executeCommand.Parameters.AddWithValue("@facettype2", -1);
                    executeCommand.Parameters.AddWithValue("@facettype3", -1);
                    executeCommand.Parameters.AddWithValue("@facettype4", -1);
                    executeCommand.Parameters.AddWithValue("@facettype5", -1);
                    executeCommand.Parameters.AddWithValue("@facettype6", -1);
                    executeCommand.Parameters.AddWithValue("@facettype7", -1);
                    executeCommand.Parameters.AddWithValue("@facettype8", -1);
                }

                // Add parameters for total items and total titles
                SqlParameter totalItemsParameter = executeCommand.Parameters.AddWithValue("@total_items", 0);
                totalItemsParameter.Direction = ParameterDirection.InputOutput;

                SqlParameter totalTitlesParameter = executeCommand.Parameters.AddWithValue("@total_titles", 0);
                totalTitlesParameter.Direction = ParameterDirection.InputOutput;

                // Add parameters for items and titles if this search is expanded to include all aggregations
                SqlParameter expandedItemsParameter = executeCommand.Parameters.AddWithValue("@all_collections_items", 0);
                expandedItemsParameter.Direction = ParameterDirection.InputOutput;

                SqlParameter expandedTitlesParameter = executeCommand.Parameters.AddWithValue("@all_collections_titles", 0);
                expandedTitlesParameter.Direction = ParameterDirection.InputOutput;

                // Create the data reader
                connect.Open();
                using (SqlDataReader reader = executeCommand.ExecuteReader())
                {

                    // Create the return argument object
                    returnArgs = new Multiple_Paged_Results_Args
                                     {Paged_Results = DataReader_To_Result_List_With_LookAhead(reader, ResultsPerPage)};

                    // Create the overall search statistics?
                    if (Return_Search_Statistics)
                    {
                        Search_Results_Statistics stats = new Search_Results_Statistics(reader, Facet_Types);
                        returnArgs.Statistics = stats;
                        reader.Close();
                        stats.Total_Items = Convert.ToInt32(totalItemsParameter.Value);
                        stats.Total_Titles = Convert.ToInt32(totalTitlesParameter.Value);
                        stats.All_Collections_Items = Convert.ToInt32(expandedItemsParameter.Value);
                        stats.All_Collections_Titles = Convert.ToInt32(expandedTitlesParameter.Value);
                    }
                    else
                    {
                        reader.Close();
                    }
                }
                connect.Close();
            }

            // Return the built result arguments
            return returnArgs;
        }