Improving quotes to allow "hyphenated-words"
This commit is contained in:
@@ -9,11 +9,10 @@ type Keywords = {
|
|||||||
} & { text: string[] }
|
} & { text: string[] }
|
||||||
|
|
||||||
export class Query {
|
export class Query {
|
||||||
query: Keywords & { exclude: Keywords }
|
query: Keywords & {
|
||||||
/**
|
exclude: Keywords
|
||||||
* @deprecated
|
}
|
||||||
*/
|
#inQuotes: string[]
|
||||||
extensions: string[] = []
|
|
||||||
|
|
||||||
constructor(text = '') {
|
constructor(text = '') {
|
||||||
if (settings.ignoreDiacritics) {
|
if (settings.ignoreDiacritics) {
|
||||||
@@ -44,7 +43,10 @@ export class Query {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.query = parsed
|
this.query = parsed
|
||||||
this.extensions = this.query.ext ?? []
|
|
||||||
|
// Get strings in quotes, and remove the quotes
|
||||||
|
this.#inQuotes =
|
||||||
|
text.match(/"([^"]+)"/g)?.map(o => o.replace(/"/g, '')) ?? []
|
||||||
}
|
}
|
||||||
|
|
||||||
public isEmpty(): boolean {
|
public isEmpty(): boolean {
|
||||||
@@ -62,7 +64,7 @@ export class Query {
|
|||||||
public segmentsToStr(): string {
|
public segmentsToStr(): string {
|
||||||
return this.query.text.join(' ')
|
return this.query.text.join(' ')
|
||||||
}
|
}
|
||||||
|
|
||||||
public getTags(): string[] {
|
public getTags(): string[] {
|
||||||
return this.query.text.filter(o => o.startsWith('#'))
|
return this.query.text.filter(o => o.startsWith('#'))
|
||||||
}
|
}
|
||||||
@@ -72,6 +74,11 @@ export class Query {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getExactTerms(): string[] {
|
public getExactTerms(): string[] {
|
||||||
return this.query.text.filter(o => o.split(' ').length > 1)
|
return [
|
||||||
|
...new Set([
|
||||||
|
...this.query.text.filter(o => o.split(' ').length > 1),
|
||||||
|
...this.#inQuotes,
|
||||||
|
]),
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user