Quickview (Search Engine) (Deprecated)
Quickview (Search Engine) (Deprecated)
|
|
Headless v1 has been deprecated. We recommend using the latest version of the Coveo Headless library. |
Example implementation
quickview.fn.tsx
import {buildQuickview, Result} from '@coveo/headless';
import {useEffect, useState, useContext, FunctionComponent} from 'react';
import {AppContext} from '../../context/engine';
interface QuickviewProps {
result: Result;
}
export const Quickview: FunctionComponent<QuickviewProps> = (props) => {
const {result} = props;
const {engine} = useContext(AppContext);
const controller = buildQuickview(engine!, {options: {result}});
const [state, setState] = useState(controller.state);
const [isModalOpen, toggleModal] = useState(false);
useEffect(() => controller.subscribe(() => setState(controller.state)), []);
const openModal = () => {
controller.fetchResultContent();
toggleModal(true);
};
const closeModal = () => toggleModal(false);
if (!state.resultHasPreview) {
return null;
}
if (isModalOpen) {
return (
<div>
<button onClick={() => closeModal()}>X</button>
<iframe srcDoc={state.content}></iframe>
</div>
);
}
return <button onClick={() => openModal()}>view</button>;
};
// usage
/**
* ```tsx
* <Quickview result={result} />;
* ```
*/
Methods
fetchResultContent
Retrieves the preview content for the configured result. If options.onlyContentURL is true this will update the contentURL state property rather than content.
subscribe
Adds a callback that’s invoked on state change.
Parameters
-
listener:
() => voidA callback that’s invoked on state change.
Returns Unsubscribe: A function to remove the listener.
Attributes
state
The state for the Quickview controller.
Properties
-
content:
stringThe result preview HTML content.
-
isLoading:
booleantrueif content is being fetched, andfalseotherwise. -
resultHasPreview:
booleantrueif the configured result has a preview, andfalseotherwise. -
contentURL?:
stringThe
srcpath to use if rendering the quickview in an iframe.
Initialize
buildQuickview
Creates a Quickview controller instance.
Parameters
-
engine:
SearchEngineThe headless engine.
-
props:
QuickviewPropsThe configurable
Quickviewproperties.
Returns Quickview
QuickviewProps
The configurable Quickview properties.
Properties
-
options:
QuickviewOptionsThe options for the
Quickviewcontroller.
QuickviewOptions
The options for the Quickview controller.
Properties
-
result:
ResultThe result to retrieve a quickview for.
-
maximumPreviewSize?:
numberThe maximum preview size to retrieve, in bytes. By default, the full preview is retrieved.
-
onlyContentURL?:
booleanWhether to only update the
contentURLattribute when usingfetchResultContentrather than updatingcontent. Use this if you’re using an iframe withstate.contentURLas the source url.
Related types
HighlightKeyword
Properties
-
length:
numberThe length of the offset.
-
offset:
numberThe 0 based offset inside the string where the highlight should start.
Raw
Properties
-
[key: string]:
unknownCustom keys that depend on the documents in the index.
Result
Properties
-
absentTerms:
string[]The basic query expression terms which this query result item does not match. Note: This property is populated by terms from the query pipeline-processed q value (not from the original q value).
-
clickUri:
stringThe hyperlinkable item URI. Notes: Use the clickUri value when you want to create hyperlinks to the item, rather than the uri or printableUri value.
-
excerpt:
stringThe contextual excerpt generated for the item (see the excerptLength query parameter).
-
excerptHighlights:
HighlightKeyword[]The length and offset of each word to highlight in the item excerpt string.
-
firstSentences:
stringThe first sentences retrieved from the item (see the retrieveFirstSentences query parameter).
-
firstSentencesHighlights:
HighlightKeyword[]The length and offset of each word to highlight in the item firstSentences string.
-
flags:
stringThe flags that are set on the item by the index. Distinct values are separated by semicolons.
-
hasHtmlVersion:
booleanWhether the index contains an HTML version of this item.
-
isRecommendation:
booleanWhether the item score was boosted as a Coveo ML recommendation.
-
isTopResult:
booleanWhether the item score was boosted by a featured result rule in the query pipeline.
-
percentScore:
numberThe item ranking score expressed as a percentage (see the sortCriteria and rankingFunctions query parameters).
-
printableUri:
stringThe human readable item URI. Note: Avoid using the printableUri value to create hyperlinks to the item. Use the clickUri value instead.
-
printableUriHighlights:
HighlightKeyword[]The length and offset of each word to highlight in the item printableUri string.
-
rankingInfo:
string | nullThe raw debug information generated by the index to detail how the item was ranked. This property is null unless the debug query parameter is set to true.
-
raw:
RawThe values of the fields which were retrieved for this item (see the fieldsToInclude and fieldsToExclude query parameters).
-
score:
numberThe total ranking score computed for the item (see the sortCriteria and rankingFunctions query parameters).
-
summary:
nullThe item summary (see the summaryLength query parameter).
-
summaryHighlights:
HighlightKeyword[]The length and offset of each word to highlight in the item summary string.
-
title:
stringContains the title of the item.
-
titleHighlights:
HighlightKeyword[]The length and offset of each word to highlight in the item title string.
-
uniqueId:
stringThe unique item identifier. You should consider the uniqueId value as an opaque string.
-
uri:
stringThe item URI. Notes: Avoid using the uri value to create hyperlinks to the item. Use the clickUri value instead.
-
rankingModifier?:
stringIf applicable, represents the type of ranking modification that was applied to this result.
Unsubscribe
Call signatures
-
(): void