Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Low-hanging perf improvements in highlighting code #196

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/purple-ghosts-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'contexture-elasticsearch': patch
---

Low-hanging perf improvements in elasticsearch highlighting
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import { pickSafeNumbers } from '../../utils/futil.js'
import { groupStats } from './groupStatUtils.js'

// [1, 2, 3] -> [{to: 1}, {from: 1, to: 2}, {from: 2, to: 3}, {from: 3}]
let boundariesToRanges = _.flow(
F.mapIndexed((to, i, list) => F.compactObject({ from: list[i - 1], to })),
(arr) => F.push({ from: _.last(arr).to }, arr)
)
let boundariesToRanges = (boundaries) => {
let ranges = F.mapIndexed(
(to, i, list) => F.compactObject({ from: list[i - 1], to }),
boundaries
)
return [...ranges, { from: _.last(ranges)?.to }]
}

let drilldownToRange = (drilldown) => {
let [gte, lt] = _.split('-', drilldown)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ let getFieldSubFields = (field) =>
/**
* Returns object of all subfields in a schema.
*/
let getSchemaSubFields = (schema) =>
F.reduceIndexed(
(acc, field, path) =>
F.mergeOn(
acc,
_.mapKeys((k) => `${path}.${k}`, getFieldSubFields(field))
),
{},
schema.fields
)
let getSchemaSubFields = _.memoize((schema) => {
let acc = {}
for (let path in schema.fields) {
let subFields = getFieldSubFields(schema.fields[path])
for (let k in subFields) {
acc[`${path}.${k}`] = subFields[k]
}
}
return acc
}, _.get('elasticsearch.index'))

/**
* Returns object of all group fields and their subfields in a schema.
Expand Down Expand Up @@ -145,13 +145,14 @@ export let getAllHighlightFields = _.memoize((schema) => {
})
}, _.get('elasticsearch.index'))

let collectKeysAndValues = (f, coll) =>
F.reduceTree()(
(acc, val, key) =>
f(val) ? F.push(val, acc) : f(key) ? F.push(key, acc) : acc,
[],
coll
)
let collectKeysAndValues = (predicate, coll) => {
let acc = []
F.walk()((val, key) => {
if (predicate(val)) acc.push(val)
else if (predicate(key)) acc.push(key)
})(coll)
return acc
}

let blobConfiguration = {
fragment_size: 250,
Expand Down
Loading