diff --git a/stream/popularity_mapper.js b/stream/popularity_mapper.js index 4a318158..e5868630 100644 --- a/stream/popularity_mapper.js +++ b/stream/popularity_mapper.js @@ -190,10 +190,11 @@ module.exports = function(){ } } - // set document popularity when it is a non-zero value - if( !!popularity ){ - doc.setPopularity( popularity ); - } + // set document popularity if it is greater than zero + if( popularity > 0 ){ doc.setPopularity( popularity ); } + + // discard places with a negative popularity + else if( popularity < 0 ){ return next(); } } catch( e ){ @@ -202,13 +203,7 @@ module.exports = function(){ peliasLogger.error( JSON.stringify( doc, null, 2 ) ); } - // discard disused and abandoned places with a negative popularity - if(( doc.getPopularity() || 0 ) < 0 ){ - return next(); - } - return next( null, doc ); - }); }; diff --git a/test/stream/popularity_mapper.js b/test/stream/popularity_mapper.js index 22628cec..38b0ddbc 100644 --- a/test/stream/popularity_mapper.js +++ b/test/stream/popularity_mapper.js @@ -197,32 +197,42 @@ module.exports.tests.nonvenue = function (test, common) { // ===================== discard disused places ====================== module.exports.tests.disused = function (test, common) { - var doc = new Document('osm', 'address', 1); + var doc = new Document('osm', 'venue', 1); doc.setMeta('tags', { 'disused:amenity': 'yes' }); test('does not map - disused', t => { var stream = mapper(); + var counter = 0; stream.pipe(through.obj((doc, enc, next) => { - t.false(doc.getPopularity(), 'no mapping performed'); - t.end(); // test will fail if not called (or called twice). + counter++; next(); + }, (done) => { + t.equal(counter, 0, 'document discarded'); + t.end(); // test will fail if not called (or called twice). + done(); })); stream.write(doc); + stream.end(); }); }; // ===================== discard abandoned places ====================== module.exports.tests.abandoned = function (test, common) { - var doc = new Document('osm', 'address', 1); + var doc = new Document('osm', 'venue', 1); doc.setMeta('tags', { 'abandoned:amenity': 'yes' }); test('does not map - abandoned', t => { var stream = mapper(); + var counter = 0; stream.pipe(through.obj((doc, enc, next) => { - t.false(doc.getPopularity(), 'no mapping performed'); - t.end(); // test will fail if not called (or called twice). + counter++; next(); + }, (done) => { + t.equal(counter, 0, 'document discarded'); + t.end(); // test will fail if not called (or called twice). + done(); })); stream.write(doc); + stream.end(); }); };