Files
omnivore/packages/api/src/utils/search.ts
2023-12-07 18:47:25 +08:00

15 lines
626 B
TypeScript

import { LiqeQuery, parse } from '@omnivore/liqe'
export const parseSearchQuery = (query: string): LiqeQuery => {
const searchQuery = query
.replace(/\W\s":/g, '')
.replace('in:subscription', 'has:subscriptions') // compatibility with old search
.replace('in:library', 'no:subscription') // compatibility with old search
// wrap the value behind colon in quotes if it's not already
.replace(/(\w+):("([^"]+)"|([^")\s]+))/g, '$1:"$3$4"')
// remove any quotes that are in the array value for example: label:"test","test2" -> label:"test,test2"
.replace(/","/g, ',')
return parse(searchQuery)
}