mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
core: properly escape fts query
This commit is contained in:
@@ -42,16 +42,17 @@ export default class Lookup {
|
|||||||
notes(query: string, noteIds?: string[]) {
|
notes(query: string, noteIds?: string[]) {
|
||||||
return this.toSearchResults(async (limit) => {
|
return this.toSearchResults(async (limit) => {
|
||||||
const db = this.db.sql() as Kysely<DatabaseSchemaWithFTS>;
|
const db = this.db.sql() as Kysely<DatabaseSchemaWithFTS>;
|
||||||
|
query = query.replace(/"/, '""');
|
||||||
const result = await db
|
const result = await db
|
||||||
.with("matching", (eb) =>
|
.with("matching", (eb) =>
|
||||||
eb
|
eb
|
||||||
.selectFrom("content_fts")
|
.selectFrom("content_fts")
|
||||||
.where("data", "match", query)
|
.where("data", "match", `"${query}"`)
|
||||||
.select(["noteId as id", "rank"])
|
.select(["noteId as id", "rank"])
|
||||||
.unionAll(
|
.unionAll(
|
||||||
eb
|
eb
|
||||||
.selectFrom("notes_fts")
|
.selectFrom("notes_fts")
|
||||||
.where("title", "match", query)
|
.where("title", "match", `"${query}"`)
|
||||||
// add 10 weight to title
|
// add 10 weight to title
|
||||||
.select(["id", sql.raw<number>(`rank * 10`).as("rank")])
|
.select(["id", sql.raw<number>(`rank * 10`).as("rank")])
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user