How to replace parts of search string automatically before launching the search?

Discussion related to "Everything" 1.5 Alpha.
Post Reply
Raindrops
Posts: 247
Joined: Sat Jan 21, 2023 10:04 am

How to replace parts of search string automatically before launching the search?

Post by Raindrops »

When I find a download on any website (e.g. Google scholar, World Bank), I first check whether I already have that file with me.

I use the following method for this check:
1. Select the filename on the web page
2. Press CTRL+C
3. Press CTRL+SpaceBar to launch Everything
4. Press CTRL+SHFT+V

While this works normally, it fails to find the matching file in many cases, because I have shortened many long-winded terms in file names for the sake of better readability.

(Reason: Research papers tend to have a very long verbose title, which is difficult to read.)

Here are a few shorthand I use:
  • Constructed wetlands -> CW
  • Sewage Treatment Plant -> STP
  • Horizontal subsurface filter -> HSSF
  • Wastewater -> WW
  • groundwater -> GW
Can Everything find matching file names by handling all these shorthand rules?
It should be able to substitute all long terms with their shorthand versions, and then search in my HDDs for a matching name.
void
Developer
Posts: 16670
Joined: Fri Oct 16, 2009 11:31 pm

Re: How to replace parts of search string automatically before launching the search?

Post by void »

Short answer: No.

Long answer: Yes, with complex filtering.

Please consider adding the following filter:
  • In Everything, from the Search menu, click Add to filters....
  • Change the Name to: My Shorthand Filter
  • Change the Search to:

    Code: Select all

    #[regexreplace:#[regexreplace:#[regexreplace:#[regexreplace:#[regexreplace:search:,\bConstructed wetlands\b,CW#]:,\bSewage Treatment Plant\b,STP#]:,\bHorizontal subsurface filter\b,HSSF#]:,\bWastewater\b,WW#]:,\bgroundwater\b,GW#]:
    
  • Change the Macro to: shorthand<search>
  • Click OK.
Please activate this filter from the Search menu, Filter bar (View -> Filters), right clicking the status bar, filter macro or filter keyboard shortcut.



A Synonyms list is on my TODO list.
Raindrops
Posts: 247
Joined: Sat Jan 21, 2023 10:04 am

Re: How to replace parts of search string automatically before launching the search?

Post by Raindrops »

Thanks!

This workaround is fine for me (it will suffice till we get the synonyms feature).

However, I would like to be able to compose this filter freely, because there are many more shorthand terms.

