Search

Prerequisite

Indexing has to be set-up before moving on to Search-related functionalities. For more details, please refer to

Overall Approach

In order to search without restrictions, using the full potential of Hawksearch, the connector provides the Optimizely.Hawksearch.Client package. This package contains classes which will correspond to the requests and responses provided by Hawksearch’s Search API.

  • SearchRequest

  • SearchResponse


It also provides a client class named SearchClient that will be responsible for calling the mentioned APIs and for deserializing the responses.

For a better experience and easier development, we included in the Optimizely.Hawksearch.Connector package:

The Flow

  1. Using only Optimizely.Hawksearch.Client

  • Create and populate a SearchRequest object

  • Use the Search method of the SearchClient class (or its async counterpart)

    public SearchResponse<T> Search<T>(SearchRequest searchRequest) where T : HawksearchBaseItem public async Task<SearchResponse<T>> SearchAsync<T>(SearchRequest searchRequest) where T : HawksearchBaseItem
  • Get the SearchResponse object then map it to your business models

 

  1. Using both

Optimizely.Hawksearch.Client and Optimizely.Hawksearch.Connector

  • Create and populate a SearchQuery object

  • Build a SearchRequest object by passing the created SearchQuery object to a SearchRequestBuilder and its Fluent API

  • Use one of the Search methods of the SearchClient class shown above

  • Get the SearchResponse object then map it to your business models


A high-level example:

var searchQuery = new SearchQuery { Keyword = "jacket", Page = 1, PageSize = 5 }; var results = Search(searchQuery); public ProductSearchResults Search(SearchQuery searchQuery) { var searchRequest = new SearchRequestBuilder() .PublishedOnly() .WithQueryOn(HawksearchConstants.PropertyNames.ItemType, HawksearchConstants.DocumentTypes.Product, FieldSearchType.Keyword) .ForLanguage("en") .InMarket("US") .InCatalog(0) .Build(searchQuery); //SearchClient _client var searchResponse = _client.Search<HawksearchProductItem>(searchRequest); var mappedResponse = MapResults(searchResponse); return mappedResponse; }

Â