Skip to content

Commit

Permalink
Fix typos (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
szepeviktor authored Jul 10, 2023
1 parent 6ab76c2 commit 212d6c7
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 39 deletions.
10 changes: 5 additions & 5 deletions packages/docs/pages/internals/components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,18 @@ To customize the index used by Orama, provide an object which has at least the f
* `id`: The ID of the document being inserted.
* `token`: The token.
* `calculateResultScores`: A function that calculates the score for the results of the current search. It should be typically invoked within `search`. It receives the following arguments:
* `context`: A search context with various useful informations about the search.
* `context`: A search context with various useful information about the search.
* `index`: The index.
* `prop`: The property search.
* `term`: The term used to search.
* `ids`: The list of documents IDs matched by the search.
* `search`: A function that search documents int index data and returns matching IDs with scores. It receives the following arguments:
* `context`: A search context with various useful informations about the search.
* `context`: A search context with various useful information about the search.
* `index`: The index.
* `prop`: The property to search.
* `term`: The term to search.
* `searchByWhereClause`: A function that searchs in boolean and numeric indexes and returns a list of matching IDs. It receives the following arguments:
* `context`: A search context with various useful informations about the search.
* `searchByWhereClause`: A function that searches in boolean and numeric indexes and returns a list of matching IDs. It receives the following arguments:
* `context`: A search context with various useful information about the search.
* `index`: The index.
* `filters`: An object where keys are the properties to match and the values are search operators as described in the [filters](usage/search/filters) page.
* `getSearchableProperties`: A function that returns a list of all searchable properties in the index. It receives the index as the only argument.
Expand Down Expand Up @@ -283,7 +283,7 @@ The sorter component is used to store the documents in Orama.
To customize the documents sort used by Orama, provide an object which has at least the following properties:
* `create`: A function that receives the schema and the configutation and returns a sorter.
* `create`: A function that receives the schema and the configuration and returns a sorter.
* `insert`: A function that inserts a new document in the sorter. It receives the following arguments:
* `sorter`: The sorter returned by the `create` function.
* `prop`: The property that it is currently considered.
Expand Down
2 changes: 1 addition & 1 deletion packages/orama/src/components/algorithms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function prioritizeTokenScores(arrays: TokenScore[][], boost: number, thr
return results.slice(0, shortestArrayLength)
}

// If the theshold is between 0 and 1, we will return all the results that contains at least the threshold of search terms
// If the threshold is between 0 and 1, we will return all the results that contains at least the threshold of search terms
// For example, if threshold is 0.5, we will return all the results that contains at least 50% of the search terms
// (fuzzy match with a minimum threshold)
const thresholdLength = Math.ceil((threshold * 100 * results.length) / 100)
Expand Down
32 changes: 16 additions & 16 deletions packages/orama/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface Index extends OpaqueIndex {
searchableProperties: string[]
searchablePropertiesWithTypes: Record<string, SearchableType>
frequencies: FrequencyMap
tokenOccurrencies: Record<string, Record<string, number>>
tokenOccurrences: Record<string, Record<string, number>>
avgFieldLength: Record<string, number>
fieldLengths: Record<string, Record<string, number | undefined>>
}
Expand Down Expand Up @@ -94,12 +94,12 @@ export async function insertTokenScoreParameters(

index.frequencies[prop][id]![token] = tf

if (!(token in index.tokenOccurrencies[prop])) {
index.tokenOccurrencies[prop][token] = 0
if (!(token in index.tokenOccurrences[prop])) {
index.tokenOccurrences[prop][token] = 0
}

// increase a token counter that may not yet exist
index.tokenOccurrencies[prop][token] = (index.tokenOccurrencies[prop][token] ?? 0) + 1
index.tokenOccurrences[prop][token] = (index.tokenOccurrences[prop][token] ?? 0) + 1
}

export async function removeDocumentScoreParameters(
Expand All @@ -115,7 +115,7 @@ export async function removeDocumentScoreParameters(
}

export async function removeTokenScoreParameters(index: Index, prop: string, token: string): Promise<void> {
index.tokenOccurrencies[prop][token]--
index.tokenOccurrences[prop][token]--
}

export async function calculateResultScores<I extends OpaqueIndex, D extends OpaqueDocumentStore, AggValue>(
Expand All @@ -130,11 +130,11 @@ export async function calculateResultScores<I extends OpaqueIndex, D extends Opa
// Exact fields for TF-IDF
const avgFieldLength = index.avgFieldLength[prop]
const fieldLengths = index.fieldLengths[prop]
const oramaOccurrencies = index.tokenOccurrencies[prop]
const oramaOccurrences = index.tokenOccurrences[prop]
const oramaFrequencies = index.frequencies[prop]

// oramaOccurrencies[term] can be undefined, 0, string, or { [k: string]: number }
const termOccurrencies = typeof oramaOccurrencies[term] === 'number' ? oramaOccurrencies[term] ?? 0 : 0
// oramaOccurrences[term] can be undefined, 0, string, or { [k: string]: number }
const termOccurrences = typeof oramaOccurrences[term] === 'number' ? oramaOccurrences[term] ?? 0 : 0

const scoreList: TokenScore[] = []

Expand All @@ -146,7 +146,7 @@ export async function calculateResultScores<I extends OpaqueIndex, D extends Opa

const bm25 = BM25(
tf,
termOccurrencies,
termOccurrences,
context.docsCount,
fieldLengths[id]!,
avgFieldLength,
Expand All @@ -170,7 +170,7 @@ export async function create(
searchableProperties: [],
searchablePropertiesWithTypes: {},
frequencies: {},
tokenOccurrencies: {},
tokenOccurrences: {},
avgFieldLength: {},
fieldLengths: {},
}
Expand Down Expand Up @@ -200,7 +200,7 @@ export async function create(
index.indexes[path] = radixCreate()
index.avgFieldLength[path] = 0
index.frequencies[path] = {}
index.tokenOccurrencies[path] = {}
index.tokenOccurrences[path] = {}
index.fieldLengths[path] = {}
break
default:
Expand Down Expand Up @@ -363,7 +363,7 @@ export async function search<D extends OpaqueDocumentStore, AggValue>(
prop: string,
term: string,
): Promise<TokenScore[]> {
if (!(prop in index.tokenOccurrencies)) {
if (!(prop in index.tokenOccurrences)) {
return []
}

Expand Down Expand Up @@ -497,7 +497,7 @@ export async function load<R = unknown>(raw: R): Promise<Index> {
searchableProperties,
searchablePropertiesWithTypes,
frequencies,
tokenOccurrencies,
tokenOccurrences,
avgFieldLength,
fieldLengths,
} = raw as Index
Expand All @@ -507,7 +507,7 @@ export async function load<R = unknown>(raw: R): Promise<Index> {
searchableProperties,
searchablePropertiesWithTypes,
frequencies,
tokenOccurrencies,
tokenOccurrences,
avgFieldLength,
fieldLengths,
}
Expand All @@ -519,7 +519,7 @@ export async function save<R = unknown>(index: Index): Promise<R> {
searchableProperties,
searchablePropertiesWithTypes,
frequencies,
tokenOccurrencies,
tokenOccurrences,
avgFieldLength,
fieldLengths,
} = index
Expand All @@ -529,7 +529,7 @@ export async function save<R = unknown>(index: Index): Promise<R> {
searchableProperties,
searchablePropertiesWithTypes,
frequencies,
tokenOccurrencies,
tokenOccurrences,
avgFieldLength,
fieldLengths,
} as R
Expand Down
8 changes: 4 additions & 4 deletions packages/orama/src/components/sorter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async function create(_: Orama, schema: Schema, config?: SorterConfig): Promise<
function stringSort(value: SortValue, language: string | undefined, d: [string, SortValue]): boolean {
return (d[1] as string).localeCompare(value as string, language) > 0
}
function numerSort(value: SortValue, d: [string, SortValue]): boolean {
function numberSort(value: SortValue, d: [string, SortValue]): boolean {
return (d[1] as number) > (value as number)
}
function booleanSort(value: SortValue, d: [string, SortValue]): boolean {
Expand All @@ -111,7 +111,7 @@ async function insert(
predicate = stringSort.bind(null, value, language)
break
case 'number':
predicate = numerSort.bind(null, value)
predicate = numberSort.bind(null, value)
break
case 'boolean':
predicate = booleanSort.bind(null, value)
Expand All @@ -128,7 +128,7 @@ async function insert(
}
s.docs[id] = index

// Increment position for the greather documents
// Increment position for the greater documents
const orderedDocsLength = s.orderedDocs.length
for (let i = index + 1; i < orderedDocsLength; i++) {
const docId = s.orderedDocs[i][0]
Expand All @@ -145,7 +145,7 @@ async function remove(sorter: Sorter, prop: string, id: string) {
const index = s.docs[id]
delete s.docs[id]

// Decrement position for the greather documents
// Decrement position for the greater documents
const orderedDocsLength = s.orderedDocs.length
for (let i = index + 1; i < orderedDocsLength; i++) {
const docId = s.orderedDocs[i][0]
Expand Down
4 changes: 2 additions & 2 deletions packages/orama/src/methods/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function remove(orama: Orama, id: string, language?: string, skipHo

for (const prop of indexableProperties) {
const value = values[prop]
// The document doens't contain the key
// The document doesn't contain the key
if (typeof value === 'undefined') {
continue
}
Expand Down Expand Up @@ -61,7 +61,7 @@ export async function remove(orama: Orama, id: string, language?: string, skipHo
const sortableProperties = await orama.sorter.getSortableProperties(orama.data.sorting)
const sortableValues = await orama.getDocumentProperties(doc, sortableProperties)
for (const prop of sortableProperties) {
// The document doens't contain the key
// The document doesn't contain the key
if (typeof sortableValues[prop] === 'undefined') {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions packages/orama/src/trees/radix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ export function find(root: Node, { term, exact, tolerance }: FindParams): FindRe
// find the common prefix between two words ex: prime and primate = prim
const commonPrefix = getCommonPrefix(edgeLabel, termSubstring)
const commonPrefixLength = commonPrefix.length
// if the common prefix lenght is equal to edgeLabel lenght (the node subword) it means they are a match
// if the common prefix length is equal to edgeLabel length (the node subword) it means they are a match
// if the common prefix is equal to the term means it is contained in the node
if (commonPrefixLength !== edgeLabel.length && commonPrefixLength !== termSubstring.length) {
// if tolerance is set we take the current node as the closest
if (tolerance) break
return {}
}

// skip the subword lenght and check the next divergent character
// skip the subword length and check the next divergent character
i += rootChildCurrentChar.subWord.length - 1
// navigate into the child node
root = rootChildCurrentChar
Expand Down
12 changes: 6 additions & 6 deletions packages/orama/tests/filters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,30 @@ t.test('filters', t => {
await t.rejects(search(db, {
term: 'coffee',
where: {
unknonwField: '5'
unknownField: '5'
},
}), {
message: 'Unknown filter property "unknonwField"',
message: 'Unknown filter property "unknownField"',
code: 'UNKNOWN_FILTER_PROPERTY',
})

await t.rejects(search(db, {
term: 'coffee',
where: {
unknonwField: { gt: '5' } as unknown as string
unknownField: { gt: '5' } as unknown as string
},
}), {
message: 'Unknown filter property "unknonwField"',
message: 'Unknown filter property "unknownField"',
code: 'UNKNOWN_FILTER_PROPERTY',
})

await t.rejects(search(db, {
term: 'coffee',
where: {
unknonwField: true as unknown as string
unknownField: true as unknown as string
},
}), {
message: 'Unknown filter property "unknonwField"',
message: 'Unknown filter property "unknownField"',
code: 'UNKNOWN_FILTER_PROPERTY',
})

Expand Down
2 changes: 1 addition & 1 deletion packages/orama/tests/group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ t.test('search with groupBy', async t => {
t.end()
})

t.test('with custom aggragator', async t => {
t.test('with custom aggregator', async t => {
interface Doc extends Document {
type: string
design: string
Expand Down
2 changes: 1 addition & 1 deletion packages/orama/tests/insert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ t.test('insertMultiple method', t => {
t.end()
})

t.test('should suport batch insert of documents', async t => {
t.test('should support batch insert of documents', async t => {
t.plan(2)

const db = await create({
Expand Down
2 changes: 1 addition & 1 deletion packages/orama/tests/sort.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ t.test('disabled', async t => {
t.end()
})

t.only('search wth sortBy should be consistent ignoring the insert order', async t => {
t.only('search with sortBy should be consistent ignoring the insert order', async t => {
const docs = [
{ id: '5' },
{ id: '2', number: 5 },
Expand Down

1 comment on commit 212d6c7

@vercel
Copy link

@vercel vercel bot commented on 212d6c7 Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.