Coder Social home page Coder Social logo

reddog.search's Introduction

RedDog.Search

This library interacts with the Microsoft Azure Search REST API. You can use the library to manage indexes, populate indexes and execute queries.

Getting Started

Initialize the ApiConnection with your credentials:

ApiConnection connection = ApiConnection.Create("myservice","mykey");

Index Management

Creating an index:

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()));

Updating an index:

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()));

Adding a scoring profile

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);

List all indexes:

var client = new IndexManagementClient(connection);
var indexes = await client.GetIndexesAsync();

Delete an index:

var client = new IndexManagementClient(connection);
var records = await client.DeleteIndexAsync("records");

Get the statistics for an index:

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);

Upload data to your index:

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)));

Querying

Execute a query:

var client = new IndexQueryClient(connection);
var results = await client.SearchAsync("records", new SearchQuery("movie")
    .OrderBy("author")
    .SearchField("title")
    .Count(true));

Execute a query by using NextLink:

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);

Execute a query with highlighting:

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>"));

Execute a query with faceting:

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));

Execute a query with a score profile:

var client = new IndexQueryClient(connection);
var results = await client.SearchAsync("records", new SearchQuery("products")
    .SearchField("title")
	.ScoringProfile("personalized")
    .ScoringParameter("brands:brandA,brandB")
    .Count(true));

Execute a suggestion:

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));

Execute a lookup:

var client = new IndexQueryClient(connection);
var results = await client.SuggestAsync("records", new LookupQuery("11ad89b6-9f1b-4380-aa06-8da39df61210")
	.Select("author,title"));

Handling exceptions:

var response = await client.DoSomething();
if (!response.IsSuccess)
{
    Console.WriteLine("{0}: {1}", response.Error.Code, response.Error.Message);
}

reddog.search's People

Contributors

nazgaul avatar sandrinodimattia avatar shibayan avatar toondc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reddog.search's Issues

Queries with / character causes silent failure

Not sure if this is you, or Azure Search service. If I try to post a query that has a '/' in the key column, I get some really unexpected behavior. The result of the PopulateAsync call comes back as a success, but there is nothing on the index. It turned out that the '/' in my url used as the key field was causing the problem. As soon as I UrlEncoded'd the value, everything started to work again:

var popResult = await client.PopulateAsync(indexName,
    new IndexOperation(IndexOperationType.Upload, "url", HttpUtility.UrlEncode(url))
        .WithProperty("content", articleMetadata.Content)
        .WithProperty("title", articleMetadata.Metadata["pageTitle"])
);

PopulateAsync fails when more the 1000 Index Operations

This is not a bug but rather a missing feature.

As per http://msdn.microsoft.com/en-us/library/azure/dn798930.aspx, a POST for populating an index should not contain more than 1000 document entities.

(up to 1000 documents per batch, or about 16 MB per batch)

Actually, when trying to upload more than 1000 documents, Azure Search REST API returns the following error message:

{"error":{"code":"","message":"The request is invalid.","innererror":{"message":"actions : The items collection must have from 1 to 1000 valid items to be indexed.\r\n","type":"","stacktrace":""}}}

PopulateAsync should handle some kind of batch mode, splitting the IndexOperation param array into parts up to maximum documents per batch.

Facet search implementation does not respect faceting parameters

As per the api documentation, the facet parameter may contain 4 optional protected parameters 'count', 'sort', 'values' and 'interval'
http://msdn.microsoft.com/en-us/library/azure/dn798927.aspx

For example when I use .Facet("wng_tags,count:100") it should translate to
search=test&facet=wng_tags,count:100 and not treat the special parameter 'count' as a new facet parameter, like it does now: search=test&facet=wng_tags&facet=count:100. This returns an error as we have no field with the name 'count'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.