Add the StringFacet widget
- Last Updated: May 5, 2026
- 1 minute read
- MarkLogic Server
- Documentation
After configuring a constraint in the query options, add the StringFacet widget.
To add the string facet widget:
-
In the search application, open the
App.jsxfile. -
Replace the existing content with this code:
import React from 'react' import './App.css' import { useContext } from "react"; import { MarkLogicContext, SearchBox, ResultsSnippet, StringFacet } from "ml-fasttrack"; function App() { const context = useContext(MarkLogicContext); const handleSearch = (params) => { context.setQtext(params?.q); } const handleFacetClick = (selection) => { context.addStringFacetConstraint(selection) } return ( <div className="App"> <div> <SearchBox onSearch={handleSearch}/> </div> <div style={{display: 'flex', flexDirection: 'row'}}> <div style={{width: '640px'}}> <ResultsSnippet results={context.searchResponse.results} paginationFooter={true} /> </div> <div> <StringFacet title="Status" name="status" data={context.searchResponse?.facets?.status} onSelect={handleFacetClick} /> </div> </div> </div> ) } export default App
Code explanation
The code in Add the StringFacet widget:
-
Imports the StringFacet widget into the application.
-
Renders the StringFacet widget with these props:
-
The
titleprop gives the facet container the title "Status". -
The
nameprop associates the widget with the constraint named "status". -
The
dataprop defines the facet results in the search response using a JSONPath expression. -
The
onSelectprop defines the callback function for handling checkbox clicks.
-
-
The
handleFacetClickcallback receives a selection object as an argument. The selection object is then passed into theaddStringFacetConstraintcontext method. This adds a facet constraint for thestatusproperty to the application context. The constraint is then applied to any search request.