From 15637ceb5c85a161f8d102904c554fcfba6dc1ef Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Mon, 13 Aug 2018 14:30:01 +0100 Subject: [PATCH] Ref #624: Filter files by shell or regular expression pattern https://github.com/BestImageViewer/geeqie/issues/624 The File name (when "contains" is selected) and Comment items on the Search page use Perl Compatible Regular Expressions. Basic searches should be no different to current usage. --- doc/docbook/GuideImageSearchSearch.xml | 18 +- doc/docbook/GuideReference.xml | 1 + doc/docbook/GuideReferencePCRE.xml | 14 + src/search.c | 44 +- web/help/GuideFaq.html | 6 +- web/help/GuideImageSearchCache.html | 477 +++++++++++++++++ web/help/GuideImageSearchSearch.html | 16 +- web/help/GuideIndex.html | 3 + web/help/GuideReference.html | 4 + web/help/GuideReferenceCommandLine.html | 1 + web/help/GuideReferenceConfig.html | 1 + web/help/GuideReferenceDecodeLatLong.html | 1 + web/help/GuideReferenceKeyboardShortcuts.html | 1 + web/help/GuideReferenceLIRC.html | 1 + web/help/GuideReferenceLua.html | 1 + web/help/GuideReferenceMetadata.html | 1 + web/help/GuideReferencePCRE.html | 479 ++++++++++++++++++ web/help/GuideReferencePixbufLoaders.html | 1 + web/help/GuideReferenceStandards.html | 7 +- web/help/GuideReferenceSupportedFormats.html | 1 + web/help/GuideReferenceThumbnails.html | 1 + web/help/GuideReferenceUTC.html | 1 + web/help/GuideReferenceXmpExif.html | 1 + 23 files changed, 1069 insertions(+), 12 deletions(-) create mode 100644 doc/docbook/GuideReferencePCRE.xml create mode 100644 web/help/GuideImageSearchCache.html create mode 100644 web/help/GuideReferencePCRE.html diff --git a/doc/docbook/GuideImageSearchSearch.xml b/doc/docbook/GuideImageSearchSearch.xml index 8dddc1a3..fdf2d26e 100644 --- a/doc/docbook/GuideImageSearchSearch.xml +++ b/doc/docbook/GuideImageSearchSearch.xml @@ -72,7 +72,13 @@ File name - The search will match if the entered text appears within the file name, or if the text exactly matches the file name, depending on the method selected from the drop down menu. The text comparison can be made to be case sensitive by enabling the Match case checkbox. + + The search will match if the entered text appears within the file name, or if the text exactly matches the file name, depending on the method selected from the drop down menu. The text comparison can be made to be case sensitive by enabling the Match case checkbox. + + If "contains" is selected, + Perl Compatible Regular Expressions + are used. + @@ -137,6 +143,16 @@ The search will match if the file's associated keywords match all, match any, or exclude the entered keywords, depending on the method selected from the drop down menu. Keywords can be separated with a space, comma, or tab character. + + + Comment + + + The search will match if the file's Comments field contains the entered pattern. + Perl Compatible Regular Expressions + are used. + + Geocoded position diff --git a/doc/docbook/GuideReference.xml b/doc/docbook/GuideReference.xml index 9b45b3a6..2b5a60a6 100644 --- a/doc/docbook/GuideReference.xml +++ b/doc/docbook/GuideReference.xml @@ -14,5 +14,6 @@ + diff --git a/doc/docbook/GuideReferencePCRE.xml b/doc/docbook/GuideReferencePCRE.xml new file mode 100644 index 00000000..66d97bed --- /dev/null +++ b/doc/docbook/GuideReferencePCRE.xml @@ -0,0 +1,14 @@ + +
+ Perl Compatible Regular Expressions + + The Filename and Comment sections on the search window use + Perl Compatible Regular Expressions + . In general use there are a number of differences to the wildcard expansion used on the command line: + + Use "." and not "?" for a single character. + Use "abc.*ghk" and not "abc*ghk" for multiple characters + Use "\." to represent the dot in a file extension + + +
diff --git a/src/search.c b/src/search.c index 577eb7cf..662dc5af 100644 --- a/src/search.c +++ b/src/search.c @@ -154,6 +154,7 @@ struct _SearchData FileData *search_dir_fd; gboolean search_path_recurse; gchar *search_name; + GRegex *search_name_regex; gboolean search_name_match_case; gint64 search_size; gint64 search_size_end; @@ -172,6 +173,7 @@ struct _SearchData CacheData *search_similarity_cd; GList *search_keyword_list; gchar *search_comment; + GRegex *search_comment_regex; gint search_rating; gint search_rating_end; gboolean search_comment_match_case; @@ -1915,13 +1917,13 @@ static gboolean search_file_next(SearchData *sd) { if (sd->search_name_match_case) { - match = (strstr(fd->name, sd->search_name) != NULL); + match = g_regex_match(sd->search_name_regex, fd->name, 0, NULL); } else { /* sd->search_name is converted in search_start() */ gchar *haystack = g_utf8_strdown(fd->name, -1); - match = (strstr(haystack, sd->search_name) != NULL); + match = g_regex_match(sd->search_name_regex, haystack, 0, NULL); g_free(haystack); } } @@ -2112,11 +2114,11 @@ static gboolean search_file_next(SearchData *sd) if (sd->match_comment == SEARCH_MATCH_CONTAINS) { - match = (strstr(comment, sd->search_comment) != NULL); + match = g_regex_match(sd->search_comment_regex, comment, 0, NULL); } else if (sd->match_comment == SEARCH_MATCH_NONE) { - match = (strstr(comment, sd->search_comment) == NULL); + match = !g_regex_match(sd->search_comment_regex, comment, 0, NULL); } g_free(comment); } @@ -2459,6 +2461,8 @@ static void search_similarity_load_done_cb(ImageLoader *il, gpointer data) static void search_start(SearchData *sd) { + GError *error = NULL; + search_stop(sd); search_result_clear(sd); @@ -2475,6 +2479,20 @@ static void search_start(SearchData *sd) sd->search_name = tmp; } + if(sd->search_name_regex) + { + g_regex_unref(sd->search_name_regex); + } + + sd->search_name_regex = g_regex_new(sd->search_name, 0, 0, &error); + if (error) + { + log_printf("Error: could not compile regular expression %s\n%s\n", sd->search_name, error->message); + g_error_free(error); + error = NULL; + sd->search_name_regex = g_regex_new("", 0, 0, NULL); + } + if (!sd->search_comment_match_case) { /* convert to lowercase here, so that this is only done once per search */ @@ -2483,6 +2501,20 @@ static void search_start(SearchData *sd) sd->search_comment = tmp; } + if(sd->search_comment_regex) + { + g_regex_unref(sd->search_comment_regex); + } + + sd->search_comment_regex = g_regex_new(sd->search_comment, 0, 0, &error); + if (error) + { + log_printf("Error: could not compile regular expression %s\n%s\n", sd->search_comment, error->message); + g_error_free(error); + error = NULL; + sd->search_comment_regex = g_regex_new("", 0, 0, NULL); + } + sd->search_count = 0; sd->search_total = 0; @@ -3032,7 +3064,9 @@ static void search_window_destroy_cb(GtkWidget *widget, gpointer data) file_data_unref(sd->search_dir_fd); g_free(sd->search_name); + g_regex_unref(sd->search_name_regex); g_free(sd->search_comment); + g_regex_unref(sd->search_comment_regex); g_free(sd->search_similarity_path); string_list_free(sd->search_keyword_list); @@ -3149,6 +3183,7 @@ void search_new(FileData *dir_fd, FileData *example_file) gtk_widget_show(combo); pref_checkbox_new_int(hbox, _("Match case"), sd->search_name_match_case, &sd->search_name_match_case); + gtk_widget_set_tooltip_text(GTK_WIDGET(combo), "When set to \"contains\", this field uses Perl Compatible Regular Expressions.\ne.g. use \n.*\\.jpg\n and not \n*.jpg\n\nSee the Help file."); /* Search for file size */ hbox = menu_choice(sd->box_search, &sd->check_size, &sd->menu_size, @@ -3257,6 +3292,7 @@ void search_new(FileData *dir_fd, FileData *example_file) gtk_widget_show(sd->entry_comment); pref_checkbox_new_int(hbox, _("Match case"), sd->search_comment_match_case, &sd->search_comment_match_case); + gtk_widget_set_tooltip_text(GTK_WIDGET(sd->entry_comment), "This field uses Perl Compatible Regular Expressions.\ne.g. use \nabc.*ghk\n and not \nabc*ghk\n\nSee the Help file."); /* Search for image rating */ hbox = menu_choice(sd->box_search, &sd->check_rating, &sd->menu_rating, diff --git a/web/help/GuideFaq.html b/web/help/GuideFaq.html index cc0e79a5..63410380 100644 --- a/web/help/GuideFaq.html +++ b/web/help/GuideFaq.html @@ -3,7 +3,7 @@ Frequently Asked Questions - + + + + + +
+

Caching Data For Searches

+ +

+ Searching large numbers of files for similarity can take significant cpu time. Part of this is the time to compute the similarity matrix for each file. +

+ If the + Cache Thumbnails + option is selected in Preferences/General, the similarity matrix and the checksum will also be cached. This will reduce the time needed for future searches. +
If you frequently search on similarity and your images are in a tree arrangement under a single point, initiating a one-time search on similarity from the top of the tree will generate the similarity data for all images.
+

Similarity data are stored in a folder hierachy that mirrors the location of the source images. The data have the same name as the original appended by the file extension .sim.

+

+ The root of the hierachy is: +

+

$XDG_CACHE_HOME/geeqie/thumbnails/
+ or, if $XDG_CACHE_HOME is not defined: +
$HOME/.cache/geeqie/thumbnails/
+

+

+

+

+
+ + + diff --git a/web/help/GuideImageSearchSearch.html b/web/help/GuideImageSearchSearch.html index 7cdadcca..5017c37a 100644 --- a/web/help/GuideImageSearchSearch.html +++ b/web/help/GuideImageSearchSearch.html @@ -531,7 +531,13 @@ dd.answer div.label { float: left; }
File name
-
The search will match if the entered text appears within the file name, or if the text exactly matches the file name, depending on the method selected from the drop down menu. The text comparison can be made to be case sensitive by enabling the Match case checkbox.
+
+ The search will match if the entered text appears within the file name, or if the text exactly matches the file name, depending on the method selected from the drop down menu. The text comparison can be made to be case sensitive by enabling the Match case checkbox. +

+ If "contains" is selected, + Perl Compatible Regular Expressions + are used. +
File size
@@ -585,6 +591,14 @@ dd.answer div.label { float: left; } Keywords
The search will match if the file's associated keywords match all, match any, or exclude the entered keywords, depending on the method selected from the drop down menu. Keywords can be separated with a space, comma, or tab character.
+
+ Comment +
+
+ The search will match if the file's Comments field contains the entered pattern. + Perl Compatible Regular Expressions + are used. +
Geocoded position
diff --git a/web/help/GuideIndex.html b/web/help/GuideIndex.html index b0e02302..a6ba7241 100644 --- a/web/help/GuideIndex.html +++ b/web/help/GuideIndex.html @@ -659,6 +659,9 @@ dd.answer div.label { float: left; }
  • 13.13. Standards
  • +
  • +13.14. Perl Compatible Regular Expressions +
  • diff --git a/web/help/GuideReference.html b/web/help/GuideReference.html index a2537db7..860b5832 100644 --- a/web/help/GuideReference.html +++ b/web/help/GuideReference.html @@ -443,6 +443,7 @@ dd.answer div.label { float: left; }
  • UTC and Daylight Saving Time (DST)
  • Decoding Latitude and Longitude
  • Standards
  • +
  • Perl Compatible Regular Expressions
  • Frequently Asked Questions
  • @@ -496,6 +497,9 @@ dd.answer div.label { float: left; }
  • 13.13. Standards
  • +
  • +13.14. Perl Compatible Regular Expressions +
  • + +
    +

    Perl Compatible Regular Expressions

    + +

    + The Filename and Comment sections on the search window use + Perl Compatible Regular Expressions + . In general use there are a number of differences to the wildcard expansion used on the command line: +

      +
    • Use "." and not "?" for a single character.
    • +
    • Use "abc.*ghk" and not "abc*ghk" for multiple characters
    • +
    • Use "\." to represent the dot in a file extension
    • +
    +

    +
    + + + diff --git a/web/help/GuideReferencePixbufLoaders.html b/web/help/GuideReferencePixbufLoaders.html index eaf24b17..a5b54a08 100644 --- a/web/help/GuideReferencePixbufLoaders.html +++ b/web/help/GuideReferencePixbufLoaders.html @@ -444,6 +444,7 @@ dd.answer div.label { float: left; }
  • UTC and Daylight Saving Time (DST)
  • Decoding Latitude and Longitude
  • Standards
  • +
  • Perl Compatible Regular Expressions
  • Frequently Asked Questions
  • diff --git a/web/help/GuideReferenceStandards.html b/web/help/GuideReferenceStandards.html index 0911b71e..0dc8d4d9 100644 --- a/web/help/GuideReferenceStandards.html +++ b/web/help/GuideReferenceStandards.html @@ -4,7 +4,7 @@ Standards - +