public SPSearch(ServiceAssemblyBase serviceBroker, Configuration configuration)
 {
     // Set local serviceBroker variable.
     this.serviceBroker = serviceBroker;
     this.Configuration = configuration;
 }
        public static RESTSearchResultsSerialized ExecuteSearch(SearchInputs inputs, Configuration Configuration, ServiceAssemblyBase serviceBroker)
        {
            RESTSearchResults res = Utilities.BrokerUtils.ExecuteRESTRequest(Utilities.BrokerUtils.BuildSearchText(inputs, Configuration), serviceBroker);

            return ProcessResults(res, inputs);
        }
        public static RESTSearchResultsSerialized ExecuteSharePointSearchRaw(Property[] inputs, RequiredProperties required, Configuration Configuration, ServiceAssemblyBase serviceBroker)
        {
            // Raw search = append input to end of querytext
            SearchInputs SearchInputs = new SearchInputs();
            string search = string.Empty;
            var searchProp = inputs.Where(p => p.Name.Equals("search", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
            if (searchProp != null && searchProp.Value != null && !string.IsNullOrWhiteSpace(searchProp.Value.ToString()))
            {
                search = searchProp.Value.ToString();
                SearchInputs.Search = search;
            }
            else
            {
                throw new Exception("Search is a required property");
            }

            string RequestUri = Configuration.SiteUrl + "/_api/search/query?querytext=" + search;

            return ProcessResults(ExecuteRESTRequest(RequestUri, serviceBroker), SearchInputs);
        }
 public static RESTSearchResultsSerialized ExecuteSharePointUserSearch(Property[] inputs, RequiredProperties required, Configuration Configuration, ServiceAssemblyBase serviceBroker)
 {
     SearchInputs SearchInputs = Utilities.BrokerUtils.GetUserSearchInputs(inputs);
     return ExecuteSearch(SearchInputs, Configuration, serviceBroker);
 }
        public static string BuildSearchText(SearchInputs Inputs, Configuration Configuration)
        {

            string RequestUri = Configuration.SiteUrl + "/_api/search/query";
            string SearchQuery = string.Empty;

            SearchQuery = "?querytext='" + Inputs.Search + "'";

            if (!string.IsNullOrWhiteSpace(Inputs.SiteUrl))
            {
                string p = "+path:\"" + Inputs.SiteUrl + "\"";
                SearchQuery = SearchQuery.Insert(SearchQuery.Length - 1, p);
            }

            SearchQuery += "&culture=" + Configuration.LocaleId;

            if (Inputs.StartRow.HasValue && Inputs.StartRow.Value > -1)
            {
                SearchQuery += "&startrow=" + Inputs.StartRow;
            }

            if (Inputs.RowLimit.HasValue && Inputs.RowLimit.Value > -1)
            {
                SearchQuery += "&rowlimit=" + Inputs.RowLimit;
            }

            if (Inputs.SourceId != null && Inputs.SourceId != Guid.Empty)
            {
                SearchQuery += "&sourceid='" + Inputs.SourceId + "'";
            }

            if (Inputs.Sort.Count > 0)
            {
                SearchQuery += "&sortlist='" + Inputs.SortString + "'";
            }

            if (!string.IsNullOrWhiteSpace(Inputs.Properties))
            {
                SearchQuery += "&Properties='" + Inputs.Properties + "'";
            }

            if (Inputs.FileExtensions != null && Inputs.FileExtensions.Count > 0)
            {
                //&refiners='filetype'

                if (Inputs.FileExtensions.Count < 2)
                {
                    SearchQuery += "&refiners='filetype,fileextension'&refinementfilters='filetype:equals(" + Inputs.FileExtensionsString + ")'";
                }
                else
                {
                    SearchQuery += "&refiners='filetype,fileextension'&refinementfilters='filetype:or(" + Inputs.FileExtensionsString + ")'";
                    //serviceBroker.ServicePackage.PageNumber
                    //serviceBroker.ServicePackage.PageSize;

                }
            }

            if (Inputs.EnableStemming.HasValue)
            {
                SearchQuery += "&enablestemming=" + Inputs.EnableStemming.ToString().ToLower();
            }

            if (Inputs.TrimDuplicates.HasValue)
            {
                SearchQuery += "&trimduplicates=" + Inputs.TrimDuplicates.ToString().ToLower();
            }

            if (Inputs.EnableQueryRules.HasValue)
            {
                SearchQuery += "&enablequeryrules=" + Inputs.EnableQueryRules.ToString().ToLower();
            }

            if (Inputs.ProcessBestBets.HasValue)
            {
                SearchQuery += "&processbestbets=" + Inputs.ProcessBestBets.ToString().ToLower();
            }

            if (Inputs.ProcessPersonal.HasValue)
            {
                SearchQuery += "&processpersonalfavorites=" + Inputs.ProcessPersonal.ToString().ToLower();
            }

            if (Inputs.EnableNicknames.HasValue)
            {
                SearchQuery += "&enablenicknames=" + Inputs.EnableNicknames.ToString().ToLower();
            }

            if (Inputs.EnablePhonetic.HasValue)
            {
                SearchQuery += "&enablephonetic=" + Inputs.EnablePhonetic.ToString().ToLower();
            }

            return RequestUri + SearchQuery;
        }