Skip to content

Commit

Permalink
Merge branch 'ft-search-note-id' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-lag committed Feb 3, 2022
2 parents 615b073 + e387dbf commit 081c496
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 58 deletions.
57 changes: 42 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ backlinks: [ ]
Notes can be searched with the subcommand `brn search` or inside the TUI mode using the `/` shortcut:

~~~shell
brn search my-first
$ brn search my-first
~~~

This can result in for example:
Expand All @@ -311,55 +311,82 @@ This can result in for example:
T20200629000001 random note name #my-first-tag
T20200629000002 some other note #my-first-tag
T20200629000003 some other random note #my-first-tag-2
T20200629000004 my-first-interesting-note #my-first-tag
T20200718000005 my-first-note
T20210629000004 my-first-interesting-note #my-first-tag
T20210718000005 my-first-note
~~~

You can see that the first 3 results were found because of their tag `my-first-tag`. The fourth one was found because of its name and its tag. In this case the tag is also displayed. The last result was found only because of its name. As the tags of this note don't matter in this case they aren't displayed here either.

If you only want to search for tags, then you can put a `#` in front of the search text:
If you only want to search for tags, then you can put a `#` in front of the search text. Note that the search text must be quoted this time as the shell would recognise the search text as a comment otherwise:

~~~shell
brn search #my-first
$ brn search "#my-first"
~~~

This will result in:

~~~shell
~~~
T20200629000001 random note name #my-first-tag
T20200629000002 some other note #my-first-tag
T20200629000003 some other random note #my-first-tag-2
T20200629000004 my-first-interesting-note #my-first-tag
T20210629000004 my-first-interesting-note #my-first-tag
~~~

As you can see the note `my-first-note` isn't displayed anymore, as it doesn't have any tag that contains the text `my-first`.

You can also combine different search requirements with `&&`. On the commandline you need to quote the search text as it now includes spaces:
You can also combine different search requirements with `&&`. Note that you need to quote the search text now not only because of the `#` but also because it now includes spaces:

~~~shell
brn search "#my-first && random"
$ brn search "#my-first && random"
~~~

This will result in:

~~~shell
~~~
T20200629000001 random note name #my-first-tag
T20200629000003 some random note #my-first-tag-2
~~~

As you can see now there are only results which have a tag containing `my-first` and either a tag or a note name containing `random`.
As you can see now there are only results which have a tag containing `my-first` and either a tag, a note name or note ID containing `random`.

You can also filter the results based on things you don't want inside your results with `!`:

~~~shell
brn search "#my-first && !random"
$ brn search "#my-first && !random"
~~~

This will result in:

~~~shell
~~~
T20200629000002 some other note #my-first-tag
T20200629000004 my-first-interesting-note #my-first-tag
T20210629000004 my-first-interesting-note #my-first-tag
~~~

Now all results that include `random` in their note name, note ID or in any of their tags aren't displayed.

The specified search text also always searches the note IDs. As the note ID contains the timestamp of its creation this can be very useful. For example if you want to see all notes that were created in July 2021:

~~~
$ brn search 202107
~~~

This will result in:

~~~
T20210718000005 my-first-note
J20210703000032 some journal written in july
~~~

You can also filter based on note type:

~~~
$ brn search T202107
~~~

This will result in:

~~~
T20210718000005 my-first-note
~~~

Now all results that include `random` in their note name or in any of their tags aren't displayed.
Note that the journal now doesn't appear as the note is not a Topic-note but a Journal-note.
16 changes: 8 additions & 8 deletions src/brn_tui/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::brn_tui::input_mode::InputMode;
use crate::database::Database;
use crate::note_property::NoteProperty;
use crate::note_type::NoteType;
use crate::notes::Notes;
use crate::note_utility::NoteUtility;
use crate::settings::Settings;

