Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thecogworks/cogworks.azuresearch

A wrapper to Azure Search allowing to easily setup Azure Search indexes, searchers.
https://github.com/thecogworks/cogworks.azuresearch

azure azure-cognitive-search azure-search azuresearch cogworks hacktoberfest search searchers

Last synced: 3 months ago
JSON representation

A wrapper to Azure Search allowing to easily setup Azure Search indexes, searchers.

Awesome Lists containing this project

README

        

# Cogworks.AzureSearch · [![GitHub license](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE.md) [![Github Build](https://img.shields.io/github/workflow/status/thecogworks/cogworks.azuresearch/Changelog%20generator%20and%20NuGet%20Releasing)](https://github.com/thecogworks/Cogworks.AzureSearch/actions?query=workflow%3A%22Changelog+generator+and+NuGet+Releasing%22) [![NuGet Version](https://img.shields.io/nuget/v/Cogworks.AzureSearch)](https://www.nuget.org/packages/Cogworks.AzureSearch/) [![codecov](https://codecov.io/gh/thecogworks/UmbracoAzureSearch/branch/master/graph/badge.svg?token=UMLJ5S8UJX)](undefined)

A wrapper to Azure Search allowing to easily setup Azure Search indexes, searchers and using it with DI/IoC approach (currently with support for Umbraco, LightInject and Autofac).

## Extension libraries

| Package Name | Release (NuGet) |
|--------------------------------|-----------------|
| `Cogworks.AzureSearch.IoC.Autofac` | [![NuGet Version](https://img.shields.io/nuget/v/Cogworks.AzureSearch.IoC.Autofac)](https://www.nuget.org/packages/Cogworks.AzureSearch.IoC.Autofac/) |
| `Cogworks.AzureSearch.IoC.LightInject` | [![NuGet Version](https://img.shields.io/nuget/v/Cogworks.AzureSearch.IoC.LightInject)](https://www.nuget.org/packages/Cogworks.AzureSearch.IoC.LightInject/) |
| `Cogworks.AzureSearch.IoC.Microsoft` | [![NuGet Version](https://img.shields.io/nuget/v/Cogworks.AzureSearch.IoC.Microsoft)](https://www.nuget.org/packages/Cogworks.AzureSearch.IoC.Umbraco/) |
| `Cogworks.AzureSearch.IoC.Umbraco` | [![NuGet Version](https://img.shields.io/nuget/v/Cogworks.AzureSearch.IoC.Umbraco)](https://www.nuget.org/packages/Cogworks.AzureSearch.IoC.Umbraco/) |

## Usage

#### Document Operations

```csharp
public class SomeDocumentService
{
private readonly IAzureDocumentOperation _documentOperation;

public SomeDocumentService(IAzureDocumentOperation documentOperation)
=> _documentOperation = documentOperation;

public async Task AddOrUpdateItem()
=> await _documentOperation.AddOrUpdateDocumentAsync(new FirstDocumentModel
{
Id = "some-id",
Content = "Some content"
});

public async Task AddOrUpdateItems()
{
var items = new List
{
new FirstDocumentModel
{
Id = "first-id",
Content = "First content"
},
new FirstDocumentModel
{
Id = "second-id",
Content = "Second content"
}
};

_ = await _documentOperation.AddOrUpdateDocumentsAsync(items);
}

public async Task RemoveItem()
=> await _documentOperation.TryRemoveDocumentAsync(new FirstDocumentModel
{
Id = "some-id"
});

public async Task RemoveItems()
{
var items = new List
{
new FirstDocumentModel
{
Id = "first-id"
},
new FirstDocumentModel
{
Id = "second-id"
}
};

_ = await _documentOperation.TryRemoveDocumentsAsync(items);
}
}
```

#### Search operations
##### Default search for index

```csharp
public class SomeService
{
private readonly ISearcher _documentSearch;

public SomeService(ISearcher documentSearch)
=> _documentSearch = documentSearch;

public void Search()
{
_ = _documentSearch.Search("Some text", new AzureSearchParameters
{
Top = 3
});
}

public async Task SearchAsync()
{
_ = await _documentSearch.SearchAsync("Some text", new AzureSearchParameters
{
Top = 3
});
}
}
```

##### Domain search

``` csharp
public interface ISomeDomainSearch
{
FirstDocumentModel GetLatestAuthorDocument(string author);
}

public class SomeDomainSearch : BaseDomainSearch, ISomeDomainSearch
{
public SomeDomainSearch(ISearcher searcher) : base(searcher)
{
}

FirstDocumentModel GetLatestAuthorDocument(string author)
=> base.Search("*", new AzureSearchParameters
{
Filter = nameof(FirstDocumentModel.Author).EqualsValue(author)
OrderBy = new List() { nameof(FirstDocumentModel.PublishedDate) + "desc" }
Top = 1
}).Results.FirstOrDefault()?.Document;
}
```

#### Index Operations

```csharp
public class SomeIndexService
{
private readonly IAzureIndexOperation _indexOperation;
public SomeIndexService(IAzureIndexOperation indexOperation)
=> _indexOperation = indexOperation;

public async Task Work()
{
_ = await _indexOperation.IndexExistsAsync();
_ = await _azureIndexOperation.IndexCreateOrUpdateAsync();
_ = await _azureIndexOperation.IndexClearAsync();
await _indexOperation.IndexDeleteAsync()
}
}
```

#### Repository Operations

All operations (API) that are available for: Document Operations, Search Operations, Index Operations.

```csharp
public class SomeAdvanceService
{
private readonly IAzureSearchRepository _documentRepository;
public SomeAdvanceService(IAzureSearchRepository documentRepository)
=> _documentRepository = documentRepository;

public async Task Work()
{
// some work here
}
}
```

#### Initializer

```csharp
public class SomeStartupService
{
private readonly IAzureInitializer _initializer;

public SomeStartupService(IAzureInitializer initializer)
=> _initializer = initializer;

public async Task Initialize()
=> await initializer.InitializeAsync();
}
```

## License

- Cogworks.AzureSearch is licensed under the [Apache License, Version 2.0](https://opensource.org/licenses/Apache-2.0)

## Code of Conduct

This project has adopted the code of conduct defined by the [Contributor Covenant](https://contributor-covenant.org/) to clarify expected behavior in our community.
For more information, see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct).

## Blogs

* [How to Simplify Azure Search Implementations](https://www.wearecogworks.com/blog/how-to-simplify-azure-search-implementations/)

## How can you help?

Please... Spread the word, contribute, submit improvements and issues, unit tests, no input is too little. Thank you in advance <3