diff --git a/packages/orama/src/trees/radix.ts b/packages/orama/src/trees/radix.ts index f4790aeec..773c7936c 100644 --- a/packages/orama/src/trees/radix.ts +++ b/packages/orama/src/trees/radix.ts @@ -1,12 +1,9 @@ -import { syncBoundedLevenshtein } from '../components/levenshtein.js' -import { Nullable } from '../types.js' -import { getOwnProperty, syncUniqueId } from '../utils.js' +import { syncBoundedLevenshtein } from "../components/levenshtein.js"; +import { getOwnProperty } from "../utils.js"; export interface Node { - id: string key: string subWord: string - parent: Nullable children: Record docs: string[] end: boolean @@ -29,7 +26,6 @@ function serialize(this: Node): object { } function updateParent(node: Node, parent: Node): void { - node.parent = parent.id node.word = parent.word + node.subWord } @@ -111,10 +107,8 @@ function getCommonPrefix(a: string, b: string) { export function create(end = false, subWord = '', key = ''): Node { const node = { - id: syncUniqueId(), key, subWord, - parent: null, children: {}, docs: [], end, diff --git a/packages/orama/src/utils.ts b/packages/orama/src/utils.ts index 21d0cff0c..c43804e6c 100644 --- a/packages/orama/src/utils.ts +++ b/packages/orama/src/utils.ts @@ -88,11 +88,6 @@ export async function uniqueId(): Promise { return `${baseId}-${lastId++}` } -// This is only used internally, keep in sync with the previous one -export function syncUniqueId(): string { - return `${baseId}-${lastId++}` -} - export function getOwnProperty(object: Record, property: string): T | undefined { // Checks if `hasOwn` method is defined avoiding errors with older Node.js versions if (Object.hasOwn === undefined) { diff --git a/packages/orama/tests/snapshots/events.json b/packages/orama/tests/snapshots/events.json index 5c6d506d7..89fb90455 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,12 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "2003/02/05", - "description": "War in Darfur begins.", + "date": "-86", + "description": "First Mithridatic War", "granularity": "year", "categories": { - "first": "February", - "second": "" + "first": "By place", + "second": "Roman Republic" } } }, @@ -193,12 +193,12 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "630", - "description": "The Byzantine-Arab Wars begin.", + "date": "1447/07/15", + "description": "The Albanian-Venetian War of 1447-1448.", "granularity": "year", "categories": { - "first": "By place", - "second": "Byzantine Empire" + "first": "Date unknown", + "second": "" } } }, @@ -206,12 +206,12 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "632/01/27", - "description": "Ridda Wars begins", + "date": "1470/10/30", + "description": "Start of the Anglo-Hanseatic War.", "granularity": "year", "categories": { - "first": "By place", - "second": "Asia" + "first": "Date unknown", + "second": "" } } }, @@ -219,12 +219,12 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "941", - "description": "The Rus'-Byzantine War is fought.", + "date": "1522/12/20", + "description": "The Habsburg-Valois Wars begin.", "granularity": "year", "categories": { - "first": "By place", - "second": "Asia" + "first": "Date unknown", + "second": "" } } }, @@ -232,12 +232,12 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "988", - "description": "Rus'–Byzantine War", + "date": "1558/01/22", + "description": " Beginning of the Livonian War.", "granularity": "year", "categories": { - "first": "By place", - "second": "Europe" + "first": "January/June", + "second": "" } } }, @@ -245,11 +245,11 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "1043/10/31", - "description": "Rus'-Byzantine War (1043).", + "date": "1728/10/20", + "description": "The Meerkat–Mongoose war.", "granularity": "year", "categories": { - "first": "", + "first": "In fiction", "second": "" } } @@ -258,8 +258,8 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "1447/07/15", - "description": "The Albanian-Venetian War of 1447-1448.", + "date": "1830/12/20", + "description": "The Java War ends.", "granularity": "year", "categories": { "first": "Date unknown", @@ -276,11 +276,11 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "1470/10/30", - "description": "Start of the Anglo-Hanseatic War.", + "date": "1857/04/04", + "description": " End of the Anglo-Persian War.", "granularity": "year", "categories": { - "first": "Date unknown", + "first": "April/June", "second": "" } } @@ -289,11 +289,11 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "1522/12/20", - "description": "The Habsburg-Valois Wars begin.", + "date": "1861/04/27", + "description": " American Civil War:", "granularity": "year", "categories": { - "first": "Date unknown", + "first": "April/June", "second": "" } } @@ -302,11 +302,11 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "1558/01/22", - "description": " Beginning of the Livonian War.", + "date": "1879/01/11", + "description": " The Anglo-Zulu War begins.", "granularity": "year", "categories": { - "first": "January/June", + "first": "January/March", "second": "" } } @@ -315,11 +315,11 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "1728/10/20", - "description": "The Meerkat–Mongoose war.", + "date": "1919/02/14", + "description": " The Polish-Soviet War begins.", "granularity": "year", "categories": { - "first": "In fiction", + "first": "February", "second": "" } } @@ -328,11 +328,11 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "1830/12/20", - "description": "The Java War ends.", + "date": "1939/03/23", + "description": " The Slovak-Hungarian War begins.", "granularity": "year", "categories": { - "first": "Date unknown", + "first": "March", "second": "" } } @@ -341,11 +341,11 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "1857/04/04", - "description": " End of the Anglo-Persian War.", + "date": "2003/02/05", + "description": "War in Darfur begins.", "granularity": "year", "categories": { - "first": "April/June", + "first": "February", "second": "" } } @@ -354,12 +354,12 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "1861/04/27", - "description": " American Civil War:", + "date": "630", + "description": "The Byzantine-Arab Wars begin.", "granularity": "year", "categories": { - "first": "April/June", - "second": "" + "first": "By place", + "second": "Byzantine Empire" } } }, @@ -367,12 +367,12 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "-113", - "description": "War between the Celtiberians and the Romans.", + "date": "632/01/27", + "description": "Ridda Wars begins", "granularity": "year", "categories": { "first": "By place", - "second": "Roman Republic" + "second": "Asia" } } }, @@ -380,12 +380,12 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "1879/01/11", - "description": " The Anglo-Zulu War begins.", + "date": "941", + "description": "The Rus'-Byzantine War is fought.", "granularity": "year", "categories": { - "first": "January/March", - "second": "" + "first": "By place", + "second": "Asia" } } }, @@ -393,15 +393,15 @@ "id": "", "score": 4.087300377720357, "document": { - "date": "-86", - "description": "First Mithridatic War", + "date": "988", + "description": "Rus'–Byzantine War", "granularity": "year", "categories": { "first": "By place", - "second": "Roman Republic" + "second": "Europe" } } } ] } -} +} \ No newline at end of file