I tried to figure out the construction, but faced an issue: Why are the [regexreplace: commands nested, instead of being ANDed?

I imagined this command to have this form:
Replace (A with A') .AND. (B with B') .AND. (C with C')

I am using AND here because more than one shorthand terms may be used in a given filename.
If I use OR, the filter will replace only one string, and leave out the rest.

Could you please point to a guide for this composition?

Thanks in advance!
void
Developer
Posts: 16670
Joined: Fri Oct 16, 2009 11:31 pm

Re: How to replace parts of search string automatically before launching the search?

Post by void »

I forgot to mention the filter needs a macro so it knows what term to use to expand the current search:
Please change the Macro to: shorthand<search>

This filter takes the entire search and applies several word replacements.

The regex replacements for each shorthand word must be nested, not ANDed or ORed.
There should only be one reference to the current search (search:) and you will only want one output string (the shorthand replaced string).

[regex-replace:]
Filter Functions
Raindrops
Posts: 247
Joined: Sat Jan 21, 2023 10:04 am

Re: How to replace parts of search string automatically before launching the search?

Post by Raindrops »

@Chris

IMHO this topic is complex enough to warrant your step-by-step tutorial!
Thanks in advance!
Raindrops
Posts: 247
Joined: Sat Jan 21, 2023 10:04 am

Re: How to replace parts of search string automatically before launching the search?

Post by Raindrops »

void wrote: Fri Mar 03, 2023 4:10 am Please consider adding the following filter:
  • In Everything, from the Search menu, click Add to filters....
  • Change the Name to: My Shorthand Filter
  • Change the Search to:

    Code: Select all

    #[regexreplace:#[regexreplace:#[regexreplace:#[regexreplace:#[regexreplace:search:,\bConstructed wetlands\b,CW#]:,\bSewage Treatment Plant\b,STP#]:,\bHorizontal subsurface filter\b,HSSF#]:,\bWastewater\b,WW#]:,\bgroundwater\b,GW#]:
    
  • Change the Macro to: shorthand<search>
  • Click OK.
Please activate this filter from the Search menu, Filter bar (View -> Filters), right clicking the status bar, filter macro or filter keyboard shortcut.
I composed this filter, and applied it.
Then I entered "sewage treatment plant" in the search bar.
I expected Everything to search for "STP" instead of "sewage treatment plant".
But Everything still searches for the longhand string, and not for the shorthand.

I tried to switch filters between this filter and the default "Everything" filter.
There is no difference in search results.

BTW I need the "find" part of this replacement action to be case-insensitive.
So should I be using the RegEx expressions such as the following?
<C|c>onstructed <W|w>etland
nod5
Posts: 38
Joined: Fri Aug 19, 2016 9:12 pm

Re: How to replace parts of search string automatically before launching the search?

Post by nod5 »

While waiting for built in synonyms it is pretty easy to do this kind of replacement with an AutoHotkey script.

Code: Select all

#Requires AutoHotkey v2
Synonyms := Map("sewage treatment plant", "STP"
              , "Constructed wetlands", "CW"
              , "Horizontal subsurface filter", "HSSF")

;hotkey Windows+V when Everything is active substitutes words and then pastes the modified clipboard text
#HotIf WinActive("ahk_class EVERYTHING")
#v::
{
    For Long, Short in Synonyms
        A_Clipboard := StrReplace(A_Clipboard, Long, Short)
    Send("^v")
}

Off topic, kind of: Lots of other niche feature requests for Everything 1.5 are also easy to DIY via scripts. I have a feeling that @void is perhaps too accomodating towards feature request ideas, making the todo list for 1.5 grow and grow and pushing the date for a 1.5 beta and then stable release further and further away... Gotta save some stuff for v1.6! ;)
void
Developer
Posts: 16670
Joined: Fri Oct 16, 2009 11:31 pm

Re: How to replace parts of search string automatically before launching the search?

Post by void »

(C|c)onstructed (W|w)etland

-or-

Code: Select all

#[regexreplace:#[regexreplace:#[regexreplace:#[regexreplace:#[regexreplace:search:,(?i)\bConstructed wetlands\b,CW#]:,(?i)\bSewage Treatment Plant\b,STP#]:,(?i)\bHorizontal subsurface filter\b,HSSF#]:,(?i)\bWastewater\b,WW#]:,(?i)\bgroundwater\b,GW#]:
(?i) enables case insensitive searching.
Raindrops
Posts: 247
Joined: Sat Jan 21, 2023 10:04 am

Re: How to replace parts of search string automatically before launching the search?

Post by Raindrops »

The nested RegEx gets too complex when a large number of replacements are involved.
It would also become error-prone.

In comparison, the solution suggested by @nod5 seems to be easier for non-programmers like me. The list is easy to expand, and errors are not likely.

However, there's a catch: This option requires me to learn AutoHotKey.
If I have to invest time and effort in learning an automation software, I may as well compare similar software and pick the software that suits such workflows. (Including tasks that don't involve Everything or even file management!)

I wonder how AutoHotKey weighs against similar automation software like AutoIT, Sikuli and Pulover's Macro creator.

I had tried them out in remote past, but without purpose.
Now I realize that they can be put to great use.
But IMHO a fresh comparison is needed, because all of them would have evolved in their own way!

I could not find such two-way or multi-way comparisons on YouTube or other websites.
[EDIT] This website seems to offer comparisons. Just discovered it. Checking how accurate+latest the comparison is!

Can anyone please help with tips?
Thanks in advance!

Also, if ready scripts are available for such automation tasks, it would be a great idea to collect them in the help docs, and index them!
nod5
Posts: 38
Joined: Fri Aug 19, 2016 9:12 pm

Re: How to replace parts of search string automatically before launching the search?

Post by nod5 »

Raindrops wrote: Mon Mar 06, 2023 5:24 am Can anyone please help with tips?
Why not just start with AutoHotkey and if you ever find something it cannot do then try the others.
Raindrops
Posts: 247
Joined: Sat Jan 21, 2023 10:04 am

Re: How to replace parts of search string automatically before launching the search?

Post by Raindrops »

I try to do everything without coding.
So Pulover's Macro Creator suits my nature better compared to AHK! :P
Specular
Posts: 16
Joined: Sat Dec 27, 2014 5:46 am

Re: How to replace parts of search string automatically before launching the search?

Post by Specular »

void wrote: Fri Mar 03, 2023 4:10 amA Synonyms list is on my TODO list.
Just wanted to add that this would be a hugely appreciated feature if implemented at some point. I haven't tested the AHK suggestion (though I augment various Windows things already with AHK) but wanted to voice support for it, as 20-30% of every filename I write is taken up by including synonyms, apart from the scenarios listed below.

For some context I have over 40k files with custom filenames that are content from third-parties and contain titles of pages/etc, author and other descriptive info. So a blend of my descriptions/notes and others'.

Just to expand on some common scenarios encountered, since I think it actually covers a broader range of searchability issues than perhaps some might realize:
  • US vs international spellings (or sometimes entirely different words). Eg: 'grey' vs 'gray'.
  • Actual synonyms like 'username' vs 'handle', 'concurrent' vs 'simultaneous', 'typeface' vs 'font' (even if the latter synonym is more colloquial), etc.
  • Commonly used abbreviations. Eg: 'CLI' vs 'command line'.
  • Pluralization and tenses that affect searchability. Eg: 'ran' vs 'running'.
  • Stylistic word differences despite most users referring to a common form. Eg: 'Wi-Fi' vs 'wifi', '[H]ard|Forum' vs 'HardForum' (in filenames pipes would typically be replaced with underlines though I use Unicode equivalent looking replacements).
In trying to pull up a search for an item when I know it exists it often requires trying multiple combinations to rule out issues like those above. Being able to transparently match strings as-is in a query to synonyms a user frequently encounters would certainly help reduce repeat queries.

If the feature does eventuate perhaps to disable the behavior for a given string it could be double quoted, or some method to disable it if desired.
Raindrops
Posts: 247
Joined: Sat Jan 21, 2023 10:04 am

Re: How to replace parts of search string automatically before launching the search?

Post by Raindrops »

That's a wonderful idea!

It would be fantastic to have a global equivalent (synonym) list.

BTW, the users should be able to export/import/save this list, so that we can share such lists through this forum!
(Why reinvent the wheel?)
Post Reply