Page 1 of 1

Add "County" to second place field

Posted: 20 Apr 2021 19:16
by BakerJL75
My places are CITY, COUNTY, STATE, UNITED STATES very consistently. If something doesn't exist, it gets , space, ie:
CITY, , STATE, UNITED STATES or , COUNTY, STATE, UNITED STATES.

I would like to add the word County to the 2nd field, COUNTY. So Brown becomes Brown County, etc.

I can reduce the work using search and replace, but there are many single instances which will need manual editing.

Is there an easy way to just add "space County" to all locations in the number 2 field? Preferably only for places ending in United States. But even if it does every Country it would be a lot less work to edit that back out than to manually add County, as the vast majority of my Places are in the US.

I'm assuming it would be the Search and Replace field plugin with LUA, but can't figure out the details.

Re: Add "County" to second place field

Posted: 20 Apr 2021 19:36
by tatewise
Yes, I think the Search and Replace plugin in Lua Pattern mode should be able to cope.

So the Search must match CITY, COUNTY, STATE, UNITED STATES where the first three column parts might be empty.
Therefore, the pattern will be something like:
^.*, .+, .*, UNITED STATES$
where ^ and $ anchor the pattern to the start and end of the Place name, although probably not strictly necessary.
It assumes that each comma is always followed by a space.
.* will match any character sequence including no characters, so CITY and STATE can be anything or nothing.
.+ will only match one or more characters, so COUNTY must exist and an empty column won't match.

That is the pattern, but the variable CITY and COUNTY and STATE text must be captured for use in the Replace field.
^(.*), (.+), (.*), UNITED STATES$

The Replace field will be something like:
%1, %2 COUNTY, %3, UNITED STATES

You typed everything in uppercase, so I've done the same in the patterns, but you must use whatever is actually appropriate.
e.g. County and United States

Backup before using, although the automatic Snapshots should offer a suitable recovery option.

I have not actually tested that pattern but I'm confident it should work.

Re: Add "County" to second place field

Posted: 21 Apr 2021 15:16
by BakerJL75
Something isn't working quite right. To make it simpler, I made a dummy database with only one place:

Wichita Falls, Wichita, Texas, United States

Search Criteria: ^.*,·.+,·.*,·United·States$

Replace: %1,·%2·County,·%3,·United·States

Search only is fine. When I run Search and Replace I get

[string "C:\ProgramData\Calico Pie\Family Historian\Pl..."]:3584: invalid capture index %2

Re: Add "County" to second place field

Posted: 21 Apr 2021 15:36
by tatewise
That is because you have forgotten to add the capture parentheses ( ) as instructed.

^(.*), (.+), (.*), United·States$

Re: Add "County" to second place field

Posted: 21 Apr 2021 15:56
by BakerJL75
I'm sorry. I should have caught that.

Thank you, you are a life saver.

Re: Add "County" to second place field

Posted: 21 Apr 2021 16:20
by BakerJL75
That worked, kind of. Same example, after I run Search and Replace I end up with two places. And I experimented, it's because my original place had latitude/longitude. The replacement place does not. I'm not sure there is any way around this. I suspect I will have to decide which is more important to me. Adding County or keeping my lat/long. Although I can always use the Map Life Facts to put them back. Thought I'd post just in case you have an ideas.
Screenshot 2021-04-21 111841.png
Screenshot 2021-04-21 111841.png (46.78 KiB) Viewed 2788 times

Re: Add "County" to second place field

Posted: 21 Apr 2021 16:26
by tatewise
The latest version of Search and Replace should not do that. Which version are you running?
Does it tell you there is a later version in the Plugin Store?
It should change the existing Place record Text name and retain the Lat/Longitude values.

Earlier versions of the plugin exhibited exactly the symptoms you have posted.
There is a workaround but the latest version is the easier path.

Re: Add "County" to second place field

Posted: 21 Apr 2021 16:39
by BakerJL75
I'm running 3.3
That's the latest I see in the Store.

Re: Add "County" to second place field

Posted: 21 Apr 2021 17:01
by tatewise
What are your plugin Major Options tab settings?
Search Scope: All Records & Events/Attributes or Place Records (_PLAC) are OK but anything else won't work correctly.
Basic Filters: Place fields must be ticked.

Re: Add "County" to second place field

Posted: 21 Apr 2021 17:09
by BakerJL75
All Records & Events/Attributes and Place Fields
Screenshot 2021-04-21 111841.png
Screenshot 2021-04-21 111841.png (106.26 KiB) Viewed 2765 times

Re: Add "County" to second place field

Posted: 21 Apr 2021 17:13
by tatewise
I've just had a thought that it would be safer to set Search Scope: Place Records (_PLAC)
Otherwise, it could upset some Place fields. Sorry, I should have suggested that to start with.

Re: Add "County" to second place field

Posted: 21 Apr 2021 17:30
by BakerJL75
If I do that I get No matching data items have been reported.

Re: Add "County" to second place field

Posted: 21 Apr 2021 17:50
by tatewise
We'll get there eventually :D
Please tick the All other Text fields option. I've just double-checked and that does work.

It is because the Place records don't actually have a Place field and the Place name is in a TEXT field!

Re: Add "County" to second place field

Posted: 21 Apr 2021 17:55
by BakerJL75
That worked! Thank you so much.

Re: Add "County" to second place field

Posted: 21 Apr 2021 18:07
by tatewise
Sorry, it took so long Jackie. I'll try and do better next time :lol: