From 32fc2c1d3b4cb33e00f1426252c0e466d8911ef5 Mon Sep 17 00:00:00 2001 From: Spencer O'HEGARTY Date: Mon, 29 Jul 2024 16:43:41 +0100 Subject: [PATCH] Updated readme. --- README.md | 94 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 78 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index e6047e3..a460364 100644 --- a/README.md +++ b/README.md @@ -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)); +builder.Services.AddScoped, SearchByKeywordUseCase>(); +builder.Services.AddSingleton(typeof(IMapper>, EstablishmentResults>), typeof(AzureSearchResponseToEstablishmentResultMapper)); +builder.Services.AddSingleton, SearchOptionsToAzureOptionsMapper>(); +builder.Services.AddSingleton, SearchByKeywordResponseToViewModelMapper>(); +builder.Services.AddSingleton, AzureSearchResultToEstablishmentMapper>(); +builder.Services.AddSingleton, ResultsToResponseMapper>(); + +builder.Services.AddOptions("establishments") + .Configure( + (settings, configuration) => + configuration.GetSection("AzureCognitiveSearchOptions:SearchEstablishment:SearchSettingsOptions").Bind(settings)); + +builder.Services.AddScoped(); +``` +### Code Usage/Examples + +Typical dependency injection and search request would look something like the following, + +``` +public class HomeController : Controller +{ + private readonly IUseCase _searchByKeywordUseCase; + private readonly IMapper _mapper; + + public HomeController( + ILogger logger, + IUseCase searchByKeywordUseCase, + IMapper mapper) + { + _searchByKeywordUseCase = searchByKeywordUseCase; + _mapper = mapper; + } + + public async Task 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.