Headless Server Developer Manual / Version 2110
Table Of ContentsGeneric search and dynamic query lists can be extended with custom filter queries, that are applied to the
fq
parameter of the Solr query.
Custom filter queries must be predefined in a configuration class, before they can be used.
Definition of custom filter queries
The definition of a custom filter query consists of a query identifier and a function, that maps the field values to a Solr query.
- Query Identifier: a String value to identify the query
- Mapping Function: a function which takes a List<String> as argument and returns a String, that contains the Solr query in Solr syntax.
For example, a filter query definition could be defined with a query identifier EXCLUDE_IDS and a (here simplified) mapping function:
values -> SearchQueryHelper.negatedQuery(SearchQueryHelper.orQuery(SearchConstants.FIELDS.ID.toString(), values))
There are some help utilities in SearchQueryHelper
to generate the Solr query in Solr syntax.
Alternatively, the Solr query can also be given in direct Solr syntax.
There are already some custom filter query definitions given in Blueprint code.
See HeadlessSearchConfiguration#filterQueryDefinitionMap
for details.
A custom filterQueryDefinition map can be provided by defining a bean with the given type and annotate it with
@Qualifier("filterQueryDefinitionMap")
.
The filterQueryDefinitionMap
is provided for the caeSolrQueryBuilder (generic search) and for
the dynamicContentSolrQueryBuilder (dynamic query lists) so that it is then available to resolve given filter queries.
Apply custom filter queries
A custom filter query can be applied statically for all queries or dynamically for each graphql query.
Static custom filter queries
Static filter queries, that shall be applied to all Solr queries, can be passed to the corresponding
*AdapterFactories
, e.g. SearchServiceAdapterFactory
or QueryListAdapterFactory
.
They are then added to all Solr queries automatically.
Dynamic custom filter queries
Dynamic filter queries, that are applied to a specific GraphQL query, can be added as query argument for generic search or dynamic
query lists. The input format is defined via the built-in type FilterQueryArg
All custom filter queries are applied as fq
(filter query) fragments to the Solr query.
This GraphQL query is an example for fetching a search result using the predefined custom filter queries EXCLUDE_IDS and TITLE_OR.
{ { content { search(query: "*", docTypes: ["CMArticle"], customFilterQueries: [{EXCLUDE_IDS: ["1234", "5678"]}, {TITLE_OR: ["Make your dream come true", "Eveningwear Trends"]}]) { numFound result { id ... on CMArticle { title } } } } } }
This GraphQL query is an example for fetching query list items using the predefined custom filter queries EXCLUDE_IDS.
{ { content { queryList(id: "10") { ... on CMQueryList { id filteredItems(customFilterQueries: {EXCLUDE_IDS: ["1234", "5678"]}) { ... on CMLinkable { id } } } } } } }