Browse Source

rename shingle->phrase, move phrase matching 'should' condition below admin condition', fix formatting/tests

pull/153/head
Peter Johnson 10 years ago
parent
commit
99c6f7e879
  1. 16
      query/search.js
  2. 16
      sanitiser/_details.js
  3. 3
      service/search.js
  4. 62
      test/unit/query/search.js
  5. 4
      test/unit/sanitiser/reverse.js
  6. 4
      test/unit/sanitiser/search.js

16
query/search.js

@ -32,14 +32,6 @@ function generate( params ){
// should query contitions
query.query.filtered.query.bool.should = [];
// add shingles should query
// note: this is required for partial phrase matching
query.query.filtered.query.bool.should.push({
'match': {
'shingle.default': params.input
}
});
if (params.input_admin) {
var admin_fields = ['admin0', 'admin1', 'admin1_abbr', 'admin2', 'alpha3'];
@ -52,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;

16
sanitiser/_details.js

@ -18,13 +18,7 @@ function sanitize( req, default_value ){
}
if (params.details !== undefined) {
var details = params.details;
if (typeof params.details === 'string') {
details = params.details === 'true';
}
clean.details = details === true || details === 1;
clean.details = isTruthy(params.details);
} else {
clean.details = default_value;
}
@ -35,5 +29,13 @@ function sanitize( req, default_value ){
}
function isTruthy(val) {
if (typeof val === 'string') {
return ['true', '1', 'yes', 'y'].indexOf(val) !== -1;
}
return val === 1 || val === true;
}
// export function
module.exports = sanitize;

3
service/search.js

@ -18,6 +18,9 @@ function service( backend, cmd, cb ){
// handle backend errors
if( err ){ return cb( err ); }
// log total ms elasticsearch reported the query took to execute
peliasLogger.verbose( 'time elasticsearch reported:', data.took / 1000 );
// map returned documents
var docs = [];
if( data && data.hits && data.hits.total && Array.isArray(data.hits.hits)){

62
test/unit/query/search.js

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

4
test/unit/sanitiser/reverse.js

@ -137,7 +137,7 @@ module.exports.tests.sanitize_details = function(test, common) {
});
});
var valid_values = [true, 'true', 1];
var valid_values = [true, 'true', 1, '1', 'yes', 'y'];
valid_values.forEach(function(details) {
test('valid details param ' + details, function(t) {
sanitize({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){
@ -154,7 +154,7 @@ module.exports.tests.sanitize_details = function(test, common) {
});
});
var valid_false_values = ['false', false, 0];
var valid_false_values = ['false', false, 0, '0', 'no', 'n'];
valid_false_values.forEach(function(details) {
test('test setting false explicitly ' + details, function(t) {
sanitize({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){

4
test/unit/sanitiser/search.js

@ -278,7 +278,7 @@ module.exports.tests.sanitize_details = function(test, common) {
});
});
var valid_values = ['true', true, 1];
var valid_values = ['true', true, 1, '1', 'yes', 'y'];
valid_values.forEach(function(details) {
test('valid details param ' + details, function(t) {
sanitize({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){
@ -288,7 +288,7 @@ module.exports.tests.sanitize_details = function(test, common) {
});
});
var valid_false_values = ['false', false, 0];
var valid_false_values = ['false', false, 0, '0', 'no', 'n'];
valid_false_values.forEach(function(details) {
test('test setting false explicitly ' + details, function(t) {
sanitize({ input: 'test', lat: 0, lon: 0, details: details }, function( err, clean ){

Loading…
Cancel
Save