Tagging, Searching and Counting

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
TedL1972
Posts: 64
Joined: 15 Nov 2018 18:49

Tagging, Searching and Counting

Post by TedL1972 »

Hello,
I have been using XYplorer for a few weeks and I love the searching area. I have been tagging and then retrieving those documents easily. What I am trying to do now is to find a way to count how many of those tagged items are there and ideally have them plotted in a list with the highest on top. For instance, let's say I have 132 documents tagged and all these documents have to do with fruit. I would like to be able to search and then have an output that looks like this:

Banana 42
Apple 34
Kiwi 22
Watermelon 14
Oranges 11
Pears 9

Am I asking too much from ZYplorer? I have been looking at some scripting feature but so far no luck. I only have a very rudimentary knowledge of Scripting so perhaps the answer is there but I just don't see it yet. Any input would be appreciated.

One more thing, is there a scripting feature that the moment a document is tagged let's say "Banana" can "Copy to" that document immediately (or after hitting "OK") into the existing folder called "Banana"?

Thanks!

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Tagging, Searching and Counting

Post by highend »

132 documents tagged and all these documents have to do with fruit
So does that mean that you have:
42 files tagged with "Banana" AND "fruit"?
etc. for all other examples?

In other words, each file only has exactly two tags and one of them is always "fruit" and the other the name of the fruit?

And regarding to output: In some kind of message box or as files in the list pane with these two additional informations (the tag + the count)?
is there a scripting feature that the moment a document is tagged let's say "Banana" can "Copy to" that document immediately (or after hitting "OK") into the existing folder called "Banana"?
Fully automatically without any user intervention? Nope
One of my scripts helped you out? Please donate via Paypal

TedL1972
Posts: 64
Joined: 15 Nov 2018 18:49

Re: Tagging, Searching and Counting

Post by TedL1972 »

Thanks for the reply!!

To clarify: some documents have just banana and fruit while some others have a combination E.g. fruit, banana, apple, orange, etc.
And regarding to output: In some kind of message box or as files in the list pane with these two additional informations (the tag + the count)?
In a message box or in the list pane would be totally OK. Anyway really that the information can be outpout would be great.

Fully automatically without any user intervention? Nope


Got it! I will take any other user intervention.... :)

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Tagging, Searching and Counting

Post by highend »

To clarify: some documents have just banana and fruit while some others have a combination E.g. fruit, banana, apple, orange, etc.
I just want to be sure about this:

- ALL items have the fruit tag, right?
- If an item has more than one name tag (Banana AND Apple) than it would be counted for BOTH (or with more fruit names, all belonging) categories?

If that's the case, this would work:

Code: Select all

    $fruitList = <<<>>>
Banana
Apple
Kiwi
Watermelon
Oranges
Pears
>>>;
    $fruitList = formatlist($fruitList, "e", <crlf>);
    $fruits = quicksearch("tags:fruit", "*", , "s");
    $tagged = regexreplace(tagitems("tags", , $fruits, 1), "(^|, )fruit");
    $result = "";
    foreach($item, $fruitList, <crlf>, "e") {
        $result .= gettoken(regexmatches($tagged, $item, "<crlf>"), "count", <crlf>) . "<::>" . $item . <crlf>;
    }
    $result = formatlist($result, "sr", <crlf>); // Reverse sort, largest numbers on top!
    $result = regexreplace($result, "^(\d+)<::>(.*?)(?=\r?\n|$)", "$2 $1");
    text $result;
One of my scripts helped you out? Please donate via Paypal

TedL1972
Posts: 64
Joined: 15 Nov 2018 18:49

Re: Tagging, Searching and Counting

Post by TedL1972 »

Hello highend, thanks very much .

[/quote]I just want to be sure about this:


[/quote]- ALL items have the fruit tag, right?[/quote][/b]

No, not all of them have the fruit tag but I would like to have an option to count all those that have the fruit tag as well. Basically I would need to be able to count every document that has the tag "banana", every doc that has "apple" etc. I understand however that having ALL the fruit tag might make it easier?
- If an item has more than one name tag (Banana AND Apple) than it would be counted for BOTH (or with more fruit names, all belonging) categories?
[/b]

Yes if a document has both "banana" and "apple" then it would be counted for both.

I will try the script which I guess I will need to do by using "run script" while the directory that contains the documents is selected in the visible pane?

Any word on the copying of the documents?

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Tagging, Searching and Counting

Post by highend »

Basically I would need to be able to count every document that has the tag "banana", every doc that has "apple" etc. I understand however that having ALL the fruit tag might make it easier?
Easier? No. But more logical

This script counts all items that are in the $fruitList, regardless if any of those items has the additional "fruit" tag:

Code: Select all

    $fruitList = <<<>>>
Banana
Apple
Kiwi
Watermelon
Oranges
Pears
>>>;
    $fruitList = formatlist($fruitList, "e", <crlf>);
    $result = "";
    foreach($fruit, $fruitList, <crlf>, "e") {
        $tagged = quicksearch("tags:$fruit", "*", , "s");
        $result .= gettoken($tagged, "count", <crlf>) . "<::>" . $fruit . <crlf>;
    }
    $result = formatlist($result, "sr", <crlf>); // Reverse sort, largest numbers on top!
    $result = regexreplace($result, "^(\d+)<::>(.*?)(?=\r?\n|$)", "$2 $1");
    text $result;