use clipboard::{ ClipboardProvider, ClipboardContext };
Expand Down Expand Up @@ -74,13 +74,13 @@ impl BrnTui {
tui_data.input_mode = InputMode::Add;
},
KeyCode::Char('d') | KeyCode::Esc => {
let note_list = Notes::get(100);
let note_list = NoteUtility::get(100);
tui_data.note_list.replace_items_with(note_list);
tui_data.note_list.select(Some(0));
tui_data.note_list_title = String::from("List");
},
KeyCode::Char('h') => {
let note_history = Notes::get_note_history(settings);
let note_history = NoteUtility::get_note_history(settings);
tui_data.note_list.replace_items_with(note_history.iter().map(|m| m.note_name.clone()).collect());
tui_data.note_list.select(Some(0));
tui_data.note_list_title = String::from("History");
Expand Down Expand Up @@ -119,7 +119,7 @@ impl BrnTui {
let confirmation_validator = Regex::new("^[Yy]$").unwrap();
if confirmation_validator.is_match(&tui_data.edit_text.get_content_text()) {
if let Some(selected_note) = tui_data.note_list.selected_item() {
if let Err(error) = Notes::remove(selected_note, &settings.notes_dir) {
if let Err(error) = NoteUtility::remove(selected_note, &settings.notes_dir) {
tui_data.message = error;
}
}
Expand Down Expand Up @@ -258,7 +258,7 @@ impl BrnTui {
fn show_note_content_preview(tui_data: &mut TuiData, settings: &mut Settings) {
if let Some(selected_note_name) = &tui_data.note_list.selected_item() {
if let Some(note_id) = Database::get_note_id_where(NoteProperty::NoteName, selected_note_name) {
match Notes::get_content_of_note(&note_id, settings) {
match NoteUtility::get_content_of_note(&note_id, settings) {
Ok(note_content) => {
tui_data.note_content_preview = note_content;
}
Expand Down Expand Up @@ -290,7 +290,7 @@ impl BrnTui {
}

fn execute_search(tui_data: &mut TuiData, settings: &mut Settings) {
let search_results = Notes::search(&tui_data.search_text.get_content_text())
let search_results = NoteUtility::search(&tui_data.search_text.get_content_text())
.iter()
.map(|m| {
match Database::get_note_where_id(&m.note_id) {
Expand All @@ -311,7 +311,7 @@ impl BrnTui {
"T" | "t" | _ => NoteType::Topic,
};

match Notes::add(tui_data.note_name_cache.as_str(), note_type, settings) {
match NoteUtility::add(tui_data.note_name_cache.as_str(), note_type, settings) {
Ok(None) => (),
Ok(Some(note_id)) => {
BrnTui::open_note(&note_id, terminal, tui_data, settings);
Expand All @@ -327,7 +327,7 @@ impl BrnTui {
DisableMouseCapture
).unwrap();

match Notes::open(&note_id, settings) {
match NoteUtility::open(&note_id, settings) {
Ok(None) => (),
Ok(Some(message)) => tui_data.message = "INFO: ".to_string() + &message,
Err(message) => tui_data.message = "ERROR: ".to_string() + &message,
Expand Down
4 changes: 2 additions & 2 deletions src/brn_tui/tui_data.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::notes::Notes;
use crate::note_utility::NoteUtility;
use crate::brn_tui::stateful_list::StatefulList;
use crate::brn_tui::input_mode::InputMode;
use crate::brn_tui::input_string::InputString;
Expand All @@ -17,7 +17,7 @@ pub struct TuiData {
impl Default for TuiData {
fn default() -> TuiData {
let mut tui_data = TuiData {
note_list: StatefulList::with_items(Notes::get(100)),
note_list: StatefulList::with_items(NoteUtility::get(100)),
note_content_preview: String::default(),
message: String::default(),
search_text: InputString::from("/"),
Expand Down
32 changes: 16 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ mod message;
mod note_property;
mod note_tagging;
mod note_type;
mod note_utility;
mod note;
mod notes;
mod settings;
mod brn_tui;
mod note_metadata;
Expand All @@ -18,7 +18,7 @@ use directory::Directory;
use message::Message;
use note_property::NoteProperty;
use note_type::NoteType;
use notes::Notes;
use note_utility::NoteUtility;
use settings::Settings;
use brn_tui::main::BrnTui;

Expand Down Expand Up @@ -212,7 +212,7 @@ fn exec_list_command(matches: &ArgMatches, settings: &mut Settings) {
if !Directory::is_zettelkasten_dir(&settings.notes_dir, false) {
return;
}
Notes::list(matches.value_of("count").unwrap_or("100").parse().unwrap_or(100));
NoteUtility::list(matches.value_of("count").unwrap_or("100").parse().unwrap_or(100));
}

fn exec_open_command(matches: &ArgMatches, settings: &mut Settings) {
Expand All @@ -224,12 +224,12 @@ fn exec_open_command(matches: &ArgMatches, settings: &mut Settings) {
let result;
match Database::get_note_id_where(NoteProperty::NoteName, note_name) {
Some(note_id) => {
result = Notes::open(&note_id, settings);
result = NoteUtility::open(&note_id, settings);
}
None => {
// Maybe the note id was given instead of the name
let note_id = note_name;
result = Notes::open(&note_id, settings);
result = NoteUtility::open(&note_id, settings);
}
};

Expand All @@ -246,25 +246,25 @@ fn exec_search_command(matches: &ArgMatches, settings: &mut Settings) {
}
let search_string = matches.value_of("search-string").unwrap_or_default();

let search_results = Notes::search(search_string);
Notes::print_search_results(search_results)
let search_results = NoteUtility::search(search_string);
NoteUtility::print_search_results(search_results)
}

fn exec_random_command(_matches: &ArgMatches, settings: &mut Settings) {
if !Directory::is_zettelkasten_dir(&settings.notes_dir, false) {
return;
}

Notes::open_random_note(settings);
NoteUtility::open_random_note(settings);
}

fn exec_history_command(_matches: &ArgMatches, settings: &mut Settings) {
if !Directory::is_zettelkasten_dir(&settings.notes_dir, false) {
return;
}

let note_history = Notes::get_note_history(settings);
Notes::print_note_list(note_history);
let note_history = NoteUtility::get_note_history(settings);
NoteUtility::print_note_list(note_history);
}

fn exec_add_command(matches: &ArgMatches, settings: &mut Settings) {
Expand All @@ -283,10 +283,10 @@ fn exec_add_command(matches: &ArgMatches, settings: &mut Settings) {
note_type = NoteType::Topic;
}

match Notes::add(note_name, note_type, settings) {
match NoteUtility::add(note_name, note_type, settings) {
Ok(None) => (),
Ok(Some(note_id)) => {
match Notes::open(&note_id, settings) {
match NoteUtility::open(&note_id, settings) {
Ok(None) => (),
Ok(Some(message)) => Message::warning(&message),
Err(error) => Message::error(&error),
Expand All @@ -303,7 +303,7 @@ fn exec_rm_command(matches: &ArgMatches, settings: &mut Settings) {

let note_name = matches.value_of("name").unwrap_or_default();

if let Err(error) = Notes::remove(note_name, &settings.notes_dir) {
if let Err(error) = NoteUtility::remove(note_name, &settings.notes_dir) {
Message::error(&error);
}
}
Expand All @@ -313,7 +313,7 @@ fn exec_update_db_command(_matches: &ArgMatches, settings: &mut Settings) {
return;
}

if let Err(error) = Notes::update_db_for_all_notes_in_project_folder(settings) {
if let Err(error) = NoteUtility::update_db_for_all_notes_in_project_folder(settings) {
Message::error(&error);
}
}
Expand All @@ -324,7 +324,7 @@ fn exec_get_name_command(matches: &ArgMatches, settings: &mut Settings) {
}

let note_id = matches.value_of("id").unwrap_or_default();
Notes::print_note_name_of(note_id);
NoteUtility::print_note_name_of(note_id);
}

fn exec_get_file_name_command(matches: &ArgMatches, settings: &mut Settings) {
Expand All @@ -333,5 +333,5 @@ fn exec_get_file_name_command(matches: &ArgMatches, settings: &mut Settings) {
}

let note_id = matches.value_of("id").unwrap_or_default();
Notes::print_file_name_of(note_id);
NoteUtility::print_file_name_of(note_id);
}
Loading

0 comments on commit 081c496

Please sign in to comment.