Skip to content

Commit

Permalink
Merge pull request #88 from pelias/cutoff_frequency
Browse files Browse the repository at this point in the history
Use cutoff_frequency everywhere
  • Loading branch information
orangejulius authored Jan 14, 2019
2 parents 5b4ac43 + b91a25f commit e141f2b
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 9 deletions.
17 changes: 12 additions & 5 deletions test/view/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ module.exports.tests.no_property = function(test, common) {
vs.var('address::analyzer', 'analyzer value');
vs.var('address::field', 'field value');
vs.var('address::boost', 'boost value');
vs.var('address::cutoff_frequency', 'cutoff_frequency value');

var falseyPropertyAddress = require('../../view/address')('');
var actual = address(vs);
var undefinedPropertyAddress = require('../../view/address')('');
var actual = undefinedPropertyAddress(vs);

t.equal(actual, null, 'should have returned null');
t.end();
Expand All @@ -49,9 +50,10 @@ module.exports.tests.no_property = function(test, common) {
vs.var('address:0:analyzer', 'analyzer value');
vs.var('address:0:field', 'field value');
vs.var('address:0:boost', 'boost value');
vs.var('address:0:cutoff_frequency', 'cutoff_frequency value');

var falseyPropertyAddress = require('../../view/address')(0);
var actual = address(vs);
var numericPropertyAddress = require('../../view/address')(0);
var actual = numericPropertyAddress(vs);

t.equal(actual, null, 'should have returned null');
t.end();
Expand All @@ -64,9 +66,10 @@ module.exports.tests.no_property = function(test, common) {
vs.var('address:false:analyzer', 'analyzer value');
vs.var('address:false:field', 'field value');
vs.var('address:false:boost', 'boost value');
vs.var('address:false:cutoff_frequency', 'cutoff_frequency value');

var falseyPropertyAddress = require('../../view/address')(false);
var actual = address(vs);
var actual = falseyPropertyAddress(vs);

t.equal(actual, null, 'should have returned null');
t.end();
Expand Down Expand Up @@ -97,6 +100,7 @@ module.exports.tests.no_exceptions_conditions = function(test, common) {
vs.var('address:asdf:analyzer', 'analyzer value');
vs.var('address:asdf:field', 'field value');
vs.var('address:asdf:boost', 'boost value');
vs.var('address:asdf:cutoff_frequency', 'cutoff_frequency value');

var actual = address(vs);

Expand All @@ -109,6 +113,9 @@ module.exports.tests.no_exceptions_conditions = function(test, common) {
boost: {
$: 'boost value'
},
cutoff_frequency: {
$: 'cutoff_frequency value'
},
query: {
$: 'input value'
}
Expand Down
32 changes: 32 additions & 0 deletions test/view/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,39 @@ module.exports.tests.no_exceptions_conditions = function(test, common) {
t.end();

});
};

module.exports.tests.cutoff_frequency = function(test, common) {
test('cutoff_frequency value used if provided', function(t) {
var vs = getBaseVariableStore();

vs.var('admin:asdf:cutoff_frequency', 'cutoff_frequency value');

var actual = admin(vs);

var expected = {
match: {
'field value': {
analyzer: {
$: 'analyzer value'
},
boost: {
$: 'boost value'
},
cutoff_frequency: {
$: 'cutoff_frequency value'
},
query: {
$: 'input value'
}
}
}
};

t.deepEquals(actual, expected, 'should have returned object');
t.end();

});
};

module.exports.all = function (tape, common) {
Expand Down
24 changes: 24 additions & 0 deletions test/view/ngrams.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,30 @@ module.exports.tests.fuzziness_variable = function(test, common) {
});
};

module.exports.tests.cutoff_frequency = function(test, common) {
test('cutoff_frequency variable should be presented in query', function(t) {
var store = getBaseVariableStore();
store.var('ngram:cutoff_frequency', 'cutoff_frequency value');

var actual = ngrams(store);

var expected = {
match: {
'field value': {
analyzer: { $: 'analyzer value' },
boost: { $: 'boost value' },
query: { $: 'name value' },
cutoff_frequency: { $: 'cutoff_frequency value' }
}
}
};

t.deepEquals(actual, expected, 'should have returned object with cutoff_frequency field');
t.end();

});
};

module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('ngrams ' + name, testFunction);
Expand Down
26 changes: 26 additions & 0 deletions test/view/phrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,32 @@ module.exports.tests.fuzziness_variable = function(test, common) {
});
};

module.exports.tests.cutoff_frequency = function(test, common) {
test('cutoff_frequency variable should be presented in query', function(t) {
var store = getBaseVariableStore();
store.var('phrase:cutoff_frequency', 'cutoff_frequency value');

var actual = phrase(store);

var expected = {
match: {
'field value': {
analyzer: { $: 'analyzer value' },
type: 'phrase',
boost: { $: 'boost value' },
slop: { $: 'slop value' },
query: { $: 'name value' },
cutoff_frequency: { $: 'cutoff_frequency value' }
}
}
};

t.deepEquals(actual, expected, 'should have returned object with cutoff_frequency field');
t.end();

});
};


module.exports.all = function (tape, common) {
function test(name, testFunction) {
Expand Down
9 changes: 7 additions & 2 deletions view/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@ module.exports = function( property ){
}

// base view
var view = { 'match': {} };
let view = { 'match': {} };

// match query
view.match[ vs.var('address:'+property+':field') ] = {
let section = view.match[ vs.var('address:'+property+':field') ] = {
analyzer: vs.var('address:'+property+':analyzer'),
boost: vs.var('address:'+property+':boost'),
query: vs.var('input:'+property)
};

// optional 'cutoff_frequency' property
if( vs.isset('address:'+property+':cutoff_frequency') ){
section.cutoff_frequency = vs.var('address:'+property+':cutoff_frequency');
}

return view;
};
};
9 changes: 7 additions & 2 deletions view/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@ module.exports = function( property ){
}

// base view
var view = { 'match': {} };
let view = { 'match': {} };

// match query
view.match[ vs.var('admin:'+property+':field') ] = {
let section = view.match[ vs.var('admin:'+property+':field') ] = {
analyzer: vs.var('admin:'+property+':analyzer'),
boost: vs.var('admin:'+property+':boost'),
query: vs.var('input:'+property)
};

// optional 'cutoff_frequency' property
if( vs.isset('admin:'+property+':cutoff_frequency') ){
section.cutoff_frequency = vs.var('admin:'+property+':cutoff_frequency');
}

return view;
};
};
4 changes: 4 additions & 0 deletions view/ngrams.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@ module.exports = function( vs ){
view.match[ vs.var('ngram:field') ].fuzziness = vs.var('ngram:fuzziness');
}

if (vs.isset('ngram:cutoff_frequency')) {
view.match[ vs.var('ngram:field') ].cutoff_frequency = vs.var('ngram:cutoff_frequency');
}

return view;
};
4 changes: 4 additions & 0 deletions view/phrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@ module.exports = function( vs ){
view.match[ vs.var('phrase:field') ].fuzziness = vs.var('phrase:fuzziness');
}

if (vs.isset('phrase:cutoff_frequency')) {
view.match[ vs.var('phrase:field') ].cutoff_frequency = vs.var('phrase:cutoff_frequency');
}

return view;
};

0 comments on commit e141f2b

Please sign in to comment.