-
Notifications
You must be signed in to change notification settings - Fork 16
Functions:searchCollection
bettybas edited this page Jan 30, 2024
·
4 revisions
The searchCollection function simplifies the process of searching within a collection of documents. It takes various parameters including the search query, the collection of documents to search through, the specific fields to consider in the search, and whether to chunk (split) large documents. This makes it versatile for different use cases.
const { result } = await searchCollection({
query,
documents: collection?.data ?? [],
fields: [propertyName],
prefilterThreshold: 0.0,
chunk,
});
-
query
: This is the parameter that defines what the search is looking for in the collection. -
documents
: The collection of documents to search in. -
fields
: The specific property name to focus the search on. -
chunk
: Whether to split a document into smaller chunks. This will improve the relevance of results.
async function performSearch() {
const collection = {
data: [
{ id: 0, title: "Document 1", content: "This is the first document." },
{ id: 1, title: "Document 2", content: "This is the second document." }
]
};
const searchResults = await searchCollection({
query: "first",
documents: collection.data,
fields: ["content"],
prefilterThreshold: 0.0,
chunk: false
});
console.log(searchResults.result);
}
- Getting started
- Page Builder Components
- Action Functions
- [deprecated] CustomFunctions