PL5 Searching doesn't work properly for all keywords in an hierarchy - only for "Selected" keywords

The following is an attempt to Pseudo-Code the logic for creating the ‘dc’ and ‘hr’ keywords from the entries in the DxPL database @Joanna. It is pesudo Pseudo code, i.e. a made up version so that I can try to understand the logic behind using the database and populating the various fields.

The sad thing is how easy it is to vary the logic to accommodate the options rather than implementing a “one size fits all” that risks being a “one size that pleases no-one”!

Such a wasted opportunity @Musashi!

There is also at least one error in my comparison table for Capture One so I will attempt to check the entries but my Wife has Covid after a coach holiday last week and I am likely to go down with it sooner rather than later and increased brain fade will result (comments like “it can’t fade much more are not welcome” true or not)!?

This post should be allowed to continue, I think it has almost run its course but does not need to be closed @Musashi

Access 'Items'
*
** Locate any keywords for an 'Items' entry via the 'ItemsKeyword' structure
*
** A keyword can fall into one of the following categories:-
** A keyword found from 'ItemsKeywords', i.e. an assigned keyword
** which may be:-
**   A  simple keyword, designated by a 'ParentId' of NULL
**   An hierarchical keyword, the "leaf" of an hierarchical keyword (which may be an element of a larger hierarchical keyword)
** and then via the 'Keywords' Table accessed using the 'KeywordId' from 'ItemsKeywords'
**   An hierarchical keyword found by a 'ParentId' pointer from another keyword and containing a 'ParentId'
**   An hierarchical keyword found by a 'ParentId' pointer from another keyword and containing a 'ParentId' = NULL - i.e. the head of the hierachical keyword

* 
ACCESS 'ItemsKeywords' VIA the 'ItemId' value from 'Items'
*
** Start reconstructing any hierarchical keywords and populating the 'dc' and 'hr' fields appropriately
*
*
** P R O C E S S   E A C H   A S S I G N E D   K E Y W O R D 
*
*
FOR EACH entry in 'ItemsKeyword' associated with the 'ItemId' THEN
*
** Taking each ASSIGNED keyword in turn (currently EVERY item in 'ItemsKeywords')
*
** Locate the entry in the 'Keywords' Table
*
  ACCESS 'Keywords' using the 'KeywordId' value from 'ItemsKeywords' (NOTFOUND = 'Unexpected ERROR')
*
** Determine keyword type by it's context, i.e. by the 'ParentId' setting etc.
*
  IF  'ParentId' = 'NULL' THEN
*
**  P R O C E S S   A   S I M P L E   K E Y W O R D 
*
    ADD 'Value' from 'Keywords' TO 'dc Keywords'
*
**  Consider whether it is correct to include that keyword in the 'hr' fields as DxPL and others do currently?
*
    (Unconditional):
      ADD 'Value' from 'Keywords' TO 'hr Keywords'   <--------------------@Joanna
    (end Unconditional)
   
  ELSE
