diff --git a/src/sites/familysearch.js b/src/sites/familysearch.js index 6360604..437180d 100644 --- a/src/sites/familysearch.js +++ b/src/sites/familysearch.js @@ -10,7 +10,7 @@ module.exports = function(config, data){ config = utils.defaults(config, defaultConfig); - var fsURL = 'https://www.familysearch.org/search/record/results?count=20&query='; + var fsURL = 'https://www.familysearch.org/search/record/results?count=20'; var query = ''; // Simple mappings from the person data object to fs params @@ -30,7 +30,7 @@ module.exports = function(config, data){ ]; utils.each(simpleMappings, function(map) { if( data[map[1]] ) { - query = addQueryParam(query, map[0], data[map[1]]); + query = utils.addQueryParam(query, map[0], data[map[1]]); } }); @@ -38,7 +38,8 @@ module.exports = function(config, data){ if(data.birthDate){ var birthYear = utils.getYearInt(data.birthDate); if( birthYear ) { - query = addQueryParam(query, 'birth_year', (birthYear - config.birthRange)+'-'+(birthYear + config.birthRange)); + query = utils.addQueryParam(query, 'birth_year_from', birthYear - config.birthRange); + query = utils.addQueryParam(query, 'birth_year_to', birthYear + config.birthRange) } } @@ -46,7 +47,8 @@ module.exports = function(config, data){ if(data.deathDate){ var deathYear = utils.getYearInt(data.deathDate); if( deathYear ) { - query = addQueryParam(query, 'death_year', (deathYear - config.deathRange)+'-'+(deathYear + config.deathRange)); + query = utils.addQueryParam(query, 'death_year_from', deathYear - config.deathRange); + query = utils.addQueryParam(query, 'death_year_to', deathYear + config.deathRange); } } @@ -54,12 +56,11 @@ module.exports = function(config, data){ if(data.marriageDate){ var marriageYear = utils.getYearInt(data.marriageDate); if( marriageYear ) { - query = addQueryParam(query, 'marriage_year', (marriageYear - config.marriageRange)+'-'+(marriageYear + config.marriageRange)); + query = utils.addQueryParam(query, 'marriage_year_from', marriageYear - config.marriageRange); + query = utils.addQueryParam(query, 'marriage_year_to', marriageYear + config.marriageRange); } } - query = encodeURIComponent(query); - if(config.collectionId){ query = utils.addQueryParam(query, 'collection_id', config.collectionId); } @@ -67,22 +68,3 @@ module.exports = function(config, data){ return fsURL + query; }; - -/** - * Add a query parameter to the current query - */ -function addQueryParam(query, queryParam, paramValue) { - if(paramValue){ - if(query) { - query += ' '; - } - query += '+' + queryParam + ':'; - // if the value has a space, wrap it in quotes - if(paramValue.indexOf(' ') >= 0) { - query += '"' + paramValue + '"~'; - } else { - query += paramValue + '~'; - } - } - return query; -}; \ No newline at end of file diff --git a/test/sites/familysearch.js b/test/sites/familysearch.js index 5e676d8..58aed1e 100644 --- a/test/sites/familysearch.js +++ b/test/sites/familysearch.js @@ -3,15 +3,15 @@ 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&query=%2Bgivenname%3A%22Joe%20William%22~%20%2Bsurname%3AClark~'); + test(test.data[0], 'https://www.familysearch.org/search/record/results?count=20&givenname=Joe%20William&surname=Clark'); }); it('2', function(){ - test(test.data[1], 'https://www.familysearch.org/search/record/results?count=20&query=%2Bgivenname%3A%22Joe%20William%22~%20%2Bsurname%3AClark~%20%2Bbirth_place%3ATexas~%20%2Bdeath_place%3A%22Springfield%2C%20Illinois%22~%20%2Bfather_givenname%3ADale~%20%2Bfather_surname%3AClark~%20%2Bmother_givenname%3ASusan~%20%2Bmother_surname%3AAnthony~%20%2Bspouse_givenname%3AJennifer~%20%2Bspouse_surname%3AThomas~%20%2Bmarriage_place%3A%22St%20Louis%2C%20MO%22~%20%2Bbirth_year%3A1833-1837~%20%2Bdeath_year%3A1887-1891~%20%2Bmarriage_year%3A1856-1860~'); + 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'); }); it('config', function(){ - test(test.data[1], 'https://www.familysearch.org/search/record/results?count=20&query=%2Bgivenname%3A%22Joe%20William%22~%20%2Bsurname%3AClark~%20%2Bbirth_place%3ATexas~%20%2Bdeath_place%3A%22Springfield%2C%20Illinois%22~%20%2Bfather_givenname%3ADale~%20%2Bfather_surname%3AClark~%20%2Bmother_givenname%3ASusan~%20%2Bmother_surname%3AAnthony~%20%2Bspouse_givenname%3AJennifer~%20%2Bspouse_surname%3AThomas~%20%2Bmarriage_place%3A%22St%20Louis%2C%20MO%22~%20%2Bbirth_year%3A1832-1838~%20%2Bdeath_year%3A1885-1893~%20%2Bmarriage_year%3A1853-1863~', { + 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', { birthRange: 3, deathRange: 4, marriageRange: 5 @@ -19,7 +19,7 @@ describe('familysearch', function(){ }); it('collection', function(){ - test(test.data[0], 'https://www.familysearch.org/search/record/results?count=20&query=%2Bgivenname%3A%22Joe%20William%22~%20%2Bsurname%3AClark~&collection_id=1473014', { + test(test.data[0], 'https://www.familysearch.org/search/record/results?count=20&givenname=Joe%20William&surname=Clark&collection_id=1473014', { collectionId: 1473014 }); });