Esempio n. 1
0
        private async Task <List <string> > ExecSuggest(string q)
        {
            // Execute /suggest API call to Azure Search and parse results
            string url = _serviceUri + AzureSuggestUrl + q;

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

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

            JObject       jsonObj     = JObject.Parse(result.ToString());
            List <string> Suggestions = new List <string>();

            // Iterate through the results to get the suggestions
            foreach (var item in jsonObj["value"])
            {
                Suggestions.Add(item["@search.text"].ToString());
            }
            // Limit to unique suggestions and sort
            return(Suggestions.Distinct().OrderBy(x => x).ToList());
        }
Esempio n. 2
0
        private int ExecListingsSearch(string q = null, bool countOnly = false)
        {
            // Execute a search using the supplied text and apply the results to a new listings list page
            string url = _serviceUri + AzureSearchUrl + "*";

            if (q != "")
            {
                url = _serviceUri + AzureSearchUrl + q;
            }

            // Append the count request
            url += "&$count=true";
            url += "&$top=10";

            // Set the page
            url += "&$skip=" + currentPage * 10;

            // Append the filter
            url += "&$filter=beds ge " + filterMinBeds + " and beds le " + filterMaxBeds +
                   " and baths ge " + filterMinBaths + " and baths le " + filterMaxBaths;

            // Determing the status filter
            string statusFilter = string.Empty;

            if ((filterShowForSale) && (filterShowPending) && (filterShowSold))
            {
                statusFilter = " and (status eq 'active' or status eq 'pending' or status eq 'sold')";
            }
            else if (!(filterShowForSale) && (filterShowPending) && (filterShowSold))
            {
                statusFilter = " and (status eq 'pending' or status eq 'sold')";
            }
            else if ((filterShowForSale) && !(filterShowPending) && (filterShowSold))
            {
                statusFilter = " and (status eq 'active' or status eq 'sold')";
            }
            else if ((filterShowForSale) && (filterShowPending) && !(filterShowSold))
            {
                statusFilter = " and (status eq 'active' or status eq 'pending')";
            }
            else if ((filterShowForSale) && !(filterShowPending) && !(filterShowSold))
            {
                statusFilter = " and (status eq 'active')";
            }
            else if (!(filterShowForSale) && !(filterShowPending) && (filterShowSold))
            {
                statusFilter = " and (status eq 'sold')";
            }
            else if (!(filterShowForSale) && (filterShowPending) && !(filterShowSold))
            {
                statusFilter = " and (status eq 'pending')";
            }
            else
            {
                statusFilter = " and status eq 'noresults'";
            }
            url += statusFilter;

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

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

            JObject jsonObj = JObject.Parse(result.ToString());

            if (countOnly == false)
            {
                ListingsForList = new List <ListListing>();;

                foreach (var item in jsonObj["value"])
                {
                    ListListing ll = new ListListing();
                    ll.ImageUrl = item["thumbnail"].ToString();
                    string price = "$" + Convert.ToInt32(item["price"].ToString()).ToString("#,##0");
                    ll.MainText = price + " Beds: " + item["beds"].ToString() +
                                  " Baths: " + item["baths"].ToString() +
                                  " Sq Ft.: " + Convert.ToInt32(item["sqft"].ToString()).ToString("#,##0");

                    ll.Id = item["listingId"].ToString();
                    // build up the address
                    string address = string.Empty;
                    if (item["number"] != null)
                    {
                        address += item["number"].ToString() + " ";
                    }
                    if (item["street"] != null)
                    {
                        address += item["street"].ToString() + " ";
                    }
                    if (item["city"] != null)
                    {
                        address += item["city"].ToString() + " ";
                    }
                    if (item["region"] != null)
                    {
                        address += item["region"].ToString() + " ";
                    }

                    ll.SubText = address;
                    ListingsForList.Add(ll);
                }

                // Default to the listings list for search results
                ConfigureListingsLayout();
            }

            int docCount = Convert.ToInt32(jsonObj["@odata.count"].ToString());

            // Update the seek bar with the paging
            maxPage = Convert.ToInt32(docCount / 10) + 1;

            if (countOnly == false)
            {
                SeekBar seekBar = FindViewById <SeekBar>(Resource.Id.seekBarPaging);
                if (maxPage > 20)
                {
                    seekBar.Max = 19;   // Base 0
                }
                else
                {
                    seekBar.Max = maxPage;
                }
            }

            return(Convert.ToInt32(docCount.ToString()));
        }
