| 128 | } |
| 129 | |
| 130 | func doQuery(ctx context.DnoteCtx, query, bookName string) (*sql.Rows, error) { |
| 131 | db := ctx.DB |
| 132 | |
| 133 | sql := `SELECT |
| 134 | notes.rowid, |
| 135 | books.label AS book_label, |
| 136 | snippet(note_fts, 0, '<dnotehl>', '</dnotehl>', '...', 28) |
| 137 | FROM note_fts |
| 138 | INNER JOIN notes ON notes.rowid = note_fts.rowid |
| 139 | INNER JOIN books ON notes.book_uuid = books.uuid |
| 140 | WHERE note_fts MATCH ?` |
| 141 | args := []interface{}{query} |
| 142 | |
| 143 | if bookName != "" { |
| 144 | sql = fmt.Sprintf("%s AND books.label = ?", sql) |
| 145 | args = append(args, bookName) |
| 146 | } |
| 147 | |
| 148 | rows, err := db.Query(sql, args...) |
| 149 | |
| 150 | return rows, err |
| 151 | } |
| 152 | |
| 153 | func newRun(ctx context.DnoteCtx) infra.RunEFunc { |
| 154 | return func(cmd *cobra.Command, args []string) error { |