Browse Source

switching to bool with a 'must' match (AND) and a few 'should's (OR)

pull/68/head
Harish Krishna 10 years ago
parent
commit
2127ebe258
  1. 24
      query/search.js

24
query/search.js

@ -22,13 +22,29 @@ function generate( params ){
// add search condition to distance query // add search condition to distance query
query.query.filtered.query = { query.query.filtered.query = {
query_string : { 'bool': {
query: params.input, 'must': [{
fields: ['name.default'], 'match': {
default_operator: 'OR' 'name.default': params.input
}
}
]
} }
}; };
if (params.input_admin) {
var admin_fields = ['admin0', 'admin1', 'alpha3'];
query.query.filtered.query.bool.should = [];
admin_fields.forEach(function(admin_field) {
var match = {};
match[admin_field] = params.input_admin;
query.query.filtered.query.bool.should.push({
'match': match
});
});
}
query.sort = query.sort.concat(sort); query.sort = query.sort.concat(sort);
return query; return query;

Loading…
Cancel
Save