Skip to content

Commit

Permalink
Match exact tags in search.
Browse files Browse the repository at this point in the history
refs gh-326
  • Loading branch information
xwmx committed Jul 13, 2024
1 parent ab4b63c commit 3212efb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
14 changes: 12 additions & 2 deletions nb
Original file line number Diff line number Diff line change
Expand Up @@ -17141,7 +17141,12 @@ _search() {
local __and_query=
for __and_query in "${_and_queries[@]:-}"
do
[[ -n "${__and_query:-}" ]] || continue
[[ -n "${__and_query:-}" ]] || continue

if [[ "${_and_query:-}" =~ ^\# ]]
then
_and_query="${_and_query}$"
fi

if ((${#_or_queries[@]}))
then
Expand All @@ -17150,7 +17155,12 @@ _search() {
local __or_query=
for __or_query in "${_or_queries[@]:-}"
do
[[ -n "${__or_query:-}" ]] || continue
[[ -n "${__or_query:-}" ]] || continue

if [[ "${__or_query:-}" =~ ^\# ]]
then
__or_query="${__or_query}$"
fi

_or_query_string="${_or_query_string}|${__or_query}"
done
Expand Down
16 changes: 7 additions & 9 deletions test/search-tags.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

load test_helper

# tags ########################################################################

@test "'search -t tag1 --and -t tag2,'#tag3' exits with status 0 and prints matches as an AND query." {
{
"${_NB}" init
Expand All @@ -12,7 +10,7 @@ load test_helper
"${_NB}" add "File Two.md" --content "Content two. #tag1"
"${_NB}" add "File Three.md" --content "Content three. tag1 #tag2"
"${_NB}" add "File Four.md" --content "Content #tag1 four. #tag2"
"${_NB}" add "File Five.md" --content "Content five."
"${_NB}" add "File Five.md" --content "Content five. #tag3ButNotReally #tag4"
"${_NB}" add "File Six.md" --content "Content six. #tag2"
"${_NB}" add "File Seven.md" --content "Content #tag2 Seven. #tag3 #tag1"
}
Expand Down Expand Up @@ -41,7 +39,7 @@ load test_helper
"${_NB}" add "File Two.md" --content "Content two. #tag1"
"${_NB}" add "File Three.md" --content "Content three. tag1 #tag2"
"${_NB}" add "File Four.md" --content "Content #tag1 four. #tag2"
"${_NB}" add "File Five.md" --content "Content five."
"${_NB}" add "File Five.md" --content "Content five. #tag3ButNotReally #tag4"
"${_NB}" add "File Six.md" --content "Content six. #tag2"
"${_NB}" add "File Seven.md" --content "Content #tag2 Seven. #tag1"
}
Expand Down Expand Up @@ -100,7 +98,7 @@ load test_helper
"${_NB}" add "File Two.md" --content "Content two. #tag1"
"${_NB}" add "File Three.md" --content "Content three. tag1"
"${_NB}" add "File Four.md" --content "Content four. #tag1"
"${_NB}" add "File Five.md" --content "Content five."
"${_NB}" add "File Five.md" --content "Content five. #tag3ButNotReally"
"${_NB}" add "File Six.md" --content "Content six. #tag2"
}

Expand Down Expand Up @@ -138,7 +136,7 @@ load test_helper
"${_NB}" add "File Two.md" --content "Content two. #tag1"
"${_NB}" add "File Three.md" --content "Content three. tag1 #tag2"
"${_NB}" add "File Four.md" --content "Content #tag1 four. #tag2"
"${_NB}" add "File Five.md" --content "Content five."
"${_NB}" add "File Five.md" --content "Content five. #tag3ButNotReally #tag4"
"${_NB}" add "File Six.md" --content "Content six. #tag2"
"${_NB}" add "File Seven.md" --content "Content #tag2 Seven. #tag1"
}
Expand Down Expand Up @@ -172,7 +170,7 @@ load test_helper
"${_NB}" add "File Two.md" --content "Content two. #tag1"
"${_NB}" add "File Three.md" --content "Content three. tag1 #tag2"
"${_NB}" add "File Four.md" --content "Content #tag1 four. #tag2"
"${_NB}" add "File Five.md" --content "Content five."
"${_NB}" add "File Five.md" --content "Content five. #tag3ButNotReally #tag4"
"${_NB}" add "File Six.md" --content "Content six. #tag2"
"${_NB}" add "File Seven.md" --content "Content #tag2 Seven. #tag1"
}
Expand Down Expand Up @@ -206,7 +204,7 @@ load test_helper
"${_NB}" add "File Two.md" --content "Content two. #tag1"
"${_NB}" add "File Three.md" --content "Content three. tag1 #tag2"
"${_NB}" add "File Four.md" --content "Content #tag1 four. #tag2"
"${_NB}" add "File Five.md" --content "Content five."
"${_NB}" add "File Five.md" --content "Content five. #tag3ButNotReally #tag4"
"${_NB}" add "File Six.md" --content "Content six. #tag2"
"${_NB}" add "File Seven.md" --content "Content #tag2 Seven. #tag1"
}
Expand Down Expand Up @@ -240,7 +238,7 @@ load test_helper
"${_NB}" add "File Two.md" --content "Content two. #tag1"
"${_NB}" add "File Three.md" --content "Content three. tag1 #tag2"
"${_NB}" add "File Four.md" --content "Content #tag1 four. #tag2"
"${_NB}" add "File Five.md" --content "Content five."
"${_NB}" add "File Five.md" --content "Content five. #tag3ButNotReally #tag4"
"${_NB}" add "File Six.md" --content "Content six. #tag2"
"${_NB}" add "File Seven.md" --content "Content #tag2 Seven. #tag1"
}
Expand Down

0 comments on commit 3212efb

Please sign in to comment.