Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/commands/search.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ nnote search

.. code-block:: text

nnote search <query> [-d <dir>]
nnote search <query> [-d <dir>] [-n <limit>]

Search notes by title and content. Results are ranked by relevance: exact
title matches score highest, followed by prefix/substring/fuzzy title matches,
then content hits. Matched terms are highlighted in the output.

Use ``-n`` / ``--limit`` to cap the number of results shown.

.. code-block:: bash

nnote search meeting
nnote search budget -d work
nnote search todo -n 5

::

Expand Down
11 changes: 10 additions & 1 deletion nnote/commands/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
help="Scope search to a subdirectory",
shell_complete=complete_directories,
)
def search(query, directory):
@click.option(
"-n",
"--limit",
default=None,
type=click.IntRange(min=1),
help="Maximum number of results to show",
)
def search(query, directory, limit):
"""Search notes by title and content."""
config = Config.load()

Expand All @@ -28,6 +35,8 @@ def search(query, directory):
raise click.ClickException(f"Directory not found: {root}")

results = search_notes(root, query)
if limit is not None:
results = results[:limit]

if not results:
click.echo("No notes found.")
Expand Down