Querying search index

To query the search index, one should create an instance of Composite.Search.SearchQuery and execute is via an instance of Composite.Search.ISearchProvider interface. An instance can be received either with Dependency Injection (in a startup handler, as an injected CMS function parameter) or by accessing Composite.Search.SearchFacade.SearchProvider property.

public interface ISearchProvider
	Task<SearchResult> SearchAsync(SearchQuery query);

public sealed class SearchQuery
	public SearchQuery(string query, CultureInfo cultureInfo);

	public void AddFieldFacet(string fieldName);
	public void AddFieldFacet(string fieldName, string[] values, string[] notValues);	
	public void FilterByAncestors(params EntityToken[] entityTokens)
	public void FilterByDataTypes(IEnumerable<Type> dataTypes);
	public void FilterByUser(string userName);

	public void ShowOnlyDocumentsWithUrls();

	public string Query { get; }

	public CultureInfo CultureInfo { get; }

	public int SearchResultOffset { get; set; }

	public int MaxDocumentsNumber { get; set; }
	public SearchQueryHighlightSettings HighlightSettings { get; set; }

	public ICollection<KeyValuePair<string, DocumentFieldFacet>> Facets { get; set; }

	public ICollection<SearchQuerySelection> Selection { get; set; }

	public IEnumerable<SearchQuerySortOption> SortOptions { get; set; }

AddFieldFacet(…) - allows returning facet values for a given field.

FilterByAncestors(…) - allows filtering results by ancestor elements in the console element tree. That enables limiting search results to f.e.  documents that are descendants of a certain website page or media library folder.

FilterByUser(…) - allows filtering results by the cms console permissions, so only the tree elements that’s visible for the given user will be shown in the results.

FilterByDataTypes(…) - allows limiting search document to specific data types.

ShowOnlyDocumentsWithUrls() - indicates that only documents that have a URL should be shown

Search result contains a list of found documents (along with matched text fragments) as well as facets information:

public sealed class SearchResult
	public IEnumerable<SearchResultItem> Items { get; set; }

	public int TotalHits { get; set; }

	public IDictionary<string, Facet[]> Facets { get; set; }

public sealed class SearchResultItem
	public SearchDocument Document { get; set; }

	public string LabelHtmlHighlight { get; set; }

	public string[] FullTextHtmlHighlights { get; set; }

public class Facet
	public string Value { get; set; }

	public int HitCount { get; set; }