An highlight result tells about the context of the result of a search query.
The highlight result is included inside a SearchDocumentResultInterface.
The highlight result is basically a map of :
An attribute name (or an empty string for a full text search).
A list of strings that contain the query string of the search.
/** * Sample to explain how to make search requests. */ import { InfiniteEvent, SearchInterface, DocumentIdConverterInterface, VisibilityContextInterface, SearchDocumentResultInterface, DocumentIdResultInterface, DocumentIdConverterResultInterface, SearchInterfaceSignal, DocumentIdConverterInterfaceSignal, DataSessionInterface } from'generated/documentation/appinfiniteapi';
// the DataSessionInterface has been created previously and is connected letlDataSession : DataSessionInterface; // the filtering context for the whole DMU as been set previously letlCurrentDMUVisibilityCtx : VisibilityContextInterface;
// the filtering context for the search has been set previously (can be lCurrentDMUVisibilityCtx) letlSearchVisibilityCtx : VisibilityContextInterface; // the string to search in documents letlQueryString : string; // the max number of results constlMaxDocsToRetrieve : number = 50;
// create a search requester constlSearch : SearchInterface = lDataSession.createSearch();
// to get actual results from a search request : // the search requester gets result in the form of documents, // in a second step, the user may enquire the server to know the // relevant `part instance ids` // the DocumentIdConverterInterface is there to make the conversion between // a document id and the actual `part instances` constlDocumentIdConverter : DocumentIdConverterInterface = lDataSession.createDocumentIdConverter();
// When the search is ready, we check for errors // we may find all the `geometric instance ids` in the search result // we get the first found document // and find the relevant `part instance ids` and `geometric instance ids` constonSearchReady = (pEvent: InfiniteEvent) : void=> { constlSearchInterface: SearchInterface = <SearchInterface>(pEvent.emitter); // make sure the search in no more running if (lSearchInterface.isRunning()) { console.assert(false, 'this should not happen'); return; } // and make sure no error if (lSearchInterface.getLastError().length > 0) { return; }
// get all the `geometric instance ids` of the search request constlGeometricInstanceIds: Uint32Array | undefined = lSearchInterface.getGeometricInstanceIds(); if (lGeometricInstanceIds !== undefined) { console.log('all the geometric instances concerned by the search:' + lGeometricInstanceIds.length); }
// and get the documents (content is filtered by the last parameter of SearchInterface.search) constlSearchResult: Array<SearchDocumentResultInterface> | undefined = lSearchInterface.getSearchDocuments(); if (lSearchResult) { console.log('Search finished: ' + lSearchResult.length + ' result(s)'); // do we have all documents, or are there more that were not included due to the search results capped to lMaxDocsToRetrieve ? if (lSearchInterface.hasOtherResults()) { // some GUI code there perhaps ? console.log('Search was capped to ' + lMaxDocsToRetrieve); } if (lSearchResult.length > 0) { // get the `part instance ids` of the first document constlDocumentId: number = lSearchResult[0].getDocumentId(); constlIsInVisibility : boolean = lSearchResult[0].isInVisibilityCtx(); letlVisibilityCtxToUse : VisibilityContextInterface; if (lIsInVisibility) { console.log('retrieve document in visibility : ' + lDocumentId); // we will try here to find instances only in the search filtering context // but depending on your needs, you may use lCurrentDMUVisibilityCtx to extend the // result to the `part instances` of the whole DMU, it is up to you // or make 2 requests, one in the search ctx, the other outside, or .... lVisibilityCtxToUse = lSearchVisibilityCtx; } else { // this case cannot happen if the third parameter to search is true console.log('retrieve document outside visibility : ' + lDocumentId); // in order to get results, we will make the conversion in the whole DMU filtering context // since this concerns `part instances` outside the search filtering context lVisibilityCtxToUse = lCurrentDMUVisibilityCtx; } // find the `part instance ids` and `geometric instance ids` of this document lDocumentIdConverter.convert(lDocumentId, lVisibilityCtxToUse); } } };
// When the document `part instances` are found // we get the relevant `part instance ids` and `geometric instance ids` of the requested document constonDocumentIdConverterReady = (pEvent: InfiniteEvent) : void=> { constlEventDocumentIdConverter: DocumentIdConverterInterface = <DocumentIdConverterInterface>(pEvent.emitter); // make sure the search in no more running if (lEventDocumentIdConverter.isRunning()) { console.assert(false, 'this should not happen'); return; } if (lEventDocumentIdConverter.getLastError().length > 0) { return; } constlResult: DocumentIdConverterResultInterface | undefined = lEventDocumentIdConverter.getConversionResult(); if (lResult) { constlDocumentIdConverterInstances: Array<DocumentIdResultInterface> = lResult.getConvertedInstances(); constlPartInstanceIds: Uint32Array = newUint32Array(lDocumentIdConverterInstances.length);
for (leti = 0; i < lDocumentIdConverterInstances.length; ++i) { lPartInstanceIds[i] = lDocumentIdConverterInstances[i].getPartInstanceId(); } console.log('documents converted :'); console.log('Convert part instances to geometric instance ids: ' + JSON.stringify(lPartInstanceIds)); } };
// what to do when we get the results ? lDocumentIdConverter.addEventListener(DocumentIdConverterInterfaceSignal.DocumentIdConverterReady, onDocumentIdConverterReady); lSearch.addEventListener(SearchInterfaceSignal.SearchReady, onSearchReady);
// make a search request, and only retrieve the "PartNumber" metadata of the result documents // we will get all the documents of the DMU (third parameter : false), but will get a hint of the // documents inside lSearchVisibilityCtx // imit the results to lMaxDocsToRetrieve documents maximum lSearch.search(lQueryString, lSearchVisibilityCtx, false, lMaxDocsToRetrieve, ['PartNumber']);
or asynchronously :
/** * Sample to explain how to make asynchronous search requests. */ import { SearchInterface, DocumentIdConverterInterface, VisibilityContextInterface, SearchDocumentResultInterface, DocumentIdResultInterface, AsyncSearchResult, AsyncResultReason, AsyncSearchResultContent, AsyncDocumentIdConverterResultInterfaceResult, DataSessionInterface, } from'generated/documentation/appinfiniteapi';
// the DataSessionInterface has been created previously and is connected letlDataSession : DataSessionInterface; // the filtering context for the whole DMU as been set previously letlCurrentDMUVisibilityCtx : VisibilityContextInterface;
// the filtering context for the search has been set previously (can be lCurrentDMUVisibilityCtx) letlSearchVisibilityCtx : VisibilityContextInterface; // the string to search in documents letlQueryString : string; // the max number of results constlMaxDocsToRetrieve : number = 50;
// create a search requester constlSearch : SearchInterface = lDataSession.createSearch();
// to get actual results from a search request : // the search requester gets result in the form of documents, // in a second step, the user may enquire the server to know the // relevant `part instance ids` // the DocumentIdConverterInterface is there to make the conversion between // a document id and the actual `part instances` constlDocumentIdConverter : DocumentIdConverterInterface = lDataSession.createDocumentIdConverter();
consttriggerSearchRequest = async () : Promise<any> => { // make a search request, and only retrieve the "PartNumber" metadata of the result documents // we will get all the documents of the DMU (third parameter : false), but will get a hint of the // documents inside lSearchVisibilityCtx // limit the results to lMaxDocsToRetrieve documents maximum constlResult : AsyncSearchResult = awaitlSearch.asyncSearch(lQueryString, lSearchVisibilityCtx, false, lMaxDocsToRetrieve, ['PartNumber']);
if (lResult.reason !== AsyncResultReason.ARR_Success || lResult.value === undefined) { console.assert(false, 'this should not happen'); return; } // When the search is ready, we check for errors // we may find all the `geometric instance ids` in the search result // we get the first found document // and find the relevant `part instance ids` and `geometric instance ids`
constlSearchContent : AsyncSearchResultContent = lResult.value; // get all the `geometric instance ids` of the search request constlGeometricInstanceIds: Uint32Array | undefined = lSearchContent.geometricInstanceIds; if (lGeometricInstanceIds !== undefined) { console.log('all the geometric instances concerned by the search:' + lGeometricInstanceIds.length); }
// and get the documents (content is filtered by the last parameter of SearchInterface.search) constlSearchResult: Array<SearchDocumentResultInterface> | undefined = lSearchContent.searchDocuments; if (!lSearchResult) { console.assert(false, 'this should not happen'); return; } console.log('Search finished: ' + lSearchResult.length + ' result(s)'); // do we have all documents, or are there more that were not included due to the search results capped to lMaxDocsToRetrieve ? if (lSearchContent.hasOtherResults) { // some GUI code there perhaps ? console.log('Search was capped to ' + lMaxDocsToRetrieve); } if (lSearchResult.length <= 0) { console.log('no document found'); return; } // get the `part instance ids` of the first document constlDocumentId: number = lSearchResult[0].getDocumentId(); constlIsInVisibility : boolean = lSearchResult[0].isInVisibilityCtx(); letlVisibilityCtxToUse : VisibilityContextInterface; if (lIsInVisibility) { console.log('retrieve document in visibility : ' + lDocumentId); // we will try here to find instances only in the search filtering context // but depending on your needs, you may use lCurrentDMUVisibilityCtx to extend the // result to the `part instances` of the whole DMU, it is up to you // or make 2 requests, one in the search ctx, the other outside, or .... lVisibilityCtxToUse = lSearchVisibilityCtx; } else { // this case cannot happen if the third parameter to search is true console.log('retrieve document outside visibility : ' + lDocumentId); // in order to get results, we will make the conversion in the whole DMU filtering context // since this concerns `part instances` outside the search filtering context lVisibilityCtxToUse = lCurrentDMUVisibilityCtx; } // find the `part instance ids` and `geometric instance ids` of this document constlConversion : AsyncDocumentIdConverterResultInterfaceResult = awaitlDocumentIdConverter.asyncConvert(lDocumentId, lVisibilityCtxToUse);
// When the document `part instances` are found // we get the relevant `part instance ids` and `geometric instance ids` of the requested document if (lConversion.reason !== AsyncResultReason.ARR_Success || lConversion.value === undefined) { console.assert(false, 'this should not happen'); return; } constlDocumentIdConverterInstances: Array<DocumentIdResultInterface> = lConversion.value.getConvertedInstances(); constlPartInstanceIds: Uint32Array = newUint32Array(lDocumentIdConverterInstances.length);
for (leti = 0; i < lDocumentIdConverterInstances.length; ++i) { lPartInstanceIds[i] = lDocumentIdConverterInstances[i].getPartInstanceId(); } console.log('documents converted :'); console.log('Convert part instances to geometric instance ids: ' + JSON.stringify(lPartInstanceIds)); }
triggerSearchRequest();
Please make sure the destination browser supports promises before using async calls.
An highlight result tells about the context of the result of a search query.
The highlight result is included inside a SearchDocumentResultInterface. The highlight result is basically a map of :
or asynchronously :
Please make sure the destination browser supports promises before using async calls.
See