IO Connect Search API
Apps can perform searches and provide results for others' searches.
For example, let's say an app provides Seinfeld quotes, and wants to make those quotes available to any other app. The Seinfeld app could register itself as a search provider with this:
const provider = await glue.search.registerProvider({
name: "Seinfeld-Quotes"
});
provider.onQuery(({search, sendResults, done}) => {
const textOfQuote = doStuffInternally(search);
sendResults({
type: {
name: "tv-quote",
displayName: "Seinfeld Quotes"
},
id: "quote-123",
description: textOfQuote
});
done();
})
Now, let's say an app is interested to see if there are any Seinfeld quotes with the word "architect". It would use the following function:
const query = await glue.search.query({search: "architect"});
query.onResults((result) => {
})
Checklists
If you're writing a custom search provider, here are things to make sure you implement:
Basics
Other considerations:
If you're querying a search providerm here are things to make sure you implement:
Other considerations:
API
glue.search has the following methods:
- getDebounceMS
- listProviders
- listTypes
- query
- registerProvider
- setDebounceMS
- version
registerProvider
Config options for .registerProvider()
are:
name
(required)
types
(optional but recommended). If you register a custom type, it will appear in the .listTypes
method.
const provider = await glue.search.registerProvider({name: "test"});
const provider = await glue.search.registerProvider({
name: "test",
types: [
{name: "application"}
]
});
registerProvider
returns a promise that resolves to a Provider
object. This has the following available methods:
onQuery
- callback when search queries are executed
onQueryCancel
- callback when an app cancels its search query
unregister
- an unregistration method.
:::tip
Search providers are automatically unregistered when windows are closed. Unregistration is a good cleanup action, but may not be required.
:::
The onQuery
callback provides a ProviderQuery
object, with the following properties:
- id - referenced when cancelling the query
- search - the text being searched for
- providers - the providers the querier is interested in
- types - the SearchTypes the querier is interested in
- providerLimits.maxResults - the maximum number of results the querier wants to receive from each provider
- providerLimits.maxResultsPerType - the maximum number of results PER TYPE the querier wants to recevie from each provider
- sendResult - callback for sending an individual result. (The querier receives this with the
query.onResults()
callback)
- error - callback if there's an error (The querier receives this with the
query.onError()
callback)
- done - callback once all results have been sent (The querier receives this with the
query.done()
callback)
When sending a result, you supply a QueryResult
object. The properties of that object are:
- type (required) - a
SearchType
(eg: {name: "application"}
)
- id
- displayName
- description
- iconURL
- metadata
- action - metadata information about a method you'd want to invoke
- secondaryActions - more actions
query
You create a query object with the query()
method:
const query = await glue.search.query({search: "My search query"});
The query
method takes the following properties:
search
(required) (string) - what you're searching for
providers
(ProviderData[]
) - providers you want to limit your search to
types
(SearchType[]
) - the types of results you want to limit your search to
providerLimits.maxResults
(number) - the maximum number of results the querier wants to receive from each provider
providerLimits.maxResultsPerType
(number) - the maximum number of results PER TYPE the querier wants to recevie from each provider
The query object you receive has the following methods:
cancel()
- Cancels the query. (See provider's onQueryCancel()
)
onResults()
- Callback to receive results (See provider's query handling for sendResult()
)
onCompleted()
- Callback when provider is done (See provider's query handling for done()
)
onError()
- Callback when provider has an error (See provider's query handling for error()
)
listProviders
await glue.search.listProviders();
listTypes
You can see what search types are available. This is especially useful if you are relying on a custom search type from another app, and want to confirm that that app has already been registered.
await glue.search.listTypes();
getDebounceMS, setDebounceMS
Default debounce: 0ms
Queries can be debounced. If you plan on querying based on individual keystrokes or mouse movements, you can potentially generate an unnecessarily large message flurry. Debouncing the queries will reduce search query traffic.
Here are examples of getting/setting the debounce time:
glue.search.getDebounceMS();
glue.search.setDebounceMS(20);
Actions
TBD
Developer notes
/* eslint-disable @typescript-eslint/no-explicit-any */
// package name: @interopio/search-api -> adds the Search API
// @interopio/browser-platform -> can use the package to register as a provider or use as a client, by default register as a provider for applications, workspaces, layouts and optionally actions
// @interopio/browser -> can use the package to register as a provider or use as a client
// GD3 -> by default register as a provider for applications, workspaces, layouts and optionally actions
// Foundation: Interop and Shared Context
// lib registers: lazily two methods
// lib uses: shared context to providers state management
// method used when registered as provider to accept queries
// category = display name for type