Repository: oramasearch/orama (TypeScript)

Issue:
Updating Object.prototype causes search to fail
### Describe the bug

Adding a new property to Object.prototype causes search function to fail

### To Reproduce

1 - Import necessary functions of Orama(insert, search, create)
2 - Add a property to object prototype
3 - Create an example schema 
4 - Insert some data into it
5 - Search

Here is an example:

```js
import { insert, search, create } from '@orama/orama';

Object.prototype.justTesting = () => {};

const schema = {
    name: 'string',
};

const orama = await create({
    schema,
});

await insert(orama, {
    name: 'John Doe',
});

const result = await search(orama, {
    term: 'John Doe',
});

console.log(result);
```

Code above throws an error saying "TypeError: searchResult[key] is not iterable" and after some debugging we can clearly see the issue:

```js
    const { exact , tolerance  } = context.params;
    const searchResult = radixFind(node, {
        term,
        exact,
        tolerance
    });
    const ids = new Set();
    console.log(searchResult)
    for(const key in searchResult){
        console.log(key, searchResult[key])
        for (const id of searchResult[key]){
            ids.add(id);
        }
    }
    return context.index.calculateResultScores(context, index, prop, term, Array.from(ids));
```

Here is the [code snippet](https://github.com/oramasearch/orama/blob/main/packages/orama/src/components/index.ts#L492C8-L492C8) from Orama's source code that I took which caused the issue. I added some console.logs to see what was the problem and second console.log prints out: "justTesting [Function (anonymous)]" and that causes searchResult[key] being not iterable.


### Expected behavior

Search function should properly return a value without any issues even if Object.prototype has changed.

### Environment Info

```bash
OS: Windows 10 Version 22H2 OS Build 19045.2486
Node: v20.10.0
Orama: 2.0.0-beta.12 (also tried it with 1.0.0-beta.16 and got the same result)
```


### Affected areas

Search

### Additional context

_No response_


Discussion:
Fixed it with adding a one line code into the for loop. I will open a PR about this in a free time 😃
@SpongeBed81 awesome, thank you! Looking forward to the PR



Patch:
diff --git a/packages/orama/src/components/index.ts b/packages/orama/src/components/index.ts
index 720e3556c..349c13a09 100644
--- a/packages/orama/src/components/index.ts
+++ b/packages/orama/src/components/index.ts
@@ -57,7 +57,7 @@ import {
   searchByPolygon
 } from '../trees/bkd.js'
 
-import { convertDistanceToMeters, intersect, safeArrayPush } from '../utils.js'
+import { convertDistanceToMeters, intersect, safeArrayPush, getOwnProperty } from '../utils.js'
 import { BM25 } from './algorithms.js'
 import { getMagnitude } from './cosine-similarity.js'
 import { getInnerType, getVectorSize, isArrayType, isVectorType } from './defaults.js'
@@ -489,9 +489,13 @@ export async function search<T extends AnyOrama, ResultDocument = TypedDocument<
   const searchResult = radixFind(node, { term, exact, tolerance })
   const ids = new Set<InternalDocumentID>()
 
-  for (const key in searchResult) {
-    for (const id of searchResult[key]) {
-      ids.add(id)
+  for(const key in searchResult){
+    //skip keys inherited from prototype
+    const ownProperty = getOwnProperty(searchResult, key);
+    if(!ownProperty) continue;
+
+    for (const id of searchResult[key]){
+        ids.add(id);
     }
   }
 


Test patch:
diff --git a/packages/orama/tests/search.test.ts b/packages/orama/tests/search.test.ts
index 9419b6567..19d2e8e4e 100644
--- a/packages/orama/tests/search.test.ts
+++ b/packages/orama/tests/search.test.ts
@@ -794,6 +794,22 @@ t.test('fix-544', async t => {
   t.end()
 })
 
+t.test('fix-601', async t => {
+  const db = await create({
+    schema: {
+      name: 'string'
+    } as const
+  })
+
+  Object.prototype['examplePrototypeFunction'] = () => {};
+
+  await insert(db, { name: 'John Doe' });
+  const result = await search(db, { term: 'John Doe' });
+
+  t.equal(result.count, 1);
+  t.end()
+})
+
 async function createSimpleDB() {
   let i = 0
   const db = await create({