Sharing custom filters

Recreating a Custom Filters from a multi-stage filter description is a painful and error-prone process.

I’ve found that I can move Custom Filters by appending the XML chunk in the custom_filters.xml in the gramps51 subdirectory of the User Directory.

Actually, you can just trim the closing line from the original XML file and then paste entire custom_filters.xml file with the 1st two lines removed (not included in the copy&paste buffer). Unfortunately, that duplicates any identically named Custom Filters … yet it only shows the first one in the GUI.

Perhaps the Custom Filters parser could be tweaked to keep reading past the </filters> and extra XML header? It should probably also overwrite identically named Filters withiin each filter object type.

The intervening lines that have to be deleted when the entire XML custom filter files have been concatenated are:

</filters>
<?xml version="1.0" encoding="utf-8"?>
<filters>

Example: the 5-stage filter in the Wiki example is:

<?xml version="1.0" encoding="utf-8"?>
<filters>
  <object type="Place">
    <filter name="5-Stage filter A" function="and" comment="Place filter A from the 5-stage FILTERS wiki example">
      <rule class="HasData" use_regex="False">
        <arg value="il"/>
        <arg value="State"/>
        <arg value=""/>
      </rule>
    </filter>
  </object>
  <object type="Event">
    <filter name="5-Stage filter B" function="and" comment="Event filter B from the 5-stage FILTERS wiki example">
      <rule class="MatchesPlaceFilter" use_regex="False">
        <arg value="5-Stage filter A"/>
      </rule>
    </filter>
  </object>
  <object type="Person">
    <filter name="5-Stage filter C" function="and" comment="Person filter C from the 5-stage FILTERS wiki example">
      <rule class="MatchesEventFilter" use_regex="False">
        <arg value="5-Stage filter B"/>
      </rule>
      <rule class="HasEvent" use_regex="False">
        <arg value="Residence"/>
        <arg value=""/>
        <arg value=""/>
        <arg value=""/>
        <arg value=""/>
        <arg value="0"/>
      </rule>
    </filter>
    <filter name="5-Stage filter D" function="and" comment="Person 5-Stage filter D from the 5-stage FILTERS wiki example">
      <rule class="MatchesEventFilter" use_regex="False">
        <arg value="5-Stage filter B"/>
      </rule>
      <rule class="HasEvent" use_regex="False">
        <arg value="Death"/>
        <arg value=""/>
        <arg value=""/>
        <arg value=""/>
        <arg value=""/>
        <arg value="0"/>
      </rule>
    </filter>
    <filter name="5-Stage filter E" function="or" comment="Person 5-Stage filter E from the 5-stage FILTERS wiki example">
      <rule class="MatchesFilter" use_regex="False">
        <arg value="5-Stage filter C"/>
      </rule>
      <rule class="MatchesFilter" use_regex="False">
        <arg value="5-Stage filter D"/>
      </rule>
    </filter>
  </object>
</filters>

Incidentally, the example 5-stage custom filter in the wiki is completely ineffective for its stated purpose. That purpose is to find People who were born or died in a variably selected State.

All the sample Events are logged at the city or county level. The filter only finds State level divisions. So the second stage Event filter does not find a single Event. And, of course, that means that none of the deeper stages can find anything either.

And it turns out that it isn’t even possible to accomplish the goal with the existing filters. The idiosyncratic Place hierarchy of the example.gramps tree defeats all the existing rules. There are 3 additional Place entities at the state level that straddle state lines. Since there might be more than 1 place, you cannot use the Places enclosed by another place rule.

It would be possible if there was a filter that would find returned from another Place filter … such as from Tagged places.

Maybe it would be good to have a tool to facilitate with upgrades. For example, after installing a new version, you could use it to migrate .ini settings and custom filters.

1 Like