Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
allevo committed Oct 11, 2024
1 parent e91f30f commit cdd0ec1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
1 change: 0 additions & 1 deletion benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"orama_211": "npm:@orama/[email protected]",
"orama_300_rc_2": "npm:@orama/[email protected]",
"orama_latest": "file:../packages/orama",
"@orama/plugin-qps": "file:../packages/plugin-qps",
"@orama/stopwords": "file:../packages/stopwords",
"@orama/plugin-pt15": "file:../packages/plugin-pt15"
},
Expand Down
12 changes: 9 additions & 3 deletions packages/orama/src/methods/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { Sorter, createSorter } from '../components/sorter.js'
import { createTokenizer } from '../components/tokenizer/index.js'
import { createError } from '../errors.js'
import {
AnySchema,
Components,
FunctionComponents,
IDocumentsStore,
IIndex,
ISorter,
ObjectComponents,
Orama,
OramaPlugin,
SorterConfig,
Expand Down Expand Up @@ -70,7 +72,7 @@ function validateComponents<
}

export function create<
OramaSchema,
OramaSchema extends AnySchema,
TIndex = IIndex<Index>,
TDocumentStore = IDocumentsStore<DocumentsStore>,
TSorter = ISorter<Sorter>
Expand All @@ -94,14 +96,18 @@ export function create<
continue;
}

const pluginComponents = plugin.getComponents(schema);
const pluginComponents = plugin.getComponents(schema) as Partial<ObjectComponents<TIndex, TDocumentStore, TSorter>>;

const keys = Object.keys(pluginComponents)
for (const key of keys) {
if (components[key]) {
if (components![key]) {
throw createError('PLUGIN_COMPONENT_CONFLICT', key, plugin.name)
}
}
components = {
...components,
...pluginComponents
}
}

if (!id) {
Expand Down
2 changes: 1 addition & 1 deletion packages/orama/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ export type OramaPluginSync<T = unknown> = {
beforeUpdateMultiple?: <T extends AnyOrama>(orama: T, docs: AnyDocument[]) => SyncOrAsyncValue
afterUpdateMultiple?: <T extends AnyOrama>(orama: T, docs: AnyDocument[]) => SyncOrAsyncValue
afterCreate?: <T extends AnyOrama>(orama: T) => SyncOrAsyncValue
getComponents?: <T extends AnyOrama>(schema: T['schema']) => SyncOrAsyncValue<Components<T, any, any, any, any>>
getComponents?: <TIndex extends IIndex<AnyIndexStore>, TDocumentStore, TSorter>(schema: AnySchema) => SyncOrAsyncValue<Partial<ObjectComponents<TIndex, TDocumentStore, TSorter>>>
}

export type OramaPluginAsync<T = unknown> = Promise<OramaPluginSync<T>>
Expand Down
16 changes: 4 additions & 12 deletions packages/plugin-pt15/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
import type { create, AnyOrama, SearchableType, IIndex, AnyIndexStore, SearchableValue, Tokenizer, OnlyStrings, FlattenSchemaProperty, TokenScore, WhereCondition, OramaPluginSync } from '@orama/orama'
import type { AnyOrama, SearchableType, IIndex, AnyIndexStore, SearchableValue, Tokenizer, OnlyStrings, FlattenSchemaProperty, TokenScore, WhereCondition, OramaPluginSync, AnySchema, ObjectComponents } from '@orama/orama'
import {
index as Index, internalDocumentIDStore } from '@orama/orama/components'
import { PT15IndexStore, insertString, recursiveCreate, PositionsStorage, searchString } from './algorithm.js';

type InternalDocumentID = internalDocumentIDStore.InternalDocumentID;
type InternalDocumentIDStore = internalDocumentIDStore.InternalDocumentIDStore;

type CreateParams = Parameters<typeof create<AnyOrama, IIndex<PT15IndexStore>>>[0]
type Component = NonNullable<CreateParams['components']>
type IndexParameter = NonNullable<Component['index']>
type DocumentID = internalDocumentIDStore.DocumentID;


export function pluginPT15(): OramaPluginSync {

return {
name: 'orama-plugin-pt15',

getComponents: function getComponents<T extends AnyOrama>(schema: T['schema']) {
getComponents: function getComponents(schema: AnySchema) {
return createComponents(schema)
}
},
}
}

function createComponents<T extends AnyOrama>(schema: T['schema']): {
index: IndexParameter,
} {

function createComponents(schema: AnySchema): Partial<ObjectComponents<any, any, any>> {
return {
index: {
create: function create() {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-pt15/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ t.test('get_position', async t => {
t.equal(get_position(49, 50), 14)
})

t.test('plugin-position', async t => {
t.test('plugin-pt15', async t => {
const db = create({
schema: {
name: 'string',
Expand Down

0 comments on commit cdd0ec1

Please sign in to comment.