@orama/orama
Version:
A complete search engine and RAG pipeline in your browser, server, or edge network with support for full-text, vector, and hybrid search in less than 2kb.
106 lines • 2.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.insertPin = insertPin;
exports.updatePin = updatePin;
exports.deletePin = deletePin;
exports.getPin = getPin;
exports.getAllPins = getAllPins;
/**
* Insert a new pinning rule into the database.
* Pinning rules allow you to promote specific documents to specific positions in search results
* based on conditional matching of the search term.
*
* @example
* ```typescript
* import { create, insert, insertPin } from '@orama/orama'
*
* const db = await create({
* schema: {
* title: 'string',
* description: 'string'
* }
* })
*
* await insert(db, { id: '1', title: 'Product A' })
* await insert(db, { id: '2', title: 'Product B' })
*
* // When searching for "featured", pin Product B to position 0
* insertPin(db, {
* id: 'featured-products',
* conditions: [
* { anchoring: 'contains', pattern: 'featured' }
* ],
* consequence: {
* promote: [
* { doc_id: '2', position: 0 }
* ]
* }
* })
* ```
*/
function insertPin(orama, rule) {
;
orama.pinning.addRule(orama.data.pinning, rule);
}
/**
* Update an existing pinning rule in the database.
* If the rule does not exist, an error will be thrown.
*
* @example
* ```typescript
* import { updatePin } from '@orama/orama'
*
* // Update the rule to pin to a different position
* updatePin(db, {
* id: 'featured-products',
* conditions: [
* { anchoring: 'contains', pattern: 'featured' }
* ],
* consequence: {
* promote: [
* { doc_id: '3', position: 0 } // Changed doc_id
* ]
* }
* })
* ```
*/
function updatePin(orama, rule) {
;
orama.pinning.updateRule(orama.data.pinning, rule);
}
/**
* Remove a pinning rule from the database by its ID.
*
* @example
* ```typescript
* deletePin(db, 'featured-products')
* ```
*/
function deletePin(orama, ruleId) {
return orama.pinning.removeRule(orama.data.pinning, ruleId);
}
/**
* Get a specific pinning rule by its ID.
*
* @example
* ```typescript
* const rule = getPin(db, 'featured-products')
* console.log(rule)
* ```
*/
function getPin(orama, ruleId) {
return orama.pinning.getRule(orama.data.pinning, ruleId);
}
/**
* Get all pinning rules in the database.
*
* @example
* ```typescript
* const allRules = getAllPins(db)
* console.log(`Total rules: ${allRules.length}`)
* ```
*/
function getAllPins(orama) {
return orama.pinning.getAllRules(orama.data.pinning);
}
//# sourceMappingURL=pinning.js.map