-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16fb771
commit 32fc2c1
Showing
1 changed file
with
78 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,93 @@ | ||
|
||
# infrastructure-cognitive-search | ||
A library to provide an accessible API for working with Azure cognitive search. The package contains a fully configured | ||
A library to provide an accessible API for working with Azure cognitive search. The package contains a fully configured default service for searching by keyword, as well as a geo-location service which allows searches to be made by town, or post-code. The package is intended to take the heavy-lifting away in terms of setup and configurartion and allow for an easy, pluggable set of components that can be used across projects. | ||
|
||
|
||
# Package readme title, e.g., display name or title of the package (optional) | ||
## Getting Started | ||
In order to leverage the search functionality it is necessary to register a number of default dependencies. The dependencies can be used in isolation or registered as a whole under a single composition root, as below. | ||
|
||
Start with a clear and concise description: A brief overview of what your package is and does, also what problem it solves. | ||
### Prerequisites | ||
|
||
## Getting started | ||
In order to use the default search services it is possible to register all dependcies listed under the default composition root, in one registration, as follows: | ||
|
||
Explain how to use your package, provide clear and concise getting started instructions, including any necessary steps. | ||
``` | ||
builder.Services.RegisterDefaultSearchServices(builder.Configuration); | ||
``` | ||
|
||
### Prerequisites | ||
Alternatively, the registrations can be configured in the consuming application IOC container, with a typical registration configured as follows: | ||
|
||
``` | ||
builder.Services.AddAzureCognitiveSearchProvider(builder.Configuration); | ||
builder.Services.AddScoped(typeof(ISearchServiceAdapter), typeof(CognitiveSearchServiceAdapter<Infrastructure.Establishment>)); | ||
builder.Services.AddScoped<IUseCase<SearchByKeywordRequest, SearchByKeywordResponse>, SearchByKeywordUseCase>(); | ||
builder.Services.AddSingleton(typeof(IMapper<Response<SearchResults<Infrastructure.Establishment>>, EstablishmentResults>), typeof(AzureSearchResponseToEstablishmentResultMapper)); | ||
builder.Services.AddSingleton<IMapper<SearchSettingsOptions, SearchOptions>, SearchOptionsToAzureOptionsMapper>(); | ||
builder.Services.AddSingleton<IMapper<SearchByKeywordResponse, SearchResultsViewModel>, SearchByKeywordResponseToViewModelMapper>(); | ||
builder.Services.AddSingleton<IMapper<Infrastructure.Establishment, Search.Establishment>, AzureSearchResultToEstablishmentMapper>(); | ||
builder.Services.AddSingleton<IMapper<EstablishmentResults, SearchByKeywordResponse>, ResultsToResponseMapper>(); | ||
builder.Services.AddOptions<SearchSettingsOptions>("establishments") | ||
.Configure<IConfiguration>( | ||
(settings, configuration) => | ||
configuration.GetSection("AzureCognitiveSearchOptions:SearchEstablishment:SearchSettingsOptions").Bind(settings)); | ||
builder.Services.AddScoped<ISearchOptionsFactory, SearchOptionsFactory>(); | ||
``` | ||
### Code Usage/Examples | ||
|
||
Typical dependency injection and search request would look something like the following, | ||
|
||
``` | ||
public class HomeController : Controller | ||
{ | ||
private readonly IUseCase<SearchByKeywordRequest, SearchByKeywordResponse> _searchByKeywordUseCase; | ||
private readonly IMapper<SearchByKeywordResponse, SearchResultsViewModel> _mapper; | ||
public HomeController( | ||
ILogger<HomeController> logger, | ||
IUseCase<SearchByKeywordRequest, SearchByKeywordResponse> searchByKeywordUseCase, | ||
IMapper<SearchByKeywordResponse, SearchResultsViewModel> mapper) | ||
{ | ||
_searchByKeywordUseCase = searchByKeywordUseCase; | ||
_mapper = mapper; | ||
} | ||
public async Task<IActionResult> Index(string searchKeyWord) | ||
{ | ||
if (string.IsNullOrEmpty(searchKeyWord)) | ||
{ | ||
return View(); | ||
} | ||
ViewBag.SearchQuery = searchKeyWord; | ||
SearchByKeywordResponse response = | ||
await _searchByKeywordUseCase.HandleRequest( | ||
new SearchByKeywordRequest(searchKeyWord, "establishments")); | ||
SearchResultsViewModel viewModel = _mapper.MapFrom(response); | ||
return View(viewModel); | ||
} | ||
} | ||
``` | ||
|
||
## Built With | ||
|
||
* [.Net 8](https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-8/overview) - Core framework used | ||
* [Azure](https://learn.microsoft.com/en-us/azure/search/) - Cloud services provider (cognitive search) | ||
|
||
What are specific minimum requirements to use your packages? Consider excluding this section if your package works without any additional setup beyond simple package installation. | ||
|
||
## Usage | ||
## Versioning | ||
|
||
Examples about how to use your package by providing code snippets/example images, or samples links on GitHub if applicable. | ||
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/your/project/tags). | ||
|
||
- Provide sample code using code snippets | ||
- Include screenshots, diagrams, or other visual help users better understand how to use your package | ||
## Authors | ||
|
||
## Additional documentation | ||
* **Spencer O'Hegarty** - *Initial work* | ||
* **Catherine Lawlor** | ||
* **Asia Witek** | ||
|
||
Provide links to more resources: List links such as detailed documentation, tutorial videos, blog posts, or any other relevant documentation to help users get the most out of your package. | ||
## License | ||
|
||
## Feedback | ||
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details | ||
|
||
Where and how users can leave feedback? | ||
|
||
- Links to a GitHub repository where could open issues, Twitter, a Discord channel, bug tracker, or other platforms where a package consumer can connect with the package author. |