This library interacts with the Microsoft Azure Search REST API. You can use the library to manage indexes, populate indexes and execute queries.
ApiConnection connection = ApiConnection.Create("myservice","mykey");
var client = new IndexManagementClient(connection);
await client.CreateIndexAsync(new Index("records")
.WithStringField("id", f => f
.IsKey()
.IsRetrievable())
.WithStringField("title", f => f
.IsSearchable()
.IsRetrievable())
.WithDateTimeField("createdOn", f => f
.IsRetrievable()));
var client = new IndexManagementClient(connection);
await client.UpdateIndexAsync(new Index("records")
.WithStringField("id", f => f
.IsKey()
.IsRetrievable())
.WithStringField("author", f => f
.IsSearchable()
.IsSortable()
.IsRetrievable())
.WithStringField("title", f => f
.IsSearchable()
.IsRetrievable())
.WithDateTimeField("createdOn", f => f
.IsRetrievable()));
var index = new Index("products")
// add additional fields to the index.
ScoringProfile scoringProfile = new ScoringProfile();
scoringProfile.Name = "personalized";
scoringProfile.Functions.Add(new ScoringProfileFunction()
{
Type = ScoringProfileFunctionType.Tag,
Boost = 2,
FieldName = "brandTags",
Tag = new ScoringProfileFunctionTag() { TagsParameter = "brands" }
});
index.ScoringProfiles.Add(scoringProfile);
var client = new IndexManagementClient(connection);
var indexes = await client.GetIndexesAsync();
var client = new IndexManagementClient(connection);
var records = await client.DeleteIndexAsync("records");
var client = new IndexManagementClient(connection);
var records = await client.GetIndexStatisticsAsync("records");
Console.WriteLine("Total documents: {0}", records.Body.DocumentCount);
Console.WriteLine("Total size: {0} bytes", records.Body.StorageSize);
var client = new IndexManagementClient(connection);
var result = await client.PopulateAsync("records",
new IndexOperation(IndexOperationType.Upload, "id", "1")
.WithProperty("title", "My first movie")
.WithProperty("author", "Sandrino")
.WithProperty("createdOn", new DateTimeOffset(2014, 8, 1, 0, 0, 0, TimeSpan.Zero)),
new IndexOperation(IndexOperationType.Upload, "id", "2")
.WithProperty("title", "My second movie")
.WithProperty("author", "Sandrino")
.WithProperty("createdOn", new DateTimeOffset(2014, 8, 2, 0, 0, 0, TimeSpan.Zero)));
var client = new IndexQueryClient(connection);
var results = await client.SearchAsync("records", new SearchQuery("movie")
.OrderBy("author")
.SearchField("title")
.Count(true));
var client = new IndexQueryClient(connection);
var results = await client.SearchAsync("records", new SearchQuery("movie")
.OrderBy("author")
.SearchField("title")
.Count(true));
var nextResults = await client.SearchAsync(results.Body.NextLink);
var client = new IndexQueryClient(connection);
var results = await client.SearchAsync("records", new SearchQuery("movie")
.OrderBy("author")
.SearchField("title")
.Count(true)
.Highlight("title")
.HighlightPreTag("<p>")
.HighlightPostTag("</p>"));
var client = new IndexQueryClient(connection);
var results = await client.SearchAsync("records", new SearchQuery("movie")
.OrderBy("author")
.SearchField("title")
.Facet("rating", "values:1|2|3")
.Count(true));
var client = new IndexQueryClient(connection);
var results = await client.SearchAsync("records", new SearchQuery("products")
.SearchField("title")
.ScoringProfile("personalized")
.ScoringParameter("brands:brandA,brandB")
.Count(true));
var client = new IndexQueryClient(connection);
var results = await client.SuggestAsync("records", new SuggestionQuery("mov")
.Fuzzy(true)
.Select("author")
.Select("title")
.SearchField("title")
.OrderBy("title")
.Top(10));
var client = new IndexQueryClient(connection);
var results = await client.SuggestAsync("records", new LookupQuery("11ad89b6-9f1b-4380-aa06-8da39df61210")
.Select("author,title"));
var response = await client.DoSomething();
if (!response.IsSuccess)
{
Console.WriteLine("{0}: {1}", response.Error.Code, response.Error.Message);
}