Search

The search module is an abstract specification of search functions which can have different search services plugged into it.  Currently there is one service implementation which plugs ElasticSearch into the Lynicon infrastructure. The Nuget module for this is LyniconANC.Search.ElasticSearch.

Configuring the module

.UseModule<Lynicon.Base.Modules.Search>((Func<Type, bool>)(t => t == typeof(Cafe)), (Func<Type, string>)(t => "main"), new ElasticSearchEngine())

The search module has a couple of settings as shown in the example above:

  • applyToType: set this to a function of Type to bool which returns true if the content type will be searched.
  • searchEngine: pass in an instance of a concrete subclass of BaseSearchEngine.

Configuring content types for search

Content types are configured for search by attaching the SearchableAttribute to the properties of the type which should be indexed. The SearchableAttribute specifies how the property is handled by the Search module. Its parameters are as follow:

  • Processing: string specifying how the property is processed, this could be the name of the analyzer used.
  • Indexing mode: Options are Not: the field is not index, Analyzed: the field is put through an analyzer, Unanalyzed: the field is stored as is.
  • IncludeInAll: A field is stored in the search index calculated from a concatenation of some of the fields of the content item allowing search across many relevant fields at once. If true, include this field.
  • Boost: Value of type double, indicating a multiplier for the addition to the score of a match caused by the match being in this field. Default is 1, set this higher e.g. 4 for fields like Title which are especially significant.

Ensure the content type returns true when you input it to the ApplyToType function so it is included in search.

Running a search

var (items, count) = await module.SearchEngine.Search<SearchContent>(
              new SearchSpec { IndexName = "search-test", TextSearch = "problem" }, 0, 100);