Skip to content

Commit

Permalink
make MIN_SEARCH_LENGTH a configurable parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourgreens committed Jun 17, 2024
1 parent 3529a35 commit 3d63f73
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import PropTypes from 'prop-types'
import { useTranslation } from 'next-i18next'
import { useState } from 'react'

/*
Tune this value to determine when a search term
is long enough to use Panoptes full-text search.
*/
const MIN_SEARCH_LENGTH = 3;

function SelectCollection ({
collections = [],
disabled = false,
Expand All @@ -30,16 +36,14 @@ function SelectCollection ({
await onSearch({
favorite: false,
current_user_roles: 'owner,collaborator,contributor',
search: search.length > 3 ? search : undefined
search: search.length > MIN_SEARCH_LENGTH ? search : undefined
})
setSearchText(search.toLowerCase())
setSearchText(search)
}

const ignorePanoptesFullTextSearch = searchText.length < 4

function collectionNameFilter(collection) {
const displayNameLowerCase = collection.display_name.toLowerCase()
return displayNameLowerCase.includes(searchText)
return displayNameLowerCase.includes(searchText.toLowerCase())
}

function collectionLabel(collection) {
Expand All @@ -49,7 +53,9 @@ function SelectCollection ({
return `${collection.display_name} (${collection.links.owner.display_name})`
}

const options = ignorePanoptesFullTextSearch ? collections.filter(collectionNameFilter) : collections
const options = searchText.length > MIN_SEARCH_LENGTH
? collections
: collections.filter(collectionNameFilter)


return (
Expand Down

0 comments on commit 3d63f73

Please sign in to comment.