Page 1 of 1

Combine combined searches?

Posted: 04 Sep 2014 02:18
by p85
Hi guys,

first of all, if I'm overthinking this and there's an easy solution, so much the better. But here's the situation:

I've got a catalog with two search categories in it. Category A has several items combined with AND, category B has several items combined with OR. I'd like to create a search in the catalog (e.g. with a script) that combines categories A and B with AND.

So the structure would be pretty easy, like:
Path'?(A1 & A2) & (B1 | B3)

The problem is: how do I get a string containing the ticked items in A and a second one with the ticked items in B? Alternatively, can I run a category search by script? Because that way I could imitate the 4 step workaround which I've achieved so far (and which is pretty unpractical):

1) Run search A
2) Press button 1 to run a script to copy the search term from the tab.
3) Run search B
4) Press button 2 to run a script to copy the new search term from the tab, combine and modify the two strings and run the search.

Thanks in advance.

Best wishes,
Petra

Re: Combine combined searches?

Posted: 04 Sep 2014 08:00
by highend
Not sure if I get it...
Alternatively, can I run a category search by script?
Afaik no.
4) Press button 2 to run a script to copy the new search term from the tab, combine and modify the two strings and run the search.
Why should the search be executed again when you already ran them both?

Do you mean something like this?

Code: Select all

    $crlf = "<crlf>";
    $items = listpane(, , , $crlf);
    if (get("trigger") == "1") { // Left click
        copytext $items;
    } elseif (get("trigger") == "2") { // Right click
        $combined = formatlist("<clipboard>" . $crlf . $items, "dents", $crlf);
        text $combined;
    }
You have to save this script in a file in your script folder, e.g. CombinedSearch.xys
and then enter the following for the button that you want to create:
On left click: ::load "CombinedSearch";
On right click: ::load "CombinedSearch";

The script copies the content of the current pane to the clipboard (left click the button after you've executed the first AND search) and combines the clipboard and again, the content of the current pane (right click the button after you've executed the second OR search).

Re: Combine combined searches?

Posted: 04 Sep 2014 09:37
by p85
Hi,
Why should the search be executed again when you already ran them both?
What I meant was: after I ran the first two (separate) searches in order to get the search terms into my variables, I'm running the third, combined search, the one I actually want.

Maybe I should post the code as it is now. The Catalog is structured as follows:
  • Item to load script Firstpartquicksearchscript.xys
    Search category A
    Item A1
    Item A2
    ...
    Item to load script Lastpartquicksearchscript.xys
    Search category B
    Item B1
    Item B2
    ...
Firstpartquicksearchscript.xys is:

Code: Select all

perm $firstpartquicksearch;
 //Get current search term
    $firstpartquicksearch = tab("get", "term");
 //Modify 1st part of string
    $firstpartquicksearch = replace($firstpartquicksearch, "F:\Vid- Videos?", "F:\Vid- Videos?(") . ")";
 //Perform combined search
    goto $firstpartquicksearch . $lastpartquicksearch;
 
Lastpartquicksearchscript.xys is:

Code: Select all

perm $lastpartquicksearch;
 //Get current search term
    $lastpartquicksearch = tab("get", "term");
 //Modify 2nd part of string
    $lastpartquicksearch = " & " . replace($lastpartquicksearch, "F:\Vid- Videos?", "(") . ")";
 //Perform combined search
    goto $firstpartquicksearch . $lastpartquicksearch;
Petra

Re: Combine combined searches?

Posted: 04 Sep 2014 10:05
by highend
I still don't get it...

You execute the AND search (from the catalog)
You execute the script Firstpartquicksearchscript.xys
You execute the OR search (from the catalog)
You execute the script Lastpartquicksearchscript.xys
?

What about my simple script? It combines the search results from the AND and the OR search without executing them more than once.

Re: Combine combined searches?

Posted: 04 Sep 2014 10:52
by p85
Your script adds the two search results, I want a conjunction between the two searches, so that the file name has to contain:
ALL items from Category A AND EITHER ONE of Category B.

The whole executing the separated searches thing is just to get the string containing the ticked items. If there's another way to get that information, I don't have to perform any search except the final one.

I hope that's clear. :?

Petra

Re: Combine combined searches?

Posted: 04 Sep 2014 11:54
by highend
Firstpartquicksearchscript.xys:

Code: Select all

perm $P_firstPartQuickSearch;
    //Get current search term
    $P_firstPartQuickSearch = tab("get", "term");
    //Modify 1st part of string
    $P_firstPartQuickSearch = regexreplace($P_firstPartQuickSearch, "^(.*?\?)(.*)$", "$1($2)");
Lastpartquicksearchscript.xys:

Code: Select all

//Get current search term
    $lastPartQuickSearch = tab("get", "term");
    //Modify 2nd part of string
    $lastPartQuickSearch = " & " . regexreplace($lastPartQuickSearch, "^(.*?\?)(.*)$", "($2)");
    //Perform combined search
    goto $P_firstPartQuickSearch . $lastPartQuickSearch;
I see no reason why the last part should be made permanent so I remove the perm statement...

Re: Combine combined searches?

Posted: 04 Sep 2014 12:29
by p85
I don't see how this makes the process easier? It still requires two clicks.

The second variable is permanent for eventual subsequent searches. That is, if I execute the combined search, and thenI change one category, I only need one click to perform the modified combined search. That's also why I execute the combined search in both scripts. In that respect, the script works exactly as I want it to.

The part that I'd like to make more convenient is the part where I change both categories. Because that's where I have to do the intermediate step of saving the one string first.

Re: Combine combined searches?

Posted: 04 Sep 2014 12:41
by highend
There isn't a more convenient way (apart from writing a script that presents the same AND / OR search terms via a html form and combines them before executing the search automatically) at least I'm not aware of one...

Category search entries can't be invoked by scripting and AND + OR can't be combined in category searches. So ofc you have to do something manually...