Faceted Search QueryBuilder Example

Below you see an example of how the facetedsearchquerybuilder macro is called within the sml_FacetedSearch smartlet.

The mode parameter is used to specify what type of query the querybuilder macro should construct: countquery, searchquery or facetquery.

The sources parameter indicates which sources, as defined within the configuration/query xml, must be used when constructing the specified type of query.

The (optional) searchprofile parameter can be used to specify a (within the configuration xml) pre-configured search profile, e.g. search in titles only.

The configurationxml parameter is a required paramter and should be supplied with the configuration xml (type Xml, so you need to use convert.toxml() on the item's xml field).

The tableorview parameter is used to specify which view must be used to join the results with, so only results from that (e.g. channel) view are displayed. This parameter in itself doesn't do anything, the specified value is just used in resolving the local instance viper this.tableorview(), which should be used in the configuration xml (a.k.a. Query xml).

Through the facetvalues parameter, the macro receives the selected filter settings (if any).

The facetedsearchquerybuilder macro will output the constructed query as result, however the macro also creates an sxml datatable which can be directly used on a subsequent sqlquery macro call as inputdata. The parameter outputbuffername is used to specify a buffer name for this sxml datatable.

Smartsite SXML CopyCode image Copy Code
<se:facetedsearchquerybuilder mode="searchquery" save="search_query" 
  sources="{smartlet.get(sources)}" outputbuffername="sqlparams" 
  searchprofile="{smartlet.get(searchprofile)}">
 <se:parameters>
  <se:parameter name="configurationxml">{buffer.get(xml)}</se:parameter>
  <se:parameter name="tableorview">{channel.view()}</se:parameter>
  <se:parameter name="facetvalues">
   <se:collection inputdata="inputdata" />
  </se:parameter>
 </se:parameters>
</se:facetedsearchquerybuilder>