Browse Source

Merge pull request #153 from pelias/ngram

merge ngram
pull/154/head
Peter Johnson a.k.a. insertcoffee 9 years ago
parent
commit
930dee47d8
  1. 20
      app.js
  2. 15
      query/search.js
  3. 6
      test/ciao/suggest/nearby_nobias.coffee
  4. 18
      test/unit/query/search.js

20
app.js

@ -37,24 +37,18 @@ app.get( '/', controllers.index() );
// doc API
app.get( '/doc', sanitisers.doc.middleware, controllers.doc() );
// suggest API
app.get( '/suggest', sanitisers.suggest.middleware, controllers.suggest() );
app.get( '/suggest/nearby',
sanitisers.suggest.middleware,
controllers.suggest(undefined, undefined, require('./helper/queryMixer').suggest_nearby) );
app.get( '/suggest/coarse',
sanitisers.coarse.middleware,
controllers.suggest(undefined, undefined, require('./helper/queryMixer').coarse) );
// search API
// suggest APIs
app.get( '/suggest', sanitisers.search.middleware, controllers.search() );
app.get( '/suggest/nearby', sanitisers.suggest.middleware, controllers.search() );
app.get( '/suggest/coarse', sanitisers.coarse.middleware, controllers.search() );
// search APIs
app.get( '/search', sanitisers.search.middleware, controllers.search() );
app.get( '/search/coarse', sanitisers.coarse.middleware, controllers.search() );
// reverse API
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 ----------------------- **/
app.use( require('./middleware/404') );

15
query/search.js

@ -25,14 +25,15 @@ function generate( params ){
'match': {
'name.default': params.input
}
}
]
}]
}
};
// should query contitions
query.query.filtered.query.bool.should = [];
if (params.input_admin) {
var admin_fields = ['admin0', 'admin1', 'admin1_abbr', 'admin2', 'alpha3'];
query.query.filtered.query.bool.should = [];
admin_fields.forEach(function(admin_field) {
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 ) );
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

18
test/unit/query/search.js

@ -80,8 +80,12 @@ var expected = {
'match': {
'name.default': 'test'
}
}],
'should': [{
'match': {
'phrase.default': 'test'
}
]
}]
}
},
'filter': {
@ -158,8 +162,12 @@ module.exports.tests.query = function(test, common) {
'match': {
'name.default': 'test'
}
}],
'should': [{
'match': {
'phrase.default': 'test'
}
]
}]
}
},
'filter': {
@ -194,8 +202,12 @@ module.exports.tests.query = function(test, common) {
'match': {
'name.default': 'test'
}
}],
'should': [{
'match': {
'phrase.default': 'test'
}
]
}]
}
},
'filter': {

Loading…
Cancel
Save