Enumeration SearchInterfaceSignal

The SearchInterfaceSignal lists all the signals that may be sent by the SearchInterface.

These signals are emitted by the SearchInterface when a search result is ready.

/** 
* Sample to explain how to make search requests.
*/
import {
InfiniteEvent, SearchInterface, DocumentIdConverterInterface, WorkingSetInterface,
SearchDocumentResultInterface, DocumentIdResultInterface, DocumentIdConverterResultInterface,
SearchInterfaceSignal, DocumentIdConverterInterfaceSignal, DataSessionInterface, MetadataDocumentType
} from 'generated_files/documentation/appinfiniteapi';

// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;
// the Working set for the whole DMU as been set previously
let lCurrentDMUVisibilityCtx : WorkingSetInterface;

// the Working set for the search has been set previously (can be lCurrentDMUVisibilityCtx)
let lSearchVisibilityCtx : WorkingSetInterface;
// the string to search in documents
let lQueryString : string;
// the max number of results
const lMaxDocsToRetrieve : number = 50;

// create a search requester
const lSearch : 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`
const lDocumentIdConverter : 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`
const onSearchReady = (pEvent: InfiniteEvent) : void =>
{
const lSearchInterface: 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() !== undefined) {
return;
}

// get all the `geometric instance ids` of the search request
const lGeometricInstanceIds: 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)
const lSearchResult: 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
const lDocumentId: number = lSearchResult[0].getDocumentId();
const lIsInVisibility : boolean = lSearchResult[0].isInWorkingSet();
const lDocumentType: MetadataDocumentType = lSearchResult[0].getDocumentType();
let lVisibilityCtxToUse : WorkingSetInterface;
if (lIsInVisibility)
{
console.log('retrieve document in visibility : ' + lDocumentId);
// we will try here to find instances only in the 'search' Working set
// 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 Working set
// since this concerns `part instances` outside the 'search' Working set
lVisibilityCtxToUse = lCurrentDMUVisibilityCtx;
}
let lPartDocuments : Array<number> | undefined = undefined;
let lLinkDocuments : Array<number> | undefined = undefined;
let lInstanceDocuments : Array<number> | undefined = undefined;

// find the `part instance ids` and `geometric instance ids` of this document
switch(lDocumentType)
{
case MetadataDocumentType.MDT_PartMetadata:
lPartDocuments = [lDocumentId];
break;
case MetadataDocumentType.MDT_LinkMetadata:
lLinkDocuments = [lDocumentId];
break;
default:
lInstanceDocuments = [lDocumentId];
break;
}
// find the `part instance ids` and `geometric instance ids` of this document
lDocumentIdConverter.convert(lPartDocuments, lLinkDocuments, lInstanceDocuments, lVisibilityCtxToUse);
}
}
};

// When the document `part instances` are found
// we get the relevant `part instance ids` and `geometric instance ids` of the requested document
const onDocumentIdConverterReady = (pEvent: InfiniteEvent) : void =>
{
const lEventDocumentIdConverter: 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() !== undefined) {
return;
}
const lResult: Array<DocumentIdConverterResultInterface> | undefined = lEventDocumentIdConverter.getConversionResult();
if (lResult && lResult.length === 1)
{
const lDocumentIdConverterInstances: Array<DocumentIdResultInterface> = lResult[0].getConvertedInstances();
const lPartInstanceIds: Uint32Array = new Uint32Array(lDocumentIdConverterInstances.length);

for (let i = 0; i < lDocumentIdConverterInstances.length; i += 1) {
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 (fifth parameter : lCurrentDMUVisibilityCtx), but will get a hint of the
// documents inside lSearchVisibilityCtx
// imit the results to lMaxDocsToRetrieve documents maximum
lSearch.search(lQueryString, lSearchVisibilityCtx, lMaxDocsToRetrieve, ['PartNumber'], lCurrentDMUVisibilityCtx);

Please refer to Search for more information about search requests.
Events

Enumeration Members

Enumeration Members

SearchCancelled: "cancelled"

Signal sent by the SearchInterface when the SearchInterface has been cancelled.

Such an event is fired if the SearchInterface was searching and SearchInterface.cancelSearch is called. The SearchReady signal will be triggered shortly after.

No attachment for events of this type.

SearchReady: "ready"

Signal sent by the SearchInterface when SearchInterface.search is ready, i.e. SearchInterface.getSearchDocuments, SearchInterface.getGeometricInstanceIds and SearchInterface.hasOtherResults can be called.

Such a signal does not tell if the call was successful or not but that the result is ready to be fetched.

Warning, the SearchReady signal is sent later when SearchInterface.cancelSearch is called and the SearchInterface is searching.

The attachment is a string telling the request id of the call to SearchInterface.search (SearchInterface.getLastRequestId).