Windows Azure Search - How do I use it?

Many times I try new features and I wonder how to use them in azure.  This one is very easy to use and provides me a search indexing service provided with the support of the robust backend of Azure Search Services.  This is an an intro of how Azure search services can work for you.

<p>Windows Azure Search - How do I use it?</p>

Azure search services are an easy way to integrate the Azure cloud into any on-prem or cloud application.  The cost is resonable, and the configuration is easy based on the portal that they provide.  Below is a sample of code that you can use to create a sample search client using the .NET framework.  Video tutorial is on it's way!

 

using Microsoft.Azure.Search;
using Microsoft.Azure.Search.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Azure_Search_Test
{
    class Program
    {
        static void Main(string[] args)
        {
            var searchID = "<searchID>";
            var indexName = "<indexName>";
            var searchKey = "<searchKey>";
            bool quit = false;
            while (!quit)
            {
                Console.WriteLine("Enter your Site ID:");
                string Site =Console.ReadLine();

                int SiteID = -1;
                if (!int.TryParse(Site, out SiteID))
                {
                    quit = true;
                    continue;
                }
                Console.WriteLine("Enter your Search Text:");
                string SearchText= Console.ReadLine();

                Console.Clear();

                SearchIndexClient search = new SearchIndexClient(searchID, indexName, new Microsoft.Azure.Search.SearchCredentials(searchKey));
                SearchParameters parameters;
                parameters =
            new SearchParameters()
            {
               Facets = new string[] { "CategoryName" },
               Filter= "SiteID eq " + SiteID.ToString()
               
            };
                var result = search.Documents.Search(SearchText, parameters);
                foreach (var r in result.Results)
                {

                    Console.WriteLine(r.Document["Title"] + ": /article/" + r.Document["ArticleID"]);
                    foreach (var v in r.Document)
                        Console.WriteLine("\t" + v.Key + ": " + v.Value);
                }
                
            }

        }
    }
}
Last Updated: 2/24/2017 11:15:12 PM