Special-case 'me' values in search queries (#11043)
This commit is contained in:
@@ -47,30 +47,12 @@ export function countLines(str: string | undefined): number {
|
||||
return str.match(/\n/g)?.length ?? 0
|
||||
}
|
||||
|
||||
// Augments search query with additional syntax like `from:me`
|
||||
export function augmentSearchQuery(query: string, {did}: {did?: string}) {
|
||||
// Don't do anything if there's no DID
|
||||
if (!did) {
|
||||
return query
|
||||
}
|
||||
|
||||
// replace “smart quotes” with normal ones
|
||||
// iOS keyboard will add fancy unicode quotes, but only normal ones work
|
||||
query = query.replaceAll(/[“”]/g, '"')
|
||||
|
||||
// We don't want to replace substrings that are being "quoted" because those
|
||||
// are exact string matches, so what we'll do here is to split them apart
|
||||
|
||||
// Even-indexed strings are unquoted, odd-indexed strings are quoted
|
||||
const splits = query.split(/("(?:[^"\\]|\\.)*")/g)
|
||||
|
||||
return splits
|
||||
.map((str, idx) => {
|
||||
if (idx % 2 === 0) {
|
||||
return str.replaceAll(/(^|\s)from:me(\s|$)/g, `$1${did}$2`)
|
||||
}
|
||||
|
||||
return str
|
||||
})
|
||||
.join('')
|
||||
/**
|
||||
* Normalizes a raw search query for the backend. The iOS keyboard inserts smart
|
||||
* quotes, but only straight quotes work for exact-phrase matching. Operators
|
||||
* like `from:me` are passed through untouched - the backend resolves `me` to
|
||||
* the viewer.
|
||||
*/
|
||||
export function augmentSearchQuery(query: string) {
|
||||
return query.replaceAll(/[“”]/g, '"')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user