*
**  'ParentId' Not NULL so part of an hierarchical keyword (in this case the "leaf" keyword
*
**  P R O C E S S   A   L E A F   H I E R A R C H I C A L   K E Y W O R D   E L E M E N T 
*
**  Start a new hierarchical keyword reconstruction from last to first, e.g.                 |D
*
    SET 'Hierachical Keyword' = 'Value' from 'Keywords'
    ADD |           TO front of 'Hierarchical keyword' 

**  This is the "leaf" keyword in the hierarchy, e.g. D in A|B|C|D (A>B>C>D) or an assigned sub-element hierarchy
**  The leaf will arguably ALWAYS be considered for the 'dc' keywords even for DxO PL5.2.0 option
*
    (Unconditional):
      ADD 'Value' from 'Keywords' TO 'dc Keywords'
    (end Unconditional)
[*
**  Optionally add 'Value' from 'Keywords' to 'hr' Keywords'!?  <------@Joanna
*
   (Conditional):
      ADD ''Value' from 'Keywords' TO 'hr Keywords'
   (End-Conditional)]

*
**  Using the 'ParentId' access the linked keyword in the 'Keywords' Table 
*
    FOR each entry in 'Keywords' Table found using the 'ParentId' from a 'Keywords' Table entry
    
      ACCESS 'Keywords' VIA 'ParentId' of 'Keywords' Table entry
      
      IF 'ParentId' = NULL Then
*
**      This is the head keyword of the hierarchical keyword
*
**      P R O C E S S   H E A D   O F   A N   H I E R A C H I C A L    K E Y W O R D 
*
**      Add keyword to the front of a reconstruction of the hierarchical keyword from leaf to top, i.e. in front of the previous keyword
*
        ADD 'Value' from 'Keywords' TO front of 'Hierarchical keyword'
*
**      Reconstruction of hierarchical keyword is now complete and the head node should be added to the 'hr' keywords <-----@Joanna
*
        (Unconditional):
          ADD 'Hierarchical keyword' TO 'hr Keywords'
        (end Unconditional)
*
*       Optionally add the keyword to the 'dc' keys this is different between pre PL5.2.0 & post PL5.2.0
*
        (Conditional):
           ADD 'Value' from 'Keywords' TO 'dc Keywords'
        (End Conditional)
*
**      Add Keyword to 'hr Keywords', typically done with the head of an hierarchical keyword  <------@Joanna
*
        (Unconditional):
          ADD 'Value' from 'Keywords' TO 'hr Keywords'
        (end Unconditional)
      ELSE
*
**      This is an itermediate hierarchical keyword
*
**      P R O C E S S   I N T E R M E D I A T E   H I E R A R C H I C A L   K E Y W O R D 
*
        ADD 'Value' from 'Keywords' TO front of 'Hierarchical keyword'
        ADD |                       TO front of 'Hierarchical keyword'        
*
*       Optionally add the keyword to the 'dc' keys - this is different between pre PL5.2.0 & post PL5.2.0
*
        (Conditional):
           ADD 'Value' from 'Keywords' TO 'dc Keys'
        (End Conditional)
[*
**      Add 'Value' from 'Keywords' to 'hr' Keywords', typically done with the head of an hierarchical keyword
**      but not necessarily with other keywords
*
        (Conditional):
          ADD 'Value' from 'Keywords' TO 'hr Keywords'                                                           <------@Joanna
        (end Conditional)]
      END-IF
    REPEAT-FOR UNTIL 'ParentId = NULL'
  END-IF
REPEAT-FOR UNTIL 'NOTFOUND' IN 'ItemsKeywords'
*
** Arguably the 'dc' keywords & 'hr' keywords need duplicate entries resolved (de-duping), I believe             <-------@Joanna
*

Wrong :- Pseudo code V02.txt (5.0 KB)

Hopefully better!?:- Pseudo code V03.txt (5.1 KB)

The [ ] are me being “over-enthusiastic” and including simple keyword elements where they are not required, i.e. keyword elements from an ‘hr’ keyword in the ‘hr’ fields when only the head of the hierarchy should be included but I included the places where that could be done and then enclosed the items with the […].

The biggest issue is all the packages (except Photo mechanic and non-hr aware products) include simple keywords in the ‘hr’ fields.

However, not doing that would mean that my Scenario 4 test, i.e. “animal”, “mammal”, “bear”, “animal|mammal|bear” input, would have the same keyword assignments as a simple "animal|mammal|bear’ input! @Joanna ?

The problem with the current DxPL handling of simple keywords, i.e. putting them into the ‘hr’ fields, is the result if the ‘dc’ entries are deleted by a non-hierarchical product (Zoner, ExifPro, ACDSee etc.) which will leave the (orphaned) ‘hr’ entries intact.

PL5 treats the remaining (orphaned) ‘hr’ entries as acceptable and will simply repopulate the ‘dc’ fields on output.

Now you see it, now you don’t, now you do again!

PS:-

The (Conditional): would be an IF <option - x > SET THEN … or IF <option - x > SET THEN …ELSE …END-IF but I wanted to keep the Pseudo code a little cleaner for review purposes.

The (Unconditional): could all be made (Conditional): but use internal option settings to control the behaviour!?

Errata: There was an error throughput V02, I used ‘KeywordId’ instead of ‘Value’ from ‘Keywords’ on every occasion - sorry!