public dynamic Suggest(string searchText)
        {
            // we still need a default filter to exclude discontinued products from the suggestions
            Uri uri = new Uri(_serviceUri, "/indexes/movies/docs/suggest?$filter=Title ne null&$select=Title&suggesterName=Sug&search=" + Uri.EscapeDataString(searchText));
            HttpResponseMessage response = AzureSearchHelper.SendSearchRequest(_httpClient, HttpMethod.Get, uri);

            AzureSearchHelper.EnsureSuccessfulSearchResponse(response);

            return(AzureSearchHelper.DeserializeJson <dynamic>(response.Content.ReadAsStringAsync().Result));
        }
        public dynamic Search(string searchText, string sort, string directors, string genres, int?yearFrom, int?yearTo, double?ratingFrom, double?ratingTo)
        {
            string search  = "&search=" + Uri.EscapeDataString(searchText);
            string facets  = "&facet=Directors&facet=Genres&facet=Year,values:1970|1980|1990|2000|2010|2020&facet=Rating,values:2|4|6|8";
            string paging  = "&$top=50";
            string filter  = BuildFilter(directors, genres, yearFrom, yearTo, ratingFrom, ratingTo);
            string orderby = BuildSort(sort);

            Uri uri = new Uri(_serviceUri, "/indexes/movies/docs?$count=true" + search + facets + paging + filter + orderby);
            HttpResponseMessage response = AzureSearchHelper.SendSearchRequest(_httpClient, HttpMethod.Get, uri);

            AzureSearchHelper.EnsureSuccessfulSearchResponse(response);

            return(AzureSearchHelper.DeserializeJson <dynamic>(response.Content.ReadAsStringAsync().Result));
        }
Esempio n. 3
0
    /// <summary>
    /// This function will return a formatted string of the documents mathcing the specified search value
    /// </summary>
    /// <param name="strValue">string - Search value</param>
    /// <returns>string - Some totally awesome search results</returns>
    private string SearchIndex(string strValue)
    {
        StringBuilder sb = new StringBuilder();

        try
        {
            //Build up the search parameter
            string search = "&search=" + Uri.EscapeDataString(strValue);

            //Get the Azure Search records for the specified value
            if (strValue.Length > 2)
            {
                Uri uri = new Uri(_serviceUri, "/indexes/" + this.AzureSearchServiceIndexName + "/docs/suggest?" + search);
                HttpResponseMessage response = AzureSearchHelper.SendSearchRequest(_httpClient, HttpMethod.Get, uri);
                AzureSearchHelper.EnsureSuccessfulSearchResponse(response);

                dynamic results = AzureSearchHelper.DeserializeJson <dynamic>(response.Content.ReadAsStringAsync().Result);

                //Create a list of the results so we can loop over them and find the assoicated document
                IEnumerable <AzureResultItem> items = ((JArray)results["value"]).Select(x => new AzureResultItem
                {
                    documentid   = (string)x["DocumentID"],
                    documentname = (string)x["@search.text"]
                }).ToList();

                foreach (AzureResultItem item in items)
                {
                    sb.Append(item.documentname + "<br />");
                    var doc = DocumentHelper.GetDocument(ValidationHelper.GetInteger(item.documentid, 0), null);
                    sb.Append("<a href=\"~" + doc.NodeAliasPath + "\">" + doc.NodeAliasPath + "</a><br /><br />");
                }
            }
            else
            {
                sb.Append("You must enter atleast 3 characters.");
            }
        }
        catch (Exception ex)
        {
            sb.Append(ex.Message);
        }
        return(sb.ToString());
    }
Esempio n. 4
0
        public dynamic Search(string searchText, string sort, string category, string department, string portfolio, string brandName)
        {
            string search = "&search=" + Uri.EscapeDataString(searchText);
            string facets = "&facet=L3_NAME&facet=L1_NAME&facet=L2_NAME&facet=BRAND_NAME";

            string paging = "&$top=100";

            string filter  = String.Empty;
            string orderby = String.Empty;

            string[] depList = department.Split(',');

            if (!string.IsNullOrWhiteSpace(department))
            {
                foreach (String d in depList)
                {
                    if (!String.IsNullOrEmpty(d))
                    {
                        if (string.IsNullOrEmpty(filter))
                        {
                            filter += "&$filter=(L1_NAME eq '" + EscapeODataString(d) + "'";
                        }
                        else
                        {
                            filter += " or L1_NAME eq '" + EscapeODataString(d) + "'";
                        }
                    }
                }

                if (!string.IsNullOrEmpty(filter))
                {
                    filter += ")";
                }
            }


            if (!string.IsNullOrWhiteSpace(category))
            {
                filter += "&$filter=L3_NAME eq '" + EscapeODataString(category) + "'";
            }


            string[] brandList = brandName.Split(',');

            if (!string.IsNullOrWhiteSpace(brandName.Replace(',', ' ').Trim()))
            {
                foreach (String b in brandList)
                {
                    if (!String.IsNullOrEmpty(b))
                    {
                        if (string.IsNullOrEmpty(filter))
                        {
                            filter += "&$filter=(BRAND_NAME eq '" + EscapeODataString(b) + "'";
                        }
                        else
                        {
                            if (b == brandList[0])
                            {
                                filter += " and (BRAND_NAME eq '" + EscapeODataString(b) + "'";
                            }
                            else
                            {
                                filter += " or BRAND_NAME eq '" + EscapeODataString(b) + "'";
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(filter))
                {
                    filter += ")";
                }
            }

            Uri uri = new Uri(_serviceUri, "/indexes/dpg/docs?$count=true" + search + facets + paging + filter + orderby);

            HttpResponseMessage response = AzureSearchHelper.SendSearchRequest(_httpClient, HttpMethod.Get, uri);

            AzureSearchHelper.EnsureSuccessfulSearchResponse(response);

            var result = AzureSearchHelper.DeserializeJson <dynamic>(response.Content.ReadAsStringAsync().Result);

            return(result);
        }