Esempio n. 3
0
        private void ConfigureDetailsLayout(string listingId)
        {
            SetContentView(Resource.Layout.Details);

            // Do an Azure Search doc lookup using the specified id
            string url = _serviceUri + AzureLookupUrl + listingId;

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

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

            JObject json = JObject.Parse(result.ToString());

            if (json != null)
            {
                TextView txtPrice = FindViewById <TextView>(Resource.Id.textDetailsPrice);
                txtPrice.Text = "$" + Convert.ToInt32(json["price"].ToString()).ToString("#,##0");;

                TextView txtAddress = FindViewById <TextView>(Resource.Id.textDetailsAddress);
                string   address    = string.Empty;
                if (json["number"] != null)
                {
                    address += json["number"].ToString() + " ";
                }
                if (json["street"] != null)
                {
                    address += json["street"].ToString() + " ";
                }
                if (json["city"] != null)
                {
                    address += json["city"].ToString() + " ";
                }
                if (json["region"] != null)
                {
                    address += json["region"].ToString().ToUpper() + " ";
                }
                txtAddress.Text = address;

                ImageView imgListing  = FindViewById <ImageView>(Resource.Id.imageDetailListing);
                var       imageBitmap = GetImageBitmapFromUrl(json["thumbnail"].ToString());
                imgListing.SetImageBitmap(imageBitmap);

                TextView txtDetails = FindViewById <TextView>(Resource.Id.textDetailsDetails);
                txtDetails.Text = " Beds: " + json["beds"].ToString() +
                                  " Baths: " + json["baths"].ToString() +
                                  " Sq Ft.: " + Convert.ToInt32(json["sqft"].ToString()).ToString("#,##0");

                TextView txtStatus = FindViewById <TextView>(Resource.Id.textDetailsStatus);
                txtStatus.Text = "Status: " + json["status"].ToString();

                TextView txtDescription = FindViewById <TextView>(Resource.Id.textDetailsDescription);
                txtDescription.Text = json["description"].ToString();

                TextView txtListingId = FindViewById <TextView>(Resource.Id.textDetailsListingId);
                txtListingId.Text = "Listing ID: " + json["listingId"].ToString();
            }

            Button buttonBackToList = FindViewById <Button>(Resource.Id.btnMainToList);

            buttonBackToList.Click += ButtonBackToList_Click;
        }
Esempio n. 4
0
        private void ExecMoreLikeThisListingsSearch(string listingIid)
        {
            // Execute a search to find similar listings to the one currently being viewed
            string url = _serviceUri + AzureSearchUrl + "&morelikethis=" + listingIid;

            url += "&$top=1";

            // Only do comparison over a few fields
            url += "&searchFields=description,city,region";

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

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

            JObject jsonObj = JObject.Parse(result.ToString());

            ListingsSimilarForDetails = new List <ListListing>();;

            foreach (var item in jsonObj["value"])
            {
                ListListing ll = new ListListing();
                ll.ImageUrl = item["thumbnail"].ToString();
                string price = "$" + Convert.ToInt32(item["price"].ToString()).ToString("#,##0");
                ll.MainText = price + " Beds: " + item["beds"].ToString() +
                              " Baths: " + item["baths"].ToString() +
                              " Sq Ft.: " + Convert.ToInt32(item["sqft"].ToString()).ToString("#,##0");

                ll.Id = item["listingId"].ToString();
                // build up the address
                string address = string.Empty;
                if (item["number"] != null)
                {
                    address += item["number"].ToString() + " ";
                }
                if (item["street"] != null)
                {
                    address += item["street"].ToString() + " ";
                }
                if (item["city"] != null)
                {
                    address += item["city"].ToString() + " ";
                }
                if (item["region"] != null)
                {
                    address += item["region"].ToString() + " ";
                }

                ll.SubText = address;
                ListingsSimilarForDetails.Add(ll);
            }

            // Default to the listings list for search results
            ListView lvListingsSimilar = FindViewById <ListView>(Resource.Id.lvListingsSimilar);

            lvListingsSimilar.Adapter    = new LoadListings(this, ListingsSimilarForDetails);
            lvListingsSimilar.ItemClick += LvListingsSimilar_ItemClick;

            return;
        }