I will need to do by using "run script" while the directory that contains the documents is selected in the visible pane?
Put it in a user defined command, a button, a catalog entry, whatever. It doesn't matter which folder is visible, it searches the tag database directly.
Any word on the copying of the documents?
Write a script that looks in the tag database for that tag, loop over all found items, check if they already exist and if not, use e.g. the script command copyto to copy the file over.
One of my scripts helped you out? Please donate via Paypal

TedL1972
Posts: 64
Joined: 15 Nov 2018 18:49

Re: Tagging, Searching and Counting

Post by TedL1972 »

Great!
It seems to be working. The only thing is that items that are mentioned only one time give an output of "zero" i.e.
Fig 0
Apricot 0

Also the word "fruit" shows up with 0.

Other then that it works great.

Got it on the other script.

Thanks very much highend.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Tagging, Searching and Counting

Post by highend »

It seems to be working. The only thing is that items that are mentioned only one time give an output of "zero" i.e.
Fig 0
Apricot 0
Can't replicate this here. Post the script you're currently using and show me a screenshot of the folder in the list pane that contains such an item (and make sure that you show the normal "Tags" column so that I can confirm that everything looks ok!)
One of my scripts helped you out? Please donate via Paypal

TedL1972
Posts: 64
Joined: 15 Nov 2018 18:49

Re: Tagging, Searching and Counting

Post by TedL1972 »

Thanks.

I did this again with a clean file and it worked on the counting and output of fruit items!! :tup:

On the second matter I tried to follow your direction but I am afraid it is above my scripting knowledge....... :oops:

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Tagging, Searching and Counting

Post by highend »

Code: Select all

    $saveTo = "R:\tst";
    $tags   = "Banana|Orange|Apple"; // If a file has one of these tags, it will be copied if it doesn't exist under "R:\tst\<name of the tag>"

    $copyList = "";
    foreach($tag, $tags, , "e") {
        $tagged = quicksearch("tags:$tag", "*", , "s");
        foreach($item, $tagged, <crlf>, "e") {
            if ($tag != $lastTag) { $copyList .= "<::>$tag" . <crlf>; }
            $dstFile = trim($saveTo, "\") . "\" . $tag . "\" . gpc($item, "file");
            if !(exists($dstFile)) { $copyList .= $item . <crlf>; }
            $lastTag = $tag;
        }
    }

    if !(regexmatches($copyList, "^([a-z]|\\)")) { status "No new item(s) found!", "8B4513", "stop"; end true; }
    $copyList = formatlist(replace($copyList, "<::>", , , , 1), "e", <crlf>); // Remove the first separator

    setting "BackgroundFileOps", 0;
    $count = gettoken($copyList, "count", "<::>");
    while ($i++ < $count) {
        $section = gettoken($copyList, $i, "<::>");
        $tag = gettoken($section, 1, <crlf>);
        $itemsToCopy = replace(gettoken($section, 2, <crlf>, , 2), <crlf>, "|");
        if ($itemsToCopy) {
            $copyToPath = trim($saveTo, "\") . "\" . $tag;
            copyto $copyToPath, $itemsToCopy, , 2, 2, 1, 1, 0, 0, , 0, 0;
        }
    }
    wait 10;
    status "All new item(s) copied...";
One of my scripts helped you out? Please donate via Paypal

TedL1972
Posts: 64
Joined: 15 Nov 2018 18:49

Re: Tagging, Searching and Counting

Post by TedL1972 »

Thanks and I ran the script but apparently nothing happens.

Are there some prior steps that need to be done?

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Tagging, Searching and Counting

Post by highend »

And you expect me to do what, wild guessing?

$saveTo was set to what?

Show the output of:

Code: Select all

text quicksearch("tags:banana | apple | orange", "*", , "s");
One of my scripts helped you out? Please donate via Paypal

TedL1972
Posts: 64
Joined: 15 Nov 2018 18:49

Re: Tagging, Searching and Counting

Post by TedL1972 »

Sorry for my incomplete data.

Going through the learning curve...

I ran the search using your last line of script and I can see that it searches but doesn't find anything. :roll:

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Tagging, Searching and Counting

Post by highend »

Em... you did read my last posting? oO
One of my scripts helped you out? Please donate via Paypal

TedL1972
Posts: 64
Joined: 15 Nov 2018 18:49

Re: Tagging, Searching and Counting

Post by TedL1972 »

Hello I am back on this thread after a while after switching from the trial version to the licensed one. I have tried to run this script again:
$fruitList = <<<>>>
Banana
Apple
Kiwi
Watermelon
Oranges
Pears
>>>;
$fruitList = formatlist($fruitList, "e", <crlf>);
$result = "";
foreach($fruit, $fruitList, <crlf>, "e") {
$tagged = quicksearch("tags:$fruit", "*", , "s");
$result .= gettoken($tagged, "count", <crlf>) . "<::>" . $fruit . <crlf>;
}
$result = formatlist($result, "sr", <crlf>); // Reverse sort, largest numbers on top!
$result = regexreplace($result, "^(\d+)<::>(.*?)(?=\r?\n|$)", "$2 $1");
text $result;
However I am getting first an error message:
Error Message
Error Message
Capture.JPG (56.94 KiB) Viewed 2610 times
Then when I click on "Continue" I get the following output:
Watermelon 0
Pears 0
Oranges 0
Kiwi 0
Banana 0
Apple 0
Not sure what is wrong. I first have re-tagged all the items in case the tags were lost from the switch over but got the same message. Then I
tried to use the same script with newly created tags on other documents and directories (just with search and replace the tag names but keeping the same
script) but I get always the same message above and either no output or an output of zeros.

Help!

Post Reply