# HG changeset patch # User Colin Clark # Date 1534167001 -3600 # Node ID 54ae25ba376b514ead490e8f145038ade06ffb98 # Parent e9e8e8b2afcef1fda9df487b5c73ff1e25c2a4b7 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. diff -r e9e8e8b2afce -r 54ae25ba376b doc/docbook/GuideImageSearchSearch.xml --- a/doc/docbook/GuideImageSearchSearch.xml Sun Aug 12 17:29:35 2018 +0100 +++ b/doc/docbook/GuideImageSearchSearch.xml Mon Aug 13 14:30:01 2018 +0100 @@ -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. + @@ -139,6 +145,16 @@ + Comment + + + The search will match if the file's Comments field contains the entered pattern. + Perl Compatible Regular Expressions + are used. + + + + Geocoded position diff -r e9e8e8b2afce -r 54ae25ba376b doc/docbook/GuideReference.xml --- a/doc/docbook/GuideReference.xml Sun Aug 12 17:29:35 2018 +0100 +++ b/doc/docbook/GuideReference.xml Mon Aug 13 14:30:01 2018 +0100 @@ -14,5 +14,6 @@ + diff -r e9e8e8b2afce -r 54ae25ba376b doc/docbook/GuideReferencePCRE.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/docbook/GuideReferencePCRE.xml Mon Aug 13 14:30:01 2018 +0100 @@ -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 -r e9e8e8b2afce -r 54ae25ba376b src/search.c --- a/src/search.c Sun Aug 12 17:29:35 2018 +0100 +++ b/src/search.c Mon Aug 13 14:30:01 2018 +0100 @@ -154,6 +154,7 @@ 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 @@ 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 @@ { 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 @@ 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_start(SearchData *sd) { + GError *error = NULL; + search_stop(sd); search_result_clear(sd); @@ -2475,6 +2479,20 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 -r e9e8e8b2afce -r 54ae25ba376b web/help/GuideFaq.html --- a/web/help/GuideFaq.html Sun Aug 12 17:29:35 2018 +0100 +++ b/web/help/GuideFaq.html Mon Aug 13 14:30:01 2018 +0100 @@ -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 -r e9e8e8b2afce -r 54ae25ba376b web/help/GuideImageSearchSearch.html --- a/web/help/GuideImageSearchSearch.html Sun Aug 12 17:29:35 2018 +0100 +++ b/web/help/GuideImageSearchSearch.html Mon Aug 13 14:30:01 2018 +0100 @@ -531,7 +531,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. +
File size
@@ -586,6 +592,14 @@
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 -r e9e8e8b2afce -r 54ae25ba376b web/help/GuideIndex.html --- a/web/help/GuideIndex.html Sun Aug 12 17:29:35 2018 +0100 +++ b/web/help/GuideIndex.html Mon Aug 13 14:30:01 2018 +0100 @@ -659,6 +659,9 @@
  • 13.13. Standards
  • +
  • +13.14. Perl Compatible Regular Expressions +
  • diff -r e9e8e8b2afce -r 54ae25ba376b web/help/GuideReference.html --- a/web/help/GuideReference.html Sun Aug 12 17:29:35 2018 +0100 +++ b/web/help/GuideReference.html Mon Aug 13 14:30:01 2018 +0100 @@ -443,6 +443,7 @@
  • UTC and Daylight Saving Time (DST)
  • Decoding Latitude and Longitude
  • Standards
  • +
  • Perl Compatible Regular Expressions
  • Frequently Asked Questions
  • @@ -496,6 +497,9 @@
  • 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 -r e9e8e8b2afce -r 54ae25ba376b web/help/GuideReferencePixbufLoaders.html --- a/web/help/GuideReferencePixbufLoaders.html Sun Aug 12 17:29:35 2018 +0100 +++ b/web/help/GuideReferencePixbufLoaders.html Mon Aug 13 14:30:01 2018 +0100 @@ -444,6 +444,7 @@
  • UTC and Daylight Saving Time (DST)
  • Decoding Latitude and Longitude
  • Standards
  • +
  • Perl Compatible Regular Expressions
  • Frequently Asked Questions
  • diff -r e9e8e8b2afce -r 54ae25ba376b web/help/GuideReferenceStandards.html --- a/web/help/GuideReferenceStandards.html Sun Aug 12 17:29:35 2018 +0100 +++ b/web/help/GuideReferenceStandards.html Mon Aug 13 14:30:01 2018 +0100 @@ -4,7 +4,7 @@ Standards - +