Browse Source

Add category filtration to /search.

query/category_filter.js
	-Define a function that handles injecting category-filtration
	logic into elasticsearch queries.
	-Abstract it out into a standalone module since it's going to be
	used by both `query/search.js` and `query/reverse.js`.

sanitiser/search.js, test/unit/sanitiser/search.js
	-Add category filtration to `/search`.
	-Fixes (partly) #128
search-suggest-categories
Severyn Kozak 10 years ago
parent
commit
555ebcbb86
  1. 16
      query/category_filter.js
  2. 3
      query/search.js
  3. 1
      sanitiser/search.js
  4. 3
      test/unit/sanitiser/search.js

16
query/category_filter.js

@ -0,0 +1,16 @@
/**
* Inject the logic for filtering results by category into an elasticsearch
* query.
*/
'use strict';
module.exports = function ( query, params ){
if( params.categories && params.categories.length > 0 ){
query.query.filtered.filter.bool.must.push({
terms: {
category: params.categories
}
});
}
};

3
query/search.js

@ -1,5 +1,6 @@
var queries = require('geopipes-elasticsearch-backend').queries,
categoryFilter = require('./category_filter'),
sort = require('../query/sort');
function generate( params ){
@ -44,7 +45,7 @@ function generate( params ){
}
query.sort = query.sort.concat( sort( params ) );
categoryFilter( query, params );
return query;
}

1
sanitiser/search.js

@ -5,6 +5,7 @@ var _sanitize = require('../sanitiser/_sanitize'),
size: require('../sanitiser/_size'),
layers: require('../sanitiser/_layers'),
details: require('../sanitiser/_details'),
categories: require('./_categories'),
latlonzoom: require('../sanitiser/_geo')
};

3
test/unit/sanitiser/search.js

@ -8,6 +8,7 @@ var search = require('../../../sanitiser/search'),
layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood',
'locality', 'local_admin', 'osmaddress', 'openaddresses' ],
size: 10,
categories: [],
details: true
},
sanitize = function(query, cb) { _sanitize({'query':query}, cb); };
@ -425,4 +426,4 @@ module.exports.all = function (tape, common) {
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};
};

Loading…
Cancel
Save