Skip to content

Commit

Permalink
Avoid performing a text index search if input looks like a locstring (#…
Browse files Browse the repository at this point in the history
…2960)

* Perform a refname navigation shortcut if it looks like a locstring

* Some small code simplifications

* Handle case where inputted strings are like chr1:FEATID

* Add comment
  • Loading branch information
cmdcolin authored May 19, 2022
1 parent 4fbed2d commit c3b9b3e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,26 @@ const ImportForm = observer(({ model }: { model: LGV }) => {
}
let trackId = option.getTrackId()
let location = input || option.getLocation() || ''
const [ref, rest] = location.split(':')
const allRefs = assembly?.allRefNames || []
try {
if (assembly?.allRefNames?.includes(location)) {
// instead of querying text-index, first:
// - check if input matches a refname directly
// - or looks like locstring
// then just navigate as if it were a locstring
if (
allRefs.includes(location) ||
(allRefs.includes(ref) &&
rest !== undefined &&
!Number.isNaN(parseInt(rest, 10)))
) {
model.navToLocString(location, selectedAsm)
} else {
const results = await fetchResults(input, 'exact')
if (results && results.length > 1) {
if (results.length > 1) {
model.setSearchResults(results, input.toLowerCase())
return
} else if (results?.length === 1) {
} else if (results.length === 1) {
location = results[0].getLocation()
trackId = results[0].getTrackId()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,35 @@ function SearchBox({
)
}

// gets a string as input, or use stored option results from previous query,
// then re-query and
// 1) if it has multiple results: pop a dialog
// 2) if it's a single result navigate to it
// 3) else assume it's a locstring and navigate to it
async function handleSelectedRegion(option: BaseResult) {
let trackId = option.getTrackId()
let location = option.getLocation()
const label = option.getLabel()
const [ref, rest] = location.split(':')
const allRefs = assembly?.allRefNames || []
try {
if (assembly?.allRefNames?.includes(location)) {
model.navToLocString(location)
// instead of querying text-index, first:
// - check if input matches a refName directly
// - or looks like locString
// then just navigate as if it were a locString
if (
allRefs.includes(location) ||
(allRefs.includes(ref) &&
rest !== undefined &&
!Number.isNaN(parseInt(rest, 10)))
) {
model.navToLocString(location, assemblyName)
} else {
const results = await fetchResults(label, 'exact')
if (results && results.length > 1) {
if (results.length > 1) {
model.setSearchResults(results, label.toLowerCase())
return
} else if (results?.length === 1) {
} else if (results.length === 1) {
location = results[0].getLocation()
trackId = results[0].getTrackId()
}
Expand Down

0 comments on commit c3b9b3e

Please sign in to comment.