Skip to content

Commit

Permalink
fix: enable search for ASNs below 100
Browse files Browse the repository at this point in the history
  • Loading branch information
JainAarjav committed Feb 5, 2025
1 parent d421be9 commit d7aa5d6
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/components/search/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ let loadingQueryRanks = false
const search = async (value, update) => {
loading.value = true
options.value = []
const asnRegex = /^(as)?(\d+)$/i
// Detect if input is AS followed by a number
const asnRegex = /^AS(\d+)$/i
const asnMatch = asnRegex.exec(value)
let prefixMatch
try {
Expand All @@ -99,8 +100,9 @@ const search = async (value, update) => {
}
}
if (asnMatch) {
// If input is AS followed by a number, search for ASNs
loadingQueryAS = true
queryAS(asnMatch.input).then((res) => {
queryAS(asnMatch[1]).then((res) => {
searchResponse(res, update)
loadingQueryAS = false
noResults(res, update)
Expand All @@ -113,6 +115,7 @@ const search = async (value, update) => {
noResults(res, update)
})
} else {
// General search for AS names, IXPs, prefixes, countries, etc.
mixedEntitySearch(value, update)
}
}
Expand Down Expand Up @@ -195,6 +198,7 @@ const queryAS = async (asn) => {
return res[0]
}
const queryPrefixes = async (value) => {
if (props.noPrefix) {
return []
Expand Down Expand Up @@ -317,13 +321,20 @@ const optimizeSearchResults = (res) => {
const filter = (value, update, abort) => {
activateSearch.value = true
if (value.length < MIN_CHARACTERS) {
if (value.length === 0) {
abort()
} else {
search(value, update)
return
}
const asnRegex = /^AS(\d+)$/i
if (value.length < MIN_CHARACTERS && !asnRegex.test(value)) {
abort()
return
}
search(value, update)
}
const paramExists = (param) => {
const params = route.params
if (param in params) {
Expand Down

0 comments on commit d7aa5d6

Please sign in to comment.