Skip to content

Commit

Permalink
fix: add missing function
Browse files Browse the repository at this point in the history
  • Loading branch information
AriTheElk committed Dec 16, 2024
1 parent e8ede5b commit 8232ea9
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readAndCompressImage } from 'browser-image-resizer'

import { AbstractIndexerNode, IndexerNode } from './backend/Indexer'
import { ROW_HEIGHT } from './constants'
import { queryTokens, ROW_HEIGHT } from './constants'

export const getSizeInKb = (size: number): number => {
return Math.round(size / 1024)
Expand Down Expand Up @@ -108,3 +108,31 @@ export const calculateGrid = (
}
return [0, 0]
}

/**
* Searches through a plaintext search query and
* returns all of the tokens contained in the query.
* Also returns the remaining query after removing
* all of the tokens.
*/
export const tokenizeSearchQuery = (query: string) => {
const tokens = query
.split(' ')
.map((token) => token.trim())
.filter(
(token) =>
token.includes(':') && queryTokens.includes(token.split(':')[0])
)
let remainingQuery = ''

for (const token of query.split(' ')) {
if (!tokens.includes(token)) {
remainingQuery += token + ' '
}
}

return {
queryTokens: tokens,
remainingQuery: remainingQuery.trim(),
}
}

0 comments on commit 8232ea9

Please sign in to comment.