Interface SearchInterface

The SearchInterface interface is used to search content in the DMU.

Please see Search.

The SearchInterface interfaces are created through the createSearch method.

The list of signals the SearchInterface may trigger is available in the SearchInterfaceSignal enumeration.

The search request is triggered through the search method. The result is not available right away, but the event SearchReady is triggered when the result of the SearchInterface is available. The result is available through the getSearchDocuments getGeometricInstanceIds and hasOtherResults functions.
As said in Search, the search result consists in a list of metadata documents that match the query (an array of SearchDocumentResultInterface from getSearchDocuments), it may be interesting to find the part instances, and the geometric instances that are linked to this search query. The DocumentIdConverterInterface fulfill this requirement.
The search result also provides right away the full list of geometric instance ids that are involved in the search result, regardless of the given cap included (the FULL list of all geometric instance ids that match the query are ALWAYS provided) with getGeometricInstanceIds.

Warning : there may be cases when the getSearchDocuments, getGeometricInstanceIds are not available such as when the SearchInterface is fetching data, i.e. when isRunning returns true, or when the SearchInterface has been cancelled, i.e. when isCancelled returns true.

A SearchInterface may be interrupted (cancelled) when the SearchInterface is running and cancelSearch is called. In such cases, the SearchCancelled signal is fired, and shortly after, SearchReady signal is fired, but getSearchDocuments and getGeometricInstanceIds will return undefined. Just call search with another (or the same) query to trigger a new search request.

If you call multiple times search before receiving the SearchReady, only one SearchReady will be sent with the content of the last call to search.

The syntax of the search is explained in the 3djuump infinite literal and search query language.

The search query must be provided with a maximum number of hits to help reduce server usage and bandwidth. If the search result is capped to this value then hasOtherResults returns true.

The search query is always limited to a filtering context (see Filtering Context) from the VisibilityContextInterface.

The search results may be filtered to include only a subset of the metadata inside the matching document, provided the search function is called with the list of metadata names to return.

/** 
* 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
let lDataSession : DataSessionInterface;
// the filtering context for the whole DMU as been set previously
let lCurrentDMUVisibilityCtx : VisibilityContextInterface;

// the filtering context for the search has been set previously (can be lCurrentDMUVisibilityCtx)
let lSearchVisibilityCtx : VisibilityContextInterface;
// 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().length > 0) {
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].isInVisibilityCtx();
let lVisibilityCtxToUse : 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
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().length > 0) {
return;
}
const lResult: DocumentIdConverterResultInterface | undefined = lEventDocumentIdConverter.getConversionResult();
if (lResult)
{
const lDocumentIdConverterInstances: Array<DocumentIdResultInterface> = lResult.getConvertedInstances();
const lPartInstanceIds: Uint32Array = new Uint32Array(lDocumentIdConverterInstances.length);

for (let i = 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
let lDataSession : DataSessionInterface;
// the filtering context for the whole DMU as been set previously
let lCurrentDMUVisibilityCtx : VisibilityContextInterface;

// the filtering context for the search has been set previously (can be lCurrentDMUVisibilityCtx)
let lSearchVisibilityCtx : VisibilityContextInterface;
// 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();

const triggerSearchRequest = 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
const lResult : AsyncSearchResult = await lSearch.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`

const lSearchContent : AsyncSearchResultContent = lResult.value;
// get all the `geometric instance ids` of the search request
const lGeometricInstanceIds: 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)
const lSearchResult: 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
const lDocumentId: number = lSearchResult[0].getDocumentId();
const lIsInVisibility : boolean = lSearchResult[0].isInVisibilityCtx();
let lVisibilityCtxToUse : 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
const lConversion : AsyncDocumentIdConverterResultInterfaceResult = await lDocumentIdConverter.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;
}
const lDocumentIdConverterInstances: Array<DocumentIdResultInterface> = lConversion.value.getConvertedInstances();
const lPartInstanceIds: Uint32Array = new Uint32Array(lDocumentIdConverterInstances.length);

for (let i = 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.
Data Retrievers

See

Hierarchy

Methods

  • Adds a listener to an event type.

    When an event of the type pType fires, the callback pListener will be called. This function returns a unique string id that may be used in removeEventListenerById to allow simple listener removal. It is possible to add an object that will be included in the callback to avoid creating too many closures.

    Returns

    The id of the inserted callback (actually an UUID).

    Parameters

    • pType: string
      in
      The type of the event pListener will be called upon.
    • pListener: tListenerCallback
      in
      The listener function that fires when the given event type occurs.
    • pObject: undefined | Object
      in
      The optional object the callback will be called with when the given event fires.

    Returns string

  • Adds a listener to an event type.

    When an event of the type pType fires, the callback pListener will be called. This function returns a unique string id that may be used in removeEventListenerById to allow simple listener removal.

    Returns

    The id of the inserted callback (actually an UUID).

    Parameters

    • pType: string
      in
      The type of the event pListener will be called upon.
    • pListener: tListenerCallback
      in
      The listener function that fires when the given event type occurs.

    Returns string

  • Asynchronously triggers a search query.

    The query is written in the 3djuump infinite literal and search query language.

    The user must :

    • Set a valid VisibilityContextInterface to limit the search on some documents (it may be the whole DMU with only an unconfigured ConfContextInterface).
    • Choose to discard or not documents matching the query but not matching the filtering context (if not, document is present in the result but isInVisibilityCtx returns false).
    • Limit the search to only pMaxDocumentResult results.
    • Filter the result of the search with pMetadataNamesFilter.

    The pMetadataNamesFilter parameter defines the fields to retrieve from the metadata documents that match the query. The parameter must be a an array of string containing the fields that must be returned. An empty array means the full document will all the metadata will be returned in the resulting SearchDocumentResultInterface. For example : if pMetadataNamesFilter is set to ["Name","srcfile"], the result will return the content of the field Name and the field srcfile from the metadata document.

    Returns a promise.

    Please note that in case of multiple promises running at the same time on the same SearchInterface, the first promises will be signalled as cancelled, the last as ok, but all calls to getSearchDocuments after awaiting will return the same value.

    If pVisibilityContext is modified during the execution, then the call is cancelled (see cancelSearch).

    Returns

    A promise. The promise is resolved with the reason (success, cancelled, disposed, bad input). In case of success, the promise contains the search result.

    Parameters

    • pQuery: string
      in
      The search query.
    • pVisibilityContext: VisibilityContextInterface
      in
      The filtering context.
    • pLimitResultsToVisibilityCtx: boolean
      in
      If true limits the search query on the documents included in the filtering context.
    • pMaxDocumentResult: number
      in
      The maximum number of resulting documents.
    • pMetadataNamesFilter: string[]
      in
      The list of metadata names to include in the resulting [SearchDocumentResultInterface](SearchDocumentResultInterface.html).

    Returns Promise<AsyncSearchResult>

  • Cancels the computation of the search query (if any).

    A SearchCancelled signal is emitted if the SearchInterface is retrieving data.

    Returns

    true if the SearchInterface was running, else false.

    See

    SearchCancelled

    Returns boolean

  • Gets the list of all geometric instance ids which matched the search query from the last call of search.

    An Uint32Array is returned if the SearchInterface has finished computing. Use addEventListener on the event SearchReady to know when the SearchInterface is ready. This array contains all the matching geometric instance ids regardless of the maximum number of hits set in search.

    DO NOT modify this data in place, this results in undefined behavior.

    Returns

    const
    The list of matching geometric instance ids, or undefined if the SearchInterface is searching or if the SearchInterface is in error or cancelled.

    See

    Returns undefined | Uint32Array

  • Gets the last error message returned by the search request.

    Returns

    The last error message.

    Returns string

  • Each call to search is assigned a request id.

    This call tels the id of the last call to search.

    Returns

    The id of the last call to search.

    Returns string

  • Tells if the EventDispatcher has such a callback registered for the given event type.

    Returns

    true if such a listener is installed for the given type of event.

    Parameters

    • pType: string
      in
      The type of the event to test.
    • pListener: tListenerCallback
      in
      The listener function that gets tested.

    Returns boolean

  • Tells if the search result would have returned more results if the search would have been limited to a superior maximum number of hits.

    Returns true if the last search query contained more results than the maximum cap requested by the search and if the SearchInterface has finished computing. Use addEventListener on the event SearchReady to know when the SearchInterface is ready.

    Returns

    true if the search result count exceeded the max document result cap and if the SearchInterface is not running.

    See

    Returns boolean

  • Tells if a search request has been cancelled.

    This is generally the case after calling cancelSearch when the SearchInterface is preforming a search.

    Returns

    true if a search request is cancelled.

    Returns boolean

  • Tells if a search request is running.

    This is the case after calling search.

    Returns

    true if a search request is running.

    Returns boolean

  • Removes a listener from an event type.

    If no such listener is found, then the function returns false and does nothing. You must use the exact parameters that were used in addEventListener to actually remove the listener.

    Returns

    true if the callback was removed else false.

    Parameters

    • pType: string
      in
      The type of the listener that gets removed.
    • pListener: tListenerCallback

      The listener function that gets removed.

    • pObject: undefined | Object

      The listener object that was used when addEventListener was called.

    Returns boolean

  • Removes a listener from an event type.

    If no such listener is found, then the function returns false and does nothing. You must use the exact parameters that were used in addEventListener to actually remove the listener.

    Returns

    true if the callback was removed else false.

    Parameters

    • pType: string
      in
      The type of the listener that gets removed.
    • pListener: tListenerCallback

      The listener function that gets removed.

    Returns boolean

  • Removes a listener by its id.

    If no such listener is found, then the function returns false and does nothing. You must use the return value of addEventListener to actually remove the listener.

    Returns

    true if the callback was removed else false.

    Parameters

    • pId: string
      in
      The id returned by the call to [addEventListener](SearchInterface.html#addEventListener) that you want to remove.

    Returns boolean

  • Triggers a search query.

    The query is written in the 3djuump infinite literal and search query language.

    The user must :

    • Set a valid VisibilityContextInterface to limit the search on some documents (it may be the whole DMU with only an unconfigured ConfContextInterface).
    • Choose to discard or not documents matching the query but not matching the filtering context (if not, document is present in the result but isInVisibilityCtx returns false).
    • Limit the search to only pMaxDocumentResult results.
    • Filter the result of the search with pMetadataNamesFilter.

    The pMetadataNamesFilter parameter defines the fields to retrieve from the metadata documents that match the query. The parameter must be a an array of string containing the fields that must be returned. An empty array means the full document will all the metadata will be returned in the resulting SearchDocumentResultInterface. For example : if pMetadataNamesFilter is set to ["Name", "srcfile"], the result will return the content of the field Name and the field srcfile from the metadata document.

    An event SearchReady is fired when the search is finished, then getLastError() tells if the search was correctly performed.

    Returns true if the search query is started (and therefore the search query is valid). If not, just call getLastError to get the reason why the procedure failed.

    If pVisibilityContext is modified during the execution, then the call is cancelled (see cancelSearch).

    Returns

    true if the search query (pQuery) is valid, in the case the SearchInterface has begun running.

    Parameters

    • pQuery: string
      in
      The search query.
    • pVisibilityContext: VisibilityContextInterface
      in
      The filtering context.
    • pLimitResultsToVisibilityCtx: boolean
      in
      If `true` limits the search query on the documents included in the filtering context.
    • pMaxDocumentResult: number
      in
      The maximum number of resulting documents.
    • pMetadataNamesFilter: string[]
      in
      The list of metadata names to include in the resulting [SearchDocumentResultInterface](SearchDocumentResultInterface.html).

    Returns boolean