Browse Source

Merge branch 'master' of github.com:pelias/api into production

pull/160/merge
Peter Johnson 9 years ago
parent
commit
e37d0cf5eb
  1. 20
      app.js
  2. 2
      package.json
  3. 21
      query/search.js
  4. 6
      test/ciao/suggest/nearby_nobias.coffee
  5. 44
      test/unit/query/search.js

20
app.js

@ -37,24 +37,18 @@ app.get( '/', controllers.index() );
// doc API // doc API
app.get( '/doc', sanitisers.doc.middleware, controllers.doc() ); app.get( '/doc', sanitisers.doc.middleware, controllers.doc() );
// suggest API // suggest APIs
app.get( '/suggest', sanitisers.suggest.middleware, controllers.suggest() ); app.get( '/suggest', sanitisers.search.middleware, controllers.search() );
app.get( '/suggest/nearby', app.get( '/suggest/nearby', sanitisers.suggest.middleware, controllers.search() );
sanitisers.suggest.middleware, app.get( '/suggest/coarse', sanitisers.coarse.middleware, controllers.search() );
controllers.suggest(undefined, undefined, require('./helper/queryMixer').suggest_nearby) );
app.get( '/suggest/coarse', // search APIs
sanitisers.coarse.middleware,
controllers.suggest(undefined, undefined, require('./helper/queryMixer').coarse) );
// search API
app.get( '/search', sanitisers.search.middleware, controllers.search() ); app.get( '/search', sanitisers.search.middleware, controllers.search() );
app.get( '/search/coarse', sanitisers.coarse.middleware, controllers.search() );
// reverse API // reverse API
app.get( '/reverse', sanitisers.reverse.middleware, controllers.search(undefined, require('./query/reverse')) ); app.get( '/reverse', sanitisers.reverse.middleware, controllers.search(undefined, require('./query/reverse')) );
// coarse API
app.get( '/search/coarse', sanitisers.coarse.middleware, controllers.search() );
/** ----------------------- error middleware ----------------------- **/ /** ----------------------- error middleware ----------------------- **/
app.use( require('./middleware/404') ); app.use( require('./middleware/404') );

2
package.json

@ -1,7 +1,7 @@
{ {
"name": "pelias-api", "name": "pelias-api",
"author": "mapzen", "author": "mapzen",
"version": "1.2.1", "version": "2.0.0",
"description": "Pelias API", "description": "Pelias API",
"homepage": "https://github.com/pelias/api", "homepage": "https://github.com/pelias/api",
"license": "MIT", "license": "MIT",

21
query/search.js

@ -21,18 +21,19 @@ function generate( params ){
// add search condition to filtered query // add search condition to filtered query
query.query.filtered.query = { query.query.filtered.query = {
'bool': { 'bool': {
'must': [{ 'must': [{
'match': { 'match': {
'name.default': params.input 'name.default': params.input
}
} }
] }]
} }
}; };
// should query contitions
query.query.filtered.query.bool.should = [];
if (params.input_admin) { if (params.input_admin) {
var admin_fields = ['admin0', 'admin1', 'admin1_abbr', 'admin2', 'alpha3']; var admin_fields = ['admin0', 'admin1', 'admin1_abbr', 'admin2', 'alpha3'];
query.query.filtered.query.bool.should = [];
admin_fields.forEach(function(admin_field) { admin_fields.forEach(function(admin_field) {
var match = {}; var match = {};
@ -43,6 +44,14 @@ function generate( params ){
}); });
} }
// add phrase matching query
// note: this is required for shingle/phrase matching
query.query.filtered.query.bool.should.push({
'match': {
'phrase.default': params.input
}
});
query.sort = query.sort.concat( sort( params ) ); query.sort = query.sort.concat( sort( params ) );
return query; return query;

6
test/ciao/suggest/nearby_nobias.coffee

@ -0,0 +1,6 @@
#> suggest without geo bias
path: '/suggest/nearby?input=a'
#? 400 bad request
response.statusCode.should.equal 400

44
test/unit/query/search.js

@ -76,12 +76,16 @@ var expected = {
'filtered': { 'filtered': {
'query': { 'query': {
'bool': { 'bool': {
'must': [{ 'must': [{
'match': { 'match': {
'name.default': 'test' 'name.default': 'test'
} }
}],
'should': [{
'match': {
'phrase.default': 'test'
} }
] }]
} }
}, },
'filter': { 'filter': {
@ -154,12 +158,16 @@ module.exports.tests.query = function(test, common) {
'filtered': { 'filtered': {
'query': { 'query': {
'bool': { 'bool': {
'must': [{ 'must': [{
'match': { 'match': {
'name.default': 'test' 'name.default': 'test'
} }
}],
'should': [{
'match': {
'phrase.default': 'test'
} }
] }]
} }
}, },
'filter': { 'filter': {
@ -190,12 +198,16 @@ module.exports.tests.query = function(test, common) {
'filtered': { 'filtered': {
'query': { 'query': {
'bool': { 'bool': {
'must': [{ 'must': [{
'match': { 'match': {
'name.default': 'test' 'name.default': 'test'
} }
}],
'should': [{
'match': {
'phrase.default': 'test'
} }
] }]
} }
}, },
'filter': { 'filter': {
@ -215,7 +227,7 @@ module.exports.tests.query = function(test, common) {
} }
] ]
} }
} }
} }
}, },
'sort': [ 'sort': [

Loading…
Cancel
Save