diff --git a/README.md b/README.md index bfdf3e14a..b2a2c8bb8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -![Orama. Search, everywhere.](https://raw.githubusercontent.com/OramaSearch/orama/main/misc/orama-edge-logo.png) +![Orama. Search, everywhere.](https://github.com/oramasearch/orama/blob/main/misc/oramasearch.gif?raw=true) -[![Tests](https://github.com/OramaSearch/orama/actions/workflows/ci.yml/badge.svg)](https://github.com/OramaSearch/orama/actions/workflows/ci.yml) +[![Tests](https://github.com/oramasearch/orama/actions/workflows/turbo.yml/badge.svg)](https://github.com/oramasearch/orama/actions/workflows/turbo.yml) # Join Orama's Slack channel @@ -8,7 +8,7 @@ If you need more info, help, or want to provide general feedback on Orama, join the [Orama Slack channel](https://join.slack.com/t/oramasearch/shared_invite/zt-1gzvj0mmt-yJhJ6pnrSGuwqPmPx9uO5Q) -# Installation - install via @orama/orama! +# Installation You can install Orama using `npm`, `yarn`, `pnpm`: @@ -30,7 +30,7 @@ Or import it directly in a browser module:
@@ -46,14 +46,14 @@ Orama is quite simple to use. The first thing to do is to create a new database instance and set an indexing schema: ```js -import { create, insert, remove, search } from "@orama/orama"; +import { create, insert, remove, search } from '@orama/orama' const db = await create({ schema: { - author: "string", - quote: "string", + author: 'string', + quote: 'string', }, -}); +}) ``` If you are using Node.js without ESM, please see [build](#builds) section below on how to properly require Orama. @@ -65,36 +65,36 @@ Once the db instance is created, you can start adding some documents: ```js await insert(db, { - quote: "It is during our darkest moments that we must focus to see the light.", - author: "Aristotle", -}); + quote: 'It is during our darkest moments that we must focus to see the light.', + author: 'Aristotle', +}) await insert(db, { - quote: "If you really look closely, most overnight successes took a long time.", - author: "Steve Jobs", -}); + quote: 'If you really look closely, most overnight successes took a long time.', + author: 'Steve Jobs', +}) await insert(db, { - quote: "If you are not willing to risk the usual, you will have to settle for the ordinary.", - author: "Jim Rohn", -}); + quote: 'If you are not willing to risk the usual, you will have to settle for the ordinary.', + author: 'Jim Rohn', +}) await insert(db, { quote: "You miss 100% of the shots you don't take", - author: "Wayne Gretzky - Michael Scott", -}); + author: 'Wayne Gretzky - Michael Scott', +}) ``` After the data has been inserted, you can finally start to query the database. ```js const searchResult = await search(db, { - term: "if", - properties: "*", + term: 'if', + properties: '*', boost: { - author: 1.5 // optional: boost author field by x1.5 - } -}); + author: 1.5, // optional: boost author field by x1.5 + }, +}) ``` In the case above, you will be searching for all the documents containing the @@ -129,9 +129,9 @@ You can also restrict the lookup to a specific property: ```js const searchResult = await search(db, { - term: "Michael", - properties: ["author"], -}); + term: 'Michael', + properties: ['author'], +}) ``` Result: @@ -156,21 +156,21 @@ Result: If needed, you can also delete a given document by using the `remove` method: ```js -await remove(db, "41045799-144"); +await remove(db, '41045799-144') ``` Orama exposes a built-in `formatNanoseconds` function to format the elapsed time in a human-readable format: ```js -import { formatNanoseconds } from "@orama/orama"; +import { formatNanoseconds } from '@orama/orama' const searchResult = await search(db, { - term: "if", - properties: "*", -}); + term: 'if', + properties: '*', +}) -console.log(`Search took ${formatNanoseconds(searchResult.elapsed)}`); +console.log(`Search took ${formatNanoseconds(searchResult.elapsed)}`) // Search took 164μs ``` @@ -185,15 +185,15 @@ Starting with version 0.4.0 it becomes: ```js async function main() { - const { create, insert } = await import("@orama/orama"); + const { create, insert } = await import('@orama/orama') - const db = create(/* ... */); + const db = create(/* ... */) insert(db, { /* ... */ - }); + }) } -main().catch(console.error); +main().catch(console.error) ``` #### Use CJS requires @@ -226,45 +226,45 @@ shipped with the default Orama installation. Example: ```js -import { create } from "@orama/orama"; -import { stemmer } from "@orama/orama/components/stemmer/it"; +import { create } from '@orama/orama' +import { stemmer } from '@orama/orama/components/stemmer/it' const db = await create({ schema: { - author: "string", - quote: "string", + author: 'string', + quote: 'string', }, - defaultLanguage: "italian", + defaultLanguage: 'italian', components: { tokenizer: { stemmingFn: stemmer, }, }, -}); +}) ``` Example using CJS (see [using with commonJS](#using-with-commonjs) above): ```js async function main() { - const { create } = await import("@orama/orama"); - const { stemmer } = await import("@orama/orama/components/stemmer/it"); + const { create } = await import('@orama/orama') + const { stemmer } = await import('@orama/orama/components/stemmer/it') const db = await create({ schema: { - author: "string", - quote: "string", + author: 'string', + quote: 'string', }, - defaultLanguage: "italian", + defaultLanguage: 'italian', components: { tokenizer: { stemmingFn: stemmer, }, }, - }); + }) } -main(); +main() ``` Right now, Orama supports 26 languages and stemmers out of the box: diff --git a/package.json b/package.json index fcf96d673..568d90e98 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "orama-monorepo", - "version": "1.0.0-beta.0", + "version": "1.0.0-beta.1", "description": "Next generation full-text search engine, written in TypeScript", "workspaces": [ "packages/*" diff --git a/packages/benchmarks/package.json b/packages/benchmarks/package.json index 9eb42ad70..1edc1acb8 100644 --- a/packages/benchmarks/package.json +++ b/packages/benchmarks/package.json @@ -1,6 +1,6 @@ { "name": "benchmarks", - "version": "1.0.0-beta.0", + "version": "1.0.0-beta.1", "scripts": { "run": "node ./typo-tolerant-search.js" }, diff --git a/packages/docs/package.json b/packages/docs/package.json index 3e510c828..69bb39231 100644 --- a/packages/docs/package.json +++ b/packages/docs/package.json @@ -1,10 +1,12 @@ { "name": "@orama/docs", - "version": "1.0.0-beta.0", + "version": "1.0.0-beta.1", "description": "Documentation for Orama", "main": "index.js", "scripts": { - "dev": "next dev" + "dev": "next dev", + "build": "next build", + "serve": "next start" }, "keywords": [], "author": "", diff --git a/packages/orama/README.md b/packages/orama/README.md new file mode 100644 index 000000000..b2a2c8bb8 --- /dev/null +++ b/packages/orama/README.md @@ -0,0 +1,305 @@ +![Orama. Search, everywhere.](https://github.com/oramasearch/orama/blob/main/misc/oramasearch.gif?raw=true) + +[![Tests](https://github.com/oramasearch/orama/actions/workflows/turbo.yml/badge.svg)](https://github.com/oramasearch/orama/actions/workflows/turbo.yml) + +# Join Orama's Slack channel + +If you need more info, help, or want to provide general feedback on Orama, join +the +[Orama Slack channel](https://join.slack.com/t/oramasearch/shared_invite/zt-1gzvj0mmt-yJhJ6pnrSGuwqPmPx9uO5Q) + +# Installation + +You can install Orama using `npm`, `yarn`, `pnpm`: + +```sh +npm i @orama/orama +``` + +```sh +yarn add @orama/orama +``` + +```sh +pnpm add @orama/orama +``` + +Or import it directly in a browser module: + +```html + + + + + +``` + +Read the complete documentation at [https://docs.oramasearch.com/](https://docs.oramasearch.com/). + +# Usage + +Orama is quite simple to use. The first thing to do is to create a new database +instance and set an indexing schema: + +```js +import { create, insert, remove, search } from '@orama/orama' + +const db = await create({ + schema: { + author: 'string', + quote: 'string', + }, +}) +``` + +If you are using Node.js without ESM, please see [build](#builds) section below on how to properly require Orama. + +Orama will only index string properties, but will allow you to set and store +additional data if needed. + +Once the db instance is created, you can start adding some documents: + +```js +await insert(db, { + quote: 'It is during our darkest moments that we must focus to see the light.', + author: 'Aristotle', +}) + +await insert(db, { + quote: 'If you really look closely, most overnight successes took a long time.', + author: 'Steve Jobs', +}) + +await insert(db, { + quote: 'If you are not willing to risk the usual, you will have to settle for the ordinary.', + author: 'Jim Rohn', +}) + +await insert(db, { + quote: "You miss 100% of the shots you don't take", + author: 'Wayne Gretzky - Michael Scott', +}) +``` + +After the data has been inserted, you can finally start to query the database. + +```js +const searchResult = await search(db, { + term: 'if', + properties: '*', + boost: { + author: 1.5, // optional: boost author field by x1.5 + }, +}) +``` + +In the case above, you will be searching for all the documents containing the +word `if`, looking up in every schema property (AKA index): + +```js +{ + elapsed: 184541n, // Elapsed time in nanoseconds + hits: [ + { + id: '41013877-56', + score: 0.025085832971998432, + document: { + quote: 'If you really look closely, most overnight successes took a long time.', + author: 'Steve Jobs' + } + }, + { + id: '41013877-107', + score: 0.02315615351261394, + document: { + quote: 'If you are not willing to risk the usual, you will have to settle for the ordinary.', + author: 'Jim Rohn' + } + } + ], + count: 2 +} +``` + +You can also restrict the lookup to a specific property: + +```js +const searchResult = await search(db, { + term: 'Michael', + properties: ['author'], +}) +``` + +Result: + +```js +{ + elapsed: 172166n, + hits: [ + { + id: '41045799-144', + score: 0.12041199826559248, + document: { + quote: "You miss 100% of the shots you don't take", + author: 'Wayne Gretzky - Michael Scott' + } + } + ], + count: 1 +} +``` + +If needed, you can also delete a given document by using the `remove` method: + +```js +await remove(db, '41045799-144') +``` + +Orama exposes a built-in `formatNanoseconds` function to format the elapsed time +in a human-readable format: + +```js +import { formatNanoseconds } from '@orama/orama' + +const searchResult = await search(db, { + term: 'if', + properties: '*', +}) + +console.log(`Search took ${formatNanoseconds(searchResult.elapsed)}`) +// Search took 164μs +``` + +### Using with CommonJS + +Orama is packaged as ES modules, suitable for Node.js, Deno, Bun and modern browsers. + +**In most cases, simply `import` or `@orama/orama` will suffice ✨.** + +In Node.js, when not using ESM (with `"type": "module"` in the `package.json`), you have several ways to properly require Orama. +Starting with version 0.4.0 it becomes: + +```js +async function main() { + const { create, insert } = await import('@orama/orama') + + const db = create(/* ... */) + insert(db, { + /* ... */ + }) +} + +main().catch(console.error) +``` + +#### Use CJS requires + +Orama methods can be required as CommonJS modules by requiring from `@orama/orama/cjs`. + +```js +const { create, insert } = require("@orama/orama/cjs") + +create(/* ... */) + .then(db => insert(db, { /* ... */ }) + .catch(console.error) +``` + +Note that only main methods are supported so for internals and other supported exports you still have to use `await import`. + +## Language + +Orama supports multiple languages. By default, it will use the `english` +language, + +You can specify a different language by using the `defaultLanguage` property +during Orama initialization. + +By default, Orama will analyze your input using an English +[Porter Stemmer](https://tartarus.org/martin/PorterStemmer/) function.