ResultsCustom
The ResultsCustom widget displays a list of search results from a POST /v1/search
response from the MarkLogic REST API. The widget constructs content for each search result using a callback function that is passed a result as a callback argument.
The ResultsCustom widget is similar to the ResultsConfig widget, which maps search results content to the UI based on a configuration object.
ResultsCustom MarkLogic configuration
To display content from search results documents in the ResultsCustom widget, that content must be extracted and included in the search results. Add an extract-document-data
property in the query options of the application to do this. See Include document extracts in search results for details.
The ResultsCustom widget expects to receive search results in the results
prop. The expected format is the format returned from POST /v1/search in the MarkLogic REST API.
ResultsCustom example rendering
In this example, the ResultsCustom widget displays a custom rendering for each search result. The rendering is constructed by the renderItem
callback.
ResultsCustom example configuration
In this example, the ResultsCustom widget is passed a renderItem
prop that constructs a custom rendering for each search result. The myResultRender
function builds the custom rendering using the URI, first name, last name, job title, and date of birth from each search result:
import { useContext } from "react"; import './App.css'; import { MarkLogicContext, SearchBox, ResultsList, ResultsSnippet } from "ml-fasttrack"; function App() { const context = useContext(MarkLogicContext); const handleSearch = (params) => { context.setQtext(params?.q); } const myResultRender = (result, index, handleClick) => { const extracted = result?.dataItem?.extracted.content[0].envelope; let fullName = extracted.firstName + ' ' + extracted.lastName; return ( <div key={index} onClick={handleClick} style={{padding: '10px 0', cursor: 'pointer'}} > <div>{result?.dataItem?.uri}</div> <div><strong>{fullName}</strong> is a <strong>{extracted.title}</strong> and has a date of birth of <strong>{extracted.dob}.</strong></div> </div> ) } return ( <div className="App"> <div className="SearchBox"> <SearchBox onSearch={handleSearch}/> </div> <ResultsList results={context.searchResponse.results} paginationFooter={true} renderItem={(result, index) => myResultRender(result, index, () => console.log(result))} /> </div> ); } export default App;
ResultsCustom API
Prop |
Type |
Description |
---|---|---|
results |
object[] |
Search results data to display. |
renderItem |
((result: any, index: number) => ReactElement<any, string | JSXElementConstructor<any>>) |
Callback function for rendering each result in the list. Receives a result object and the current index. |
title |
string |
Optional title for the results list. |
titleStyle |
CSSProperties |
CSS styles applied to the results list title. |
className |
string |
Class name applied to the widget. |
headerClassName |
string |
Class name applied to the widget header. |
headerValue |
any |
Content displayed in the widget header. |
footerClassName |
number |
Class name applied to the widget footer. |
footerValue |
any |
Content to display in the widget footer. |
paginationHeader |
boolean |
Indicates whether to display pagination controls in the header. |
paginationFooter |
boolean |
Indicates whether to display pagination controls in the footer. |
pageSizeChanger |
number[] |
Numeric array for displaying a menu in the pagination for configuring the number of items on each page. |
showPreviousNext |
boolean |
Whether to display previous and next buttons in the pagination. |
showInfoSummary |
boolean |
Whether to show a summary in the pagination. |
paginationClassName |
string |
Optional class name for the pagination container. |
paginationSize |
string |
Size of the pagination: Available values are:
|
pagerButtonCount |
number |
The number of page buttons to display in the pagination controls. |