diff --git a/packages/orama/src/components.ts b/packages/orama/src/components.ts index a85674ae4..4db44d604 100644 --- a/packages/orama/src/components.ts +++ b/packages/orama/src/components.ts @@ -3,3 +3,4 @@ export * as documentsStore from './components/documents-store.js' export * as index from './components/index.js' export * as tokenizer from './components/tokenizer/index.js' export * as sorter from './components/sorter.js' +export * as internalDocumentIDStore from './components/internal-document-id-store.js' diff --git a/packages/orama/src/components/documents-store.ts b/packages/orama/src/components/documents-store.ts index 0f5c3403a..33acba62a 100644 --- a/packages/orama/src/components/documents-store.ts +++ b/packages/orama/src/components/documents-store.ts @@ -1,4 +1,4 @@ -import { InternalDocumentStore, getInternalDocumentId, InternalDocumentID, InternalDocumentIDStore } from "./internal-document-store.js"; +import { DocumentID, getInternalDocumentId, InternalDocumentID, InternalDocumentIDStore } from "./internal-document-id-store.js"; import { Document, IDocumentsStore, OpaqueDocumentStore } from "../types.js"; export interface DocumentsStore extends OpaqueDocumentStore { @@ -23,7 +23,7 @@ export async function get(store: DocumentsStore, id: string): Promise { +export async function getMultiple(store: DocumentsStore, ids: DocumentID[]): Promise<(Document | undefined)[]> { const found: (Document | undefined)[] = Array.from({ length: ids.length }) for (let i = 0; i < ids.length; i++) { @@ -38,7 +38,7 @@ export async function getAll(store: DocumentsStore): Promise } -export async function store(store: DocumentsStore, id: InternalDocumentStore, doc: Document): Promise { +export async function store(store: DocumentsStore, id: DocumentID, doc: Document): Promise { const internalId = getInternalDocumentId(store.sharedInternalDocumentStore, id); if (typeof store.docs[internalId] !== 'undefined') { @@ -51,7 +51,7 @@ export async function store(store: DocumentsStore, id: InternalDocumentStore, do return true } -export async function remove(store: DocumentsStore, id: InternalDocumentStore): Promise { +export async function remove(store: DocumentsStore, id: DocumentID): Promise { const internalId = getInternalDocumentId(store.sharedInternalDocumentStore, id); if (typeof store.docs[internalId] === 'undefined') { diff --git a/packages/orama/src/components/groups.ts b/packages/orama/src/components/groups.ts index 31a6b07e0..2d391d29e 100644 --- a/packages/orama/src/components/groups.ts +++ b/packages/orama/src/components/groups.ts @@ -1,6 +1,7 @@ import type { Orama, ScalarSearchableValue, TokenScore, GroupByParams, GroupResult, Result, Reduce } from '../types.js' import { createError } from '../errors.js' import { getNested, intersect } from '../utils.js' +import { getDocumentIdFromInternalId } from "./internal-document-id-store.js"; interface PropertyGroup { property: string @@ -47,7 +48,7 @@ export async function getGroups( } } - const allIDs = results.map(([id]) => id) + const allIDs = results.map(([id]) => getDocumentIdFromInternalId(orama.internalDocumentIDStore, id)) // allDocs is already sorted by the sortBy algorithm // We leverage on that to limit the number of documents returned diff --git a/packages/orama/src/components/index.ts b/packages/orama/src/components/index.ts index d4e526f94..da79e19ae 100644 --- a/packages/orama/src/components/index.ts +++ b/packages/orama/src/components/index.ts @@ -1,4 +1,4 @@ -import { InternalDocumentStore, getInternalDocumentId, InternalDocumentID, InternalDocumentIDStore } from "./internal-document-store.js"; +import { DocumentID, getInternalDocumentId, InternalDocumentID, InternalDocumentIDStore } from "./internal-document-id-store.js"; import { createError } from "../errors.js"; import { create as avlCreate, find as avlFind, greaterThan as avlGreaterThan, insert as avlInsert, lessThan as avlLessThan, Node as AVLNode, rangeSearch as avlRangeSearch, removeDocument as avlRemoveDocument } from "../trees/avl.js"; import { create as radixCreate, find as radixFind, insert as radixInsert, Node as RadixNode, removeDocumentByWord as radixRemoveDocument } from "../trees/radix.js"; @@ -100,7 +100,7 @@ export async function calculateResultScores { const documentIDs = Array.from(ids) @@ -143,7 +143,7 @@ export async function create( ): Promise { if (!index) { index = { - sharedInternalDocumentStore: orama.internalDocumentStore, + sharedInternalDocumentStore: orama.internalDocumentIDStore, indexes: {}, searchableProperties: [], searchablePropertiesWithTypes: {}, diff --git a/packages/orama/src/components/internal-document-id-store.ts b/packages/orama/src/components/internal-document-id-store.ts new file mode 100644 index 000000000..b327a1f65 --- /dev/null +++ b/packages/orama/src/components/internal-document-id-store.ts @@ -0,0 +1,66 @@ +import { Orama } from '../types.js'; + +export type DocumentID = string | number; +export type InternalDocumentID = number; + +export type InternalDocumentIDStore = { + idToInternalId: Map; + internalIdToId: string[]; + save: (store: InternalDocumentIDStore) => unknown; + load: (orama: Orama, raw: unknown) => void; +}; + +export function createInternalDocumentIDStore(): InternalDocumentIDStore { + return { + idToInternalId: new Map(), + internalIdToId: [], + save, + load, + }; +} + +export function save(store: InternalDocumentIDStore): unknown { + return { + internalIdToId: store.internalIdToId, + }; +} + +export function load(orama: Orama, raw: unknown): void { + const { internalIdToId } = raw as InternalDocumentIDStore; + + orama.internalDocumentIDStore.idToInternalId.clear(); + orama.internalDocumentIDStore.internalIdToId = []; + + for (let i = 0; i < internalIdToId.length; i++) { + orama.internalDocumentIDStore.idToInternalId.set(internalIdToId[i], i + 1); + orama.internalDocumentIDStore.internalIdToId.push(internalIdToId[i]); + } +} + +export function getInternalDocumentId(store: InternalDocumentIDStore, id: DocumentID): InternalDocumentID { + if (typeof id === "string") { + const internalId = store.idToInternalId.get(id); + + if (internalId) { + return internalId; + } + + const currentId = store.idToInternalId.size + 1; + + store.idToInternalId.set(id, currentId); + store.internalIdToId.push(id); + + return currentId; + } + + return id as number; +} + +export function getDocumentIdFromInternalId(store: InternalDocumentIDStore, internalId: InternalDocumentID): string { + if (store.internalIdToId.length < internalId) { + throw new Error(`Invalid internalId ${internalId}`); + } + + return store.internalIdToId[internalId - 1]; +} + diff --git a/packages/orama/src/components/internal-document-store.ts b/packages/orama/src/components/internal-document-store.ts deleted file mode 100644 index b71c282b9..000000000 --- a/packages/orama/src/components/internal-document-store.ts +++ /dev/null @@ -1,30 +0,0 @@ -export type InternalDocumentStore = string | number; -export type InternalDocumentID = number; - -const InternalDocumentIDCounter = Symbol('InternalDocumentIDCounter'); - -export type InternalDocumentIDStore = Record & { [InternalDocumentIDCounter]: number }; - -export function createInternalDocumentIDStore(): InternalDocumentIDStore { - return { - [InternalDocumentIDCounter]: 0 - }; -} - -export function getInternalDocumentId(store: InternalDocumentIDStore, id: InternalDocumentStore): InternalDocumentID { - if (typeof id === "string" && isNaN(+id)) { - const internalId = store[id]; - - if (internalId) { - return internalId; - } - - const currentId = ++store[InternalDocumentIDCounter]; - - store[id] = currentId; - - return currentId; - } - - return id as number; -} diff --git a/packages/orama/src/components/sorter.ts b/packages/orama/src/components/sorter.ts index 25b9e1489..27f3b4acd 100644 --- a/packages/orama/src/components/sorter.ts +++ b/packages/orama/src/components/sorter.ts @@ -1,4 +1,4 @@ -import { InternalDocumentStore, getInternalDocumentId, InternalDocumentID, InternalDocumentIDStore } from "./internal-document-store.js"; +import { DocumentID, getInternalDocumentId, InternalDocumentID, InternalDocumentIDStore } from "./internal-document-id-store.js"; import { createError } from "../errors.js"; import { ISorter, OpaqueSorter, Orama, Schema, SorterConfig, SorterParams, SortType, SortValue } from "../types.js"; @@ -20,7 +20,7 @@ export type DefaultSorter = ISorter function innerCreate(orama: Orama, schema: Schema, sortableDeniedProperties: string[], prefix: string): Sorter { const sorter: Sorter = { - sharedInternalDocumentStore: orama.internalDocumentStore, + sharedInternalDocumentStore: orama.internalDocumentIDStore, enabled: true, sortableProperties: [], sortablePropertiesWithTypes: {}, @@ -143,7 +143,7 @@ async function insert( } } -async function remove(sorter: Sorter, prop: string, id: InternalDocumentStore) { +async function remove(sorter: Sorter, prop: string, id: DocumentID) { if (!sorter.enabled) { return } diff --git a/packages/orama/src/methods/create.ts b/packages/orama/src/methods/create.ts index f48f92ded..f481aadec 100644 --- a/packages/orama/src/methods/create.ts +++ b/packages/orama/src/methods/create.ts @@ -3,7 +3,7 @@ import { createDocumentsStore } from '../components/documents-store.js' import { OBJECT_COMPONENTS, FUNCTION_COMPONENTS, SINGLE_OR_ARRAY_COMPONENTS } from '../components/hooks.js' import { createIndex } from '../components/index.js' import { createTokenizer } from '../components/tokenizer/index.js' -import { createInternalDocumentIDStore, InternalDocumentStore, InternalDocumentID, InternalDocumentIDStore } from "../components/internal-document-store.js"; +import { createInternalDocumentIDStore } from "../components/internal-document-id-store.js"; import { createError } from '../errors.js' import { uniqueId } from '../utils.js' import { @@ -159,7 +159,7 @@ export async function create

({ index, sorter, documentsStore, - internalDocumentStore, + internalDocumentIDStore: internalDocumentStore, getDocumentProperties, getDocumentIndexId, validateSchema, diff --git a/packages/orama/src/methods/search.ts b/packages/orama/src/methods/search.ts index e36d8d5f1..102bcd421 100644 --- a/packages/orama/src/methods/search.ts +++ b/packages/orama/src/methods/search.ts @@ -3,7 +3,7 @@ import { getFacets } from '../components/facets.js' import { intersectFilteredIDs } from '../components/filters.js' import { getGroups } from '../components/groups.js' import { runAfterSearch } from '../components/hooks.js' -import { InternalDocumentID } from "../components/internal-document-store.js"; +import { getDocumentIdFromInternalId, InternalDocumentID } from "../components/internal-document-id-store.js"; import { createError } from '../errors.js' import { BM25Params, @@ -247,7 +247,12 @@ export async function search( } if (typeof results !== 'undefined') { - searchResult.hits = results.filter(Boolean) + for (const result of results) { + if (!result) continue; + + result.id = getDocumentIdFromInternalId(orama.internalDocumentIDStore, +result.id); + searchResult.hits.push(result); + } } if (shouldCalculateFacets) { @@ -318,7 +323,7 @@ async function fetchDocumentsWithDistinct( continue } - results.push({ id, score, document: doc! }) + results.push({ id: id.toString(), score, document: doc! }) resultIDs.add(id) // reached the limit, break the loop @@ -361,7 +366,7 @@ async function fetchDocuments( // We retrieve the full document only AFTER making sure that we really want it. // We never retrieve the full document preventively. const fullDoc = await orama.documentsStore.get(docs, id) - results[i] = { id, score, document: fullDoc! } + results[i] = { id: id.toString(), score, document: fullDoc! } resultIDs.add(id) } } diff --git a/packages/orama/src/methods/serialization.ts b/packages/orama/src/methods/serialization.ts index 6315fa872..1955ec98f 100644 --- a/packages/orama/src/methods/serialization.ts +++ b/packages/orama/src/methods/serialization.ts @@ -1,12 +1,15 @@ import { Orama } from '../types.js' export interface RawData { + internalIdStore: unknown index: unknown docs: unknown sorting: unknown } export async function load(orama: Orama, raw: RawData): Promise { + orama.internalDocumentIDStore.load(orama, raw.internalIdStore); + orama.data.index = await orama.index.load(raw.index) orama.data.docs = await orama.documentsStore.load(raw.docs) orama.data.sorting = await orama.sorter.load(raw.sorting) @@ -14,6 +17,7 @@ export async function load(orama: Orama, raw: RawData): Promise { export async function save(orama: Orama): Promise { return { + internalIdStore: orama.internalDocumentIDStore.save(orama.internalDocumentIDStore), index: await orama.index.save(orama.data.index), docs: await orama.documentsStore.save(orama.data.docs), sorting: await orama.sorter.save(orama.data.sorting), diff --git a/packages/orama/src/trees/radix.ts b/packages/orama/src/trees/radix.ts index adc5b06ef..bf5d1d95f 100644 --- a/packages/orama/src/trees/radix.ts +++ b/packages/orama/src/trees/radix.ts @@ -1,5 +1,5 @@ import { syncBoundedLevenshtein } from "../components/levenshtein.js"; -import { InternalDocumentID } from "../components/internal-document-store.js"; +import { InternalDocumentID } from "../components/internal-document-id-store.js"; import { getOwnProperty } from "../utils.js"; export interface Node { diff --git a/packages/orama/src/types.ts b/packages/orama/src/types.ts index 3fd1164e4..dba655bff 100644 --- a/packages/orama/src/types.ts +++ b/packages/orama/src/types.ts @@ -1,5 +1,5 @@ import { Language } from "./components/tokenizer/languages.js"; -import { InternalDocumentStore, InternalDocumentID, InternalDocumentIDStore } from "./components/internal-document-store.js"; +import { DocumentID, InternalDocumentID, InternalDocumentIDStore } from "./components/internal-document-id-store.js"; export type Nullable = T | null @@ -301,7 +301,7 @@ export type Result = { /** * The id of the document. */ - id: InternalDocumentID + id: string; /** * The score of the document in the search. */ @@ -449,7 +449,7 @@ export interface IIndex { index: I, prop: string, term: string, - ids: InternalDocumentStore[], + ids: DocumentID[], ): SyncOrAsyncValue search( @@ -475,11 +475,11 @@ export interface IDocumentsStore( orama: Orama<{ Schema: S; Index: I; DocumentStore: D; Sorter: So }>, ): SyncOrAsyncValue - get(store: D, id: InternalDocumentStore): SyncOrAsyncValue - getMultiple(store: D, ids: InternalDocumentStore[]): SyncOrAsyncValue<(Document | undefined)[]> + get(store: D, id: DocumentID): SyncOrAsyncValue + getMultiple(store: D, ids: DocumentID[]): SyncOrAsyncValue<(Document | undefined)[]> getAll(store: D): SyncOrAsyncValue> - store(store: D, id: InternalDocumentStore, doc: Document): SyncOrAsyncValue - remove(store: D, id: InternalDocumentStore): SyncOrAsyncValue + store(store: D, id: DocumentID, doc: Document): SyncOrAsyncValue + remove(store: D, id: DocumentID): SyncOrAsyncValue count(store: D): SyncOrAsyncValue load(raw: R): SyncOrAsyncValue @@ -601,7 +601,7 @@ type Internals

= { documentsStore: IDocumentsStore sorter: ISorter data: Data - internalDocumentStore: InternalDocumentIDStore + internalDocumentIDStore: InternalDocumentIDStore caches: Record [kInsertions]: number | undefined [kRemovals]: number | undefined diff --git a/packages/orama/tests/array.test.ts b/packages/orama/tests/array.test.ts index 5744b8f60..787499210 100644 --- a/packages/orama/tests/array.test.ts +++ b/packages/orama/tests/array.test.ts @@ -1,5 +1,4 @@ import t from 'tap' -import { getInternalDocumentId } from "../src/components/internal-document-store.js"; import { create, getByID, insert, insertMultiple, load, remove, save, search, update } from '../src/index.js' t.test('create should support array of string', async t => { @@ -240,7 +239,7 @@ async function checkSearchTerm(t, db, term, expectedIds) { }) t.equal(result.hits.length, expectedIds.length) t.equal(result.count, expectedIds.length) - t.strictSame(new Set(result.hits.map(h => h.id)), new Set(expectedIds.map(getInternalDocumentId))) + t.strictSame(new Set(result.hits.map(h => h.id)), new Set(expectedIds)) } async function checkSearchWhere(t, db, key, where, expectedIds) { @@ -251,7 +250,7 @@ async function checkSearchWhere(t, db, key, where, expectedIds) { }) t.equal(result.hits.length, expectedIds.length) t.equal(result.count, expectedIds.length) - t.strictSame(new Set(result.hits.map(h => h.id)), new Set(expectedIds.map(getInternalDocumentId))) + t.strictSame(new Set(result.hits.map(h => h.id)), new Set(expectedIds)) } async function checkSearchFacets(t: Tap.Test, db, key, facet, expectedFacet) { diff --git a/packages/orama/tests/customize.component.test.ts b/packages/orama/tests/customize.component.test.ts index c59fe8fe5..6026cd007 100644 --- a/packages/orama/tests/customize.component.test.ts +++ b/packages/orama/tests/customize.component.test.ts @@ -1,6 +1,7 @@ import t from 'tap' import { ISorter, OpaqueSorter, Orama, create, insert, load, remove, save, search } from '../src/index.js' import { + internalDocumentIDStore as defaultInternalDocumentIDStore, sorter as defaultSorter, documentsStore as defaultDocumentsStore, index as defaultIndex, @@ -9,7 +10,8 @@ import { DefaultSorter, Sorter } from '../src/components/sorter.js' t.test('index', t => { t.test('should allow custom component', async t => { - const index = await defaultIndex.createIndex() + const internalDocumentIdStore = defaultInternalDocumentIDStore.createInternalDocumentIDStore() + const index = await defaultIndex.createIndex(internalDocumentIdStore) const db = await create({ schema: { number: 'number', @@ -37,7 +39,8 @@ t.test('index', t => { t.test('documentStore', t => { t.test('should allow custom component', async t => { - const store = await defaultDocumentsStore.createDocumentsStore() + const internalDocumentIdStore = defaultInternalDocumentIDStore.createInternalDocumentIDStore() + const store = await defaultDocumentsStore.createDocumentsStore(internalDocumentIdStore) const db = await create({ schema: { number: 'number', @@ -84,7 +87,8 @@ t.test('documentStore', t => { }) t.test('should allow custom component - partially', async t => { - const store = await defaultDocumentsStore.createDocumentsStore() + const internalDocumentIdStore = defaultInternalDocumentIDStore.createInternalDocumentIDStore() + const store = await defaultDocumentsStore.createDocumentsStore(internalDocumentIdStore) const db = await create({ schema: { number: 'number', @@ -112,7 +116,8 @@ t.test('documentStore', t => { t.test('sorter', t => { t.test('should allow custom component', async t => { - const s = await defaultSorter.createSorter() + const internalDocumentIdStore = defaultInternalDocumentIDStore.createInternalDocumentIDStore() + const s = await defaultSorter.createSorter(internalDocumentIdStore) const order: string[] = [] const db = await create({ schema: { @@ -165,7 +170,8 @@ t.test('sorter', t => { }) t.test('should allow custom component - partially', async t => { - const s = await defaultSorter.createSorter() + const internalDocumentIdStore = defaultInternalDocumentIDStore.createInternalDocumentIDStore() + const s = await defaultSorter.createSorter(internalDocumentIdStore) const order: string[] = [] const db = await create({ schema: { @@ -230,12 +236,13 @@ t.test('sorter', t => { } } + const internalDocumentIdStore = defaultInternalDocumentIDStore.createInternalDocumentIDStore() const db: Orama<{ Sorter: MyCustomSorter }> = await create({ schema: { number: 'number', }, components: { - sorter: new MyCustomSorter(await defaultSorter.createSorter()), + sorter: new MyCustomSorter(await defaultSorter.createSorter(internalDocumentIdStore)), }, }) const id = await insert(db, { number: 1 }) diff --git a/packages/orama/tests/dataset.test.ts b/packages/orama/tests/dataset.test.ts index 55edb8bb3..dc4a27d4f 100644 --- a/packages/orama/tests/dataset.test.ts +++ b/packages/orama/tests/dataset.test.ts @@ -19,7 +19,7 @@ type EventJson = { function removeVariadicData(res: Results): Omit { const hits = res.hits.map(h => { - h.id = 1 + h.id = '' return h }) diff --git a/packages/orama/tests/group.test.ts b/packages/orama/tests/group.test.ts index d8ff96ad3..0fcaf862f 100644 --- a/packages/orama/tests/group.test.ts +++ b/packages/orama/tests/group.test.ts @@ -1,4 +1,5 @@ import t from 'tap' +import { inspect } from "util"; import { Document, GroupResult, diff --git a/packages/orama/tests/insert.test.ts b/packages/orama/tests/insert.test.ts index 83fb749f8..5abc3d0a7 100644 --- a/packages/orama/tests/insert.test.ts +++ b/packages/orama/tests/insert.test.ts @@ -1,4 +1,5 @@ import t from 'tap' +import { getInternalDocumentId } from '../src/components/internal-document-id-store.js'; import { insert, insertMultiple, create, search, Document } from '../src/index.js' import { DocumentsStore } from '../src/components/documents-store.js' import { Index } from '../src/components/index.js' @@ -190,17 +191,17 @@ t.test('insert method', t => { authors: 'author should be singular', }) - t.equal(Object.getOwnPropertySymbols((db.data.docs as DocumentsStore).docs).length, 1) + t.equal(Object.keys((db.data.docs as DocumentsStore).docs).length, 1) const docWithExtraKey = { quote: 'hello, world!', foo: { bar: 10 } } const insertedInfo = await insert(db, docWithExtraKey) t.ok(insertedInfo) - t.equal(Object.getOwnPropertySymbols((db.data.docs as DocumentsStore).docs).length, 2) + t.equal(Object.keys((db.data.docs as DocumentsStore).docs).length, 2) - t.ok('foo' in (db.data.docs as DocumentsStore).docs[Symbol.for(insertedInfo)]!) - t.same(docWithExtraKey.foo, (db.data.docs as DocumentsStore).docs[Symbol.for(insertedInfo)]!.foo) + t.ok('foo' in (db.data.docs as DocumentsStore).docs[getInternalDocumentId(db.internalDocumentIDStore, insertedInfo)]!) + t.same(docWithExtraKey.foo, (db.data.docs as DocumentsStore).docs[getInternalDocumentId(db.internalDocumentIDStore, insertedInfo)]!.foo) t.notOk('foo' in (db.data.index as Index).indexes) }) @@ -241,16 +242,16 @@ t.test('insert method', t => { const insertedInfo = await insert(db, nestedExtraKeyDoc) t.ok(insertedInfo) - t.equal(Object.getOwnPropertySymbols((db.data.docs as DocumentsStore).docs).length, 1) + t.equal(Object.keys((db.data.docs as DocumentsStore).docs).length, 1) t.same( nestedExtraKeyDoc.unexpectedProperty, - (db.data.docs as DocumentsStore).docs[Symbol.for(insertedInfo)]!.unexpectedProperty, + (db.data.docs as DocumentsStore).docs[getInternalDocumentId(db.internalDocumentIDStore, insertedInfo)]!.unexpectedProperty, ) t.same( nestedExtraKeyDoc.tag.unexpectedNestedProperty, - ((db.data.docs as DocumentsStore).docs[Symbol.for(insertedInfo)]!.tag as unknown as Record) + ((db.data.docs as DocumentsStore).docs[getInternalDocumentId(db.internalDocumentIDStore, insertedInfo)]!.tag as unknown as Record) .unexpectedNestedProperty, ) @@ -462,7 +463,7 @@ t.test('insertMultiple method', t => { try { await insertMultiple(db, docs) - t.equal(Object.getOwnPropertySymbols((db.data.docs as DocumentsStore).docs).length, 4000) + t.equal(Object.keys((db.data.docs as DocumentsStore).docs).length, 4000) // eslint-disable-next-line no-empty } catch (_e) {} diff --git a/packages/orama/tests/serialization.test.ts b/packages/orama/tests/serialization.test.ts index 19184ee0e..7d336eecf 100644 --- a/packages/orama/tests/serialization.test.ts +++ b/packages/orama/tests/serialization.test.ts @@ -1,4 +1,5 @@ import t from 'tap' +import { getInternalDocumentId } from '../src/components/internal-document-id-store.js'; import type { Document } from '../src/types.js' import { Node as RadixNode } from '../src/trees/radix.js' import { create, insert, load, Result, save, search } from '../src/index.js' @@ -63,8 +64,8 @@ t.test('Edge getters', t => { const { docs } = await save(db) - t.strictSame((docs as DocumentsStore).docs[Symbol.for(doc1)], { name: 'John', age: 30 }) - t.strictSame((docs as DocumentsStore).docs[Symbol.for(doc2)], { name: 'Jane', age: 25 }) + t.strictSame((docs as DocumentsStore).docs[getInternalDocumentId(db.internalDocumentIDStore, doc1)], { name: 'John', age: 30 }) + t.strictSame((docs as DocumentsStore).docs[getInternalDocumentId(db.internalDocumentIDStore, doc2)], { name: 'Jane', age: 25 }) }) t.test('should correctly enable index setter', async t => { diff --git a/packages/orama/tests/snapshots/events.json b/packages/orama/tests/snapshots/events.json index 5c6d506d7..cbb3d135e 100644 --- a/packages/orama/tests/snapshots/events.json +++ b/packages/orama/tests/snapshots/events.json @@ -6,12 +6,12 @@ "id": "", "score": 4.744426329679039, "document": { - "date": "1809/03/13", - "description": "Peninsular War", + "date": "-89", + "description": "Social War:", "granularity": "year", "categories": { - "first": "January/March", - "second": "" + "first": "By place", + "second": "Roman Republic" } } }, @@ -19,12 +19,12 @@ "id": "", "score": 4.744426329679039, "document": { - "date": "1867/12/02", - "description": "Paraguayan War.", + "date": "-57", + "description": "Gallic Wars:", "granularity": "year", "categories": { - "first": "Ongoing", - "second": "" + "first": "By place", + "second": "Roman Republic" } } }, @@ -32,8 +32,8 @@ "id": "", "score": 4.744426329679039, "document": { - "date": "-89", - "description": "Social War:", + "date": "-55", + "description": "Gallic War", "granularity": "year", "categories": { "first": "By place", @@ -45,12 +45,12 @@ "id": "", "score": 4.744426329679039, "document": { - "date": "1914/12/24", - "description": " World War I:", + "date": "-54", + "description": "Gallic Wars", "granularity": "year", "categories": { - "first": "December", - "second": "" + "first": "By place", + "second": "Roman Republic" } } }, @@ -58,8 +58,8 @@ "id": "", "score": 4.744426329679039, "document": { - "date": "-57", - "description": "Gallic Wars:", + "date": "-53", + "description": "Parthian war:", "granularity": "year", "categories": { "first": "By place", @@ -71,8 +71,8 @@ "id": "", "score": 4.744426329679039, "document": { - "date": "-55", - "description": "Gallic War", + "date": "-53", + "description": "Gallic War:", "granularity": "year", "categories": { "first": "By place", @@ -84,8 +84,8 @@ "id": "", "score": 4.744426329679039, "document": { - "date": "-54", - "description": "Gallic Wars", + "date": "-48", + "description": "Civil War:", "granularity": "year", "categories": { "first": "By place", @@ -97,8 +97,8 @@ "id": "", "score": 4.744426329679039, "document": { - "date": "-53", - "description": "Parthian war:", + "date": "-47", + "description": "Civil War:", "granularity": "year", "categories": { "first": "By place", @@ -110,8 +110,8 @@ "id": "", "score": 4.744426329679039, "document": { - "date": "-53", - "description": "Gallic War:", + "date": "-46", + "description": "Civil War:", "granularity": "year", "categories": { "first": "By place", @@ -123,12 +123,12 @@ "id": "", "score": 4.744426329679039, "document": { - "date": "-48", - "description": "Civil War:", + "date": "1809/03/13", + "description": "Peninsular War", "granularity": "year", "categories": { - "first": "By place", - "second": "Roman Republic" + "first": "January/March", + "second": "" } } } @@ -141,12 +141,12 @@ "id": "", "score": 4.744426329679039, "document": { - "date": "-47", - "description": "Civil War:", + "date": "1867/12/02", + "description": "Paraguayan War.", "granularity": "year", "categories": { - "first": "By place", - "second": "Roman Republic" + "first": "Ongoing", + "second": "" } } }, @@ -154,12 +154,12 @@ "id": "", "score": 4.744426329679039, "document": { - "date": "-46", - "description": "Civil War:", + "date": "1914/12/24", + "description": " World War I:", "granularity": "year", "categories": { - "first": "By place", - "second": "Roman Republic" + "first": "December", + "second": "" } } }, @@ -180,12 +180,25 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "2003/02/05", - "description": "War in Darfur begins.", + "date": "-113", + "description": "War between the Celtiberians and the Romans.", "granularity": "year", "categories": { - "first": "February", - "second": "" + "first": "By place", + "second": "Roman Republic" + } + } + }, + { + "id": "", + "score": 4.087300377720357, + "document": { + "date": "-86", + "description": "First Mithridatic War", + "granularity": "year", + "categories": { + "first": "By place", + "second": "Roman Republic" } } }, @@ -253,7 +266,12 @@ "second": "" } } - }, + } + ] + }, + "should perform paginate search-page-3": { + "count": 2357, + "hits": [ { "id": "", "score": 4.087300377720357, @@ -266,12 +284,7 @@ "second": "" } } - } - ] - }, - "should perform paginate search-page-3": { - "count": 2357, - "hits": [ + }, { "id": "", "score": 4.087300377720357, @@ -363,19 +376,6 @@ } } }, - { - "id": "", - "score": 4.087300377720357, - "document": { - "date": "-113", - "description": "War between the Celtiberians and the Romans.", - "granularity": "year", - "categories": { - "first": "By place", - "second": "Roman Republic" - } - } - }, { "id": "", "score": 4.087300377720357, @@ -393,15 +393,15 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "-86", - "description": "First Mithridatic War", + "date": "1919/02/14", + "description": " The Polish-Soviet War begins.", "granularity": "year", "categories": { - "first": "By place", - "second": "Roman Republic" + "first": "February", + "second": "" } } } ] } -} +} \ No newline at end of file diff --git a/packages/orama/tests/sort.test.ts b/packages/orama/tests/sort.test.ts index a2fe91c73..c6602f499 100644 --- a/packages/orama/tests/sort.test.ts +++ b/packages/orama/tests/sort.test.ts @@ -24,8 +24,6 @@ t.test('search with sortBy', t => { }, }) - console.log(result); - t.strictSame( result.hits.map(d => d.id), [id5, id2, id1, id3, id4, id6],