Optional ReadonlyidThe id of this source.
Must be unique across all search sources used within the same search component.
The id must not change while the source is in use (this value is not reactive). If no id is defined, the search component generates one internally.
ReadonlylabelThe label of this source.
This will be displayed by the user interface when results from this search source are shown.
Performs a search and return a list of search results.
Implementations should return the results ordered by priority (best match first), if possible.
The provided AbortSignal in options.signal is used to cancel outdated requests.
NOTE: If your search source implements custom error handling (i.e. try/catch), it is good practice to forward
abort errors without modification. This will enable the Search widget to hide "errors" due to
cancellation.
For example:
import { isAbortError } from "@open-pioneer/core";
class CustomSearchSource {
async search(input, { signal }) {
try {
// If the search is cancelled by the UI, doRequest
// will throw an AbortError. It might throw other errors
// due to application errors, network problems etc.
const result = await doCustomSearch(input, signal);
// ... do something with result
} catch (e) {
if (isAbortError(e)) {
throw e; // rethrow original error
}
// Possibly use custom error codes or error classes for better error messages
throw new Error("Custom search failed", { cause: e });
}
}
}
An object that allows searching some set of data.
Developers can create classes that implement this interface for different search sources.