Skip to content

Commit

Permalink
make text indexing paths configurable, index definitions by default
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuels committed Aug 1, 2023
1 parent 64f7d2f commit 03e59ea
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { OntologyTerm } from '..'
function getStringAt(obj: Record<string, unknown>, path: string[]) {
let thing = obj
for (const key of path) {
thing = thing[key] as Record<string, unknown>
if (key in thing) {
thing = thing[key] as Record<string, unknown>
} else {
return
}
}
return String(thing)
}
Expand All @@ -29,9 +33,11 @@ export function getWords(node: OntologyDBNode, paths: string[][]) {
const wordSet = new Set<string>()
for (const path of paths) {
const text = getStringAt(node, path)
stringToWords(text).forEach((word) => {
wordSet.add(word)
})
if (text) {
stringToWords(text).forEach((word) => {
wordSet.add(word)
})
}
}
return wordSet
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function loadOboGraphJson(this: OntologyStore, db: Database) {
const nodeStore = tx.objectStore('nodes')
const fullTextIndexPaths = this.options.textIndexing?.indexPaths
? this.options.textIndexing?.indexPaths.map((p) => p.split('/'))
: [['lbl']]
: [['lbl'], ['meta', 'definition', 'val']]
for (const node of graph.nodes ?? []) {
if (isOntologyDBNode(node)) {
await nodeStore.add({
Expand Down
18 changes: 16 additions & 2 deletions packages/jbrowse-plugin-apollo/src/OntologyManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { autorun } from 'mobx'
import { Instance, addDisposer, getSnapshot, types } from 'mobx-state-tree'

import OntologyStore from './OntologyStore'
import OntologyStore, { OntologyStoreOptions } from './OntologyStore'
import { OntologyDBNode } from './OntologyStore/indexeddb-schema'

export { isDeprecated } from './OntologyStore/indexeddb-schema'
Expand All @@ -17,6 +17,7 @@ export const OntologyRecordType = types
name: types.string,
version: 'unversioned',
source: types.union(LocalPathLocation, UriLocation, BlobLocation),
options: types.frozen<OntologyStoreOptions>(),
})
.volatile((_self) => ({
dataStore: undefined as undefined | OntologyStore,
Expand All @@ -31,6 +32,7 @@ export const OntologyRecordType = types
self.name,
self.version,
getSnapshot(self.source),
self.options,
)
},
afterCreate() {
Expand Down Expand Up @@ -104,8 +106,14 @@ export const OntologyManagerType = types
name: string,
version: string,
source: Instance<typeof LocalPathLocation> | Instance<typeof UriLocation>,
options?: OntologyStoreOptions,
) {
const newlen = self.ontologies.push({ name, version, source })
const newlen = self.ontologies.push({
name,
version,
source,
options: options ?? {},
})
// access it immediately to fire its lifecycle hooks
// (see https://github.com/mobxjs/mobx-state-tree/issues/1665)
self.ontologies[newlen - 1].ping()
Expand Down Expand Up @@ -140,6 +148,12 @@ export const OntologyRecordConfiguration = ConfigurationSchema(
uri: 'http://example.com/myontology.json',
},
},
textIndexingPaths: {
type: 'frozen',
description:
'JSON paths for text fields that will be indexed for text searching',
defaultValue: ['lbl', 'meta/definition/val'],
},
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export function OntologyTermMultiSelect({
const label = option.lbl ?? '(no label)'
const matches = highlightMatch(label, inputValue, {
insideWords: true,
findAllOccurrences: true,
})
parts = highlightParse(label, matches)
return (
Expand Down
7 changes: 5 additions & 2 deletions packages/jbrowse-plugin-apollo/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,18 @@ function clientDataStoreFactory(
>[]

for (const ont of configuredOntologies || []) {
const [name, version, source] = [
const [name, version, source, indexPaths] = [
readConfObject(ont, 'name') as string,
readConfObject(ont, 'version') as string,
readConfObject(ont, 'source') as
| Instance<typeof LocalPathLocation>
| Instance<typeof UriLocation>,
readConfObject(ont, 'textIndexingPaths') as string[],
]
if (!ontologyManager.findOntology(name)) {
ontologyManager.addOntology(name, version, source)
ontologyManager.addOntology(name, version, source, {
textIndexing: { indexPaths },
})
}
}

Expand Down

0 comments on commit 03e59ea

Please sign in to comment.