Skip to content

Commit

Permalink
v2.4.3 - fix #44, FamilySearch changed url params
Browse files Browse the repository at this point in the history
  • Loading branch information
justincy committed Dec 14, 2021
1 parent f87880a commit 1bc3cbd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gensearch",
"version": "2.4.2",
"version": "2.4.3",
"description": "Generate search links for genealogy websites",
"repository": {
"type": "git",
Expand Down
40 changes: 20 additions & 20 deletions src/sites/familysearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ module.exports = function(config, data){

config = utils.defaults(config, defaultConfig);

var fsURL = 'https://www.familysearch.org/search/record/results?count=20';
var fsURL = 'https://www.familysearch.org/search/record/results?';
var query = '';

// Simple mappings from the person data object to fs params
// These don't need any special processing
var simpleMappings = [
['givenname', 'givenName'],
['surname', 'familyName'],
['birth_place', 'birthPlace'],
['death_place', 'deathPlace'],
['father_givenname', 'fatherGivenName'],
['father_surname', 'fatherFamilyName'],
['mother_givenname', 'motherGivenName'],
['mother_surname', 'motherFamilyName'],
['spouse_givenname', 'spouseGivenName'],
['spouse_surname', 'spouseFamilyName'],
['marriage_place', 'marriagePlace']
['q.givenName', 'givenName'],
['q.surname', 'familyName'],
['q.birthLikePlace', 'birthPlace'],
['q.deathLikePlace', 'deathPlace'],
['q.fatherGivenName', 'fatherGivenName'],
['q.fatherSurname', 'fatherFamilyName'],
['q.motherGivenName', 'motherGivenName'],
['q.motherSurname', 'motherFamilyName'],
['q.spouseGivenName', 'spouseGivenName'],
['q.spouseSurname', 'spouseFamilyName'],
['q.marriageLikePlace', 'marriagePlace']
];
utils.each(simpleMappings, function(map) {
if( data[map[1]] ) {
Expand All @@ -38,33 +38,33 @@ module.exports = function(config, data){
if(data.birthDate){
var birthYear = utils.getYearInt(data.birthDate);
if( birthYear ) {
query = utils.addQueryParam(query, 'birth_year_from', birthYear - config.birthRange);
query = utils.addQueryParam(query, 'birth_year_to', birthYear + config.birthRange)
query = utils.addQueryParam(query, 'q.birthLikeDate.from', birthYear - config.birthRange);
query = utils.addQueryParam(query, 'q.birthLikeDate.to', birthYear + config.birthRange)
}
}

// Process the death year
if(data.deathDate){
var deathYear = utils.getYearInt(data.deathDate);
if( deathYear ) {
query = utils.addQueryParam(query, 'death_year_from', deathYear - config.deathRange);
query = utils.addQueryParam(query, 'death_year_to', deathYear + config.deathRange);
query = utils.addQueryParam(query, 'q.deathLikeDate.from', deathYear - config.deathRange);
query = utils.addQueryParam(query, 'q.deathLikeDate.to', deathYear + config.deathRange);
}
}

// Process the marriage year
if(data.marriageDate){
var marriageYear = utils.getYearInt(data.marriageDate);
if( marriageYear ) {
query = utils.addQueryParam(query, 'marriage_year_from', marriageYear - config.marriageRange);
query = utils.addQueryParam(query, 'marriage_year_to', marriageYear + config.marriageRange);
query = utils.addQueryParam(query, 'q.marriageLikeDate.from', marriageYear - config.marriageRange);
query = utils.addQueryParam(query, 'q.marriageLikeDate.to', marriageYear + config.marriageRange);
}
}

if(config.collectionId){
query = utils.addQueryParam(query, 'collection_id', config.collectionId);
query = utils.addQueryParam(query, 'f.collectionId', config.collectionId);
}

return fsURL + query;
return fsURL + query.replace('&', '');

};
8 changes: 4 additions & 4 deletions test/sites/familysearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ var test = require('../tester.js')('familysearch');
describe('familysearch', function(){

it('1', function(){
test(test.data[0], 'https://www.familysearch.org/search/record/results?count=20&givenname=Joe%20William&surname=Clark');
test(test.data[0], 'https://www.familysearch.org/search/record/results?q.givenName=Joe%20William&q.surname=Clark');
});

it('2', function(){
test(test.data[1], 'https://www.familysearch.org/search/record/results?count=20&givenname=Joe%20William&surname=Clark&birth_place=Texas&death_place=Springfield%2C%20Illinois&father_givenname=Dale&father_surname=Clark&mother_givenname=Susan&mother_surname=Anthony&spouse_givenname=Jennifer&spouse_surname=Thomas&marriage_place=St%20Louis%2C%20MO&birth_year_from=1833&birth_year_to=1837&death_year_from=1887&death_year_to=1891&marriage_year_from=1856&marriage_year_to=1860');
test(test.data[1], 'https://www.familysearch.org/search/record/results?q.birthLikeDate.from=1833&q.birthLikeDate.to=1837&q.birthLikePlace=Texas&q.deathLikeDate.from=1887&q.deathLikeDate.to=1891&q.deathLikePlace=Springfield%2C%20Illinois&q.fatherGivenName=Dale&q.fatherSurname=Clark&q.givenName=Joe%20William&q.marriageLikeDate.from=1856&q.marriageLikeDate.to=1860&q.marriageLikePlace=St%20Louis%2C%20MO&q.motherGivenName=Susan&q.motherSurname=Anthony&q.spouseGivenName=Jennifer&q.spouseSurname=Thomas&q.surname=Clark');
});

it('config', function(){
test(test.data[1], 'https://www.familysearch.org/search/record/results?count=20&givenname=Joe%20William&surname=Clark&birth_place=Texas&death_place=Springfield%2C%20Illinois&father_givenname=Dale&father_surname=Clark&mother_givenname=Susan&mother_surname=Anthony&spouse_givenname=Jennifer&spouse_surname=Thomas&marriage_place=St%20Louis%2C%20MO&birth_year_from=1832&birth_year_to=1838&death_year_from=1885&death_year_to=1893&marriage_year_from=1853&marriage_year_to=1863', {
test(test.data[1], 'https://www.familysearch.org/search/record/results?q.birthLikeDate.from=1832&q.birthLikeDate.to=1838&q.birthLikePlace=Texas&q.deathLikeDate.from=1885&q.deathLikeDate.to=1893&q.deathLikePlace=Springfield%2C%20Illinois&q.fatherGivenName=Dale&q.fatherSurname=Clark&q.givenName=Joe%20William&q.marriageLikeDate.from=1853&q.marriageLikeDate.to=1863&q.marriageLikePlace=St%20Louis%2C%20MO&q.motherGivenName=Susan&q.motherSurname=Anthony&q.spouseGivenName=Jennifer&q.spouseSurname=Thomas&q.surname=Clark', {
birthRange: 3,
deathRange: 4,
marriageRange: 5
});
});

it('collection', function(){
test(test.data[0], 'https://www.familysearch.org/search/record/results?count=20&givenname=Joe%20William&surname=Clark&collection_id=1473014', {
test(test.data[0], 'https://www.familysearch.org/search/record/results?q.givenName=Joe%20William&q.surname=Clark&f.collectionId=1473014', {
collectionId: 1473014
});
});
Expand Down
10 changes: 9 additions & 1 deletion test/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ var assert = require('assert'),

module.exports = function(site){
var tester = function(data, url, opts){
assert.equal(search(site, data, opts), url);
// Parse URLs so that we can compare query params without requiring them to be in the same order
const searchUrl = new URL(search(site, data, opts));
const expectedUrl = new URL(url);
// Compare origin and path
assert.equal(`${searchUrl.origin}${searchUrl.pathname}`, `${expectedUrl.origin}${expectedUrl.pathname}`);
// Compare query params
searchUrl.searchParams.sort();
expectedUrl.searchParams.sort()
assert.equal(searchUrl.searchParams.toString(), expectedUrl.searchParams.toString());
};
tester.data = data;
return tester;
Expand Down

0 comments on commit 1bc3cbd

Please sign in to comment.