Table of Contents

Query Publisher

Render query results in frontend.

The Query Publisher is a paragraph app which is used to publish a query result to frontend. This is typically used to show a search result of some sort - but may also be used to show lists of users, files, or other things which can be indexed.

When you add the Query Publisher app to a paragraph you'll see a list of settings controlling how the app works: QueryPublisherSettings The steps to implement the app are:

  1. Select a query to publish the results from – you can also enable search statistics
  2. Decide if you want to use facets to filter the result – and decide if you want to show facet options with no results
  3. Set up override default parameters on the query if applicable
  4. Specify how many items per page you want (default is 10)
  5. If relevant enable spell check
  6. Select a template for rendering the search results

The template used to publish a query can have many designs and functionalities, in the following sections we will show simple examples.

Query results

Use the QueryResultViewModel to display the query results and its various information, the results can be products, users, search results etc.:

<!-- Display total count of query result item(s) -->
<div> We have found @Model.TotalCount results </div>

<!-- Looping over each query result -->
@foreach (var result in @Model.Results)
{
    <!-- Looping over each results' key and value pair -->
    @foreach (var kvp in @result)
    {
        @kvp.Key: @kvp.Value
    }
}

Facets

Use the query publisher to show facets and facet options:

<!-- Looping over facet groups -->
@foreach (var facetGroup in Model.FacetGroups)
{
    <span>Facet group: @facetGroup.Name</span>

    <!-- Looping over facets in the facet groups -->
    foreach (var facet in facetGroup.Facets)
    {
        <span>Facet:@facet.Name, field: @facet.Field, query parameter: @facet.QueryParameter, query parameter type: @facet.QueryParameterType</span>

        <!-- Looping over facet options -->
        foreach (var option in facet.FacetOptions)
        {
            <span>Option: @option.Name, label: option.Label, count: @option.Count</span>
        }
    }
}

Parameters

You can also display query parameters:

<!-- Looping over parameters -->
@foreach (var parameter in Model.Parameters)
{
    Name: @parameter.Name, type: @parameter.TypeName, Value: @parameter.Value
}
To top