Skip to content

Commit b91a25f

Browse files
missinglinkorangejulius
authored andcommitted
feat(cutoff_frequency): make cutoff_frequency variable optional
1 parent 41917b7 commit b91a25f

File tree

8 files changed

+102
-21
lines changed

8 files changed

+102
-21
lines changed

test/view/address.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ function getBaseVariableStore(toExclude) {
77
vs.var('address:asdf:analyzer', 'analyzer value');
88
vs.var('address:asdf:field', 'field value');
99
vs.var('address:asdf:boost', 'boost value');
10-
vs.var('address:asdf:cutoff_frequency', 'cutoff_frequency value');
1110

1211
if (toExclude) {
1312
vs.unset(toExclude);

test/view/admin.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ function getBaseVariableStore(toExclude) {
77
vs.var('admin:asdf:analyzer', 'analyzer value');
88
vs.var('admin:asdf:field', 'field value');
99
vs.var('admin:asdf:boost', 'boost value');
10-
vs.var('admin:asdf:cutoff_frequency', 'cutoff_frequency value');
1110

1211
if (toExclude) {
1312
vs.unset(toExclude);
@@ -67,6 +66,36 @@ module.exports.tests.no_exceptions_conditions = function(test, common) {
6766

6867
var actual = admin(vs);
6968

69+
var expected = {
70+
match: {
71+
'field value': {
72+
analyzer: {
73+
$: 'analyzer value'
74+
},
75+
boost: {
76+
$: 'boost value'
77+
},
78+
query: {
79+
$: 'input value'
80+
}
81+
}
82+
}
83+
};
84+
85+
t.deepEquals(actual, expected, 'should have returned object');
86+
t.end();
87+
88+
});
89+
};
90+
91+
module.exports.tests.cutoff_frequency = function(test, common) {
92+
test('cutoff_frequency value used if provided', function(t) {
93+
var vs = getBaseVariableStore();
94+
95+
vs.var('admin:asdf:cutoff_frequency', 'cutoff_frequency value');
96+
97+
var actual = admin(vs);
98+
7099
var expected = {
71100
match: {
72101
'field value': {
@@ -90,7 +119,6 @@ module.exports.tests.no_exceptions_conditions = function(test, common) {
90119
t.end();
91120

92121
});
93-
94122
};
95123

96124
module.exports.all = function (tape, common) {

test/view/ngrams.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ function getBaseVariableStore(toExclude) {
77
vs.var('ngram:analyzer', 'analyzer value');
88
vs.var('ngram:field', 'field value');
99
vs.var('ngram:boost', 'boost value');
10-
vs.var('ngram:cutoff_frequency', 'cutoff_frequency value');
1110

1211
if (toExclude) {
1312
vs.unset(toExclude);
@@ -52,7 +51,6 @@ module.exports.tests.no_exceptions_conditions = function(test, common) {
5251
'field value': {
5352
analyzer: { $: 'analyzer value' },
5453
boost: { $: 'boost value' },
55-
cutoff_frequency: { $: 'cutoff_frequency value' },
5654
query: { $: 'name value' }
5755
}
5856
}
@@ -78,7 +76,6 @@ module.exports.tests.fuzziness_variable = function(test, common) {
7876
analyzer: { $: 'analyzer value' },
7977
boost: { $: 'boost value' },
8078
query: { $: 'name value' },
81-
cutoff_frequency: { $: 'cutoff_frequency value' },
8279
fuzziness: { $: 'fuzziness value' }
8380
}
8481
}
@@ -90,6 +87,30 @@ module.exports.tests.fuzziness_variable = function(test, common) {
9087
});
9188
};
9289

90+
module.exports.tests.cutoff_frequency = function(test, common) {
91+
test('cutoff_frequency variable should be presented in query', function(t) {
92+
var store = getBaseVariableStore();
93+
store.var('ngram:cutoff_frequency', 'cutoff_frequency value');
94+
95+
var actual = ngrams(store);
96+
97+
var expected = {
98+
match: {
99+
'field value': {
100+
analyzer: { $: 'analyzer value' },
101+
boost: { $: 'boost value' },
102+
query: { $: 'name value' },
103+
cutoff_frequency: { $: 'cutoff_frequency value' }
104+
}
105+
}
106+
};
107+
108+
t.deepEquals(actual, expected, 'should have returned object with cutoff_frequency field');
109+
t.end();
110+
111+
});
112+
};
113+
93114
module.exports.all = function (tape, common) {
94115
function test(name, testFunction) {
95116
return tape('ngrams ' + name, testFunction);

test/view/phrase.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ function getBaseVariableStore(toExclude) {
88
vs.var('phrase:field', 'field value');
99
vs.var('phrase:boost', 'boost value');
1010
vs.var('phrase:slop', 'slop value');
11-
vs.var('phrase:cutoff_frequency', 'cutoff_frequency value');
1211

1312
if (toExclude) {
1413
vs.unset(toExclude);
@@ -55,7 +54,6 @@ module.exports.tests.no_exceptions_conditions = function(test, common) {
5554
type: 'phrase',
5655
boost: { $: 'boost value' },
5756
slop: { $: 'slop value' },
58-
cutoff_frequency: { $: 'cutoff_frequency value' },
5957
query: { $: 'name value' }
6058
}
6159
}
@@ -83,7 +81,6 @@ module.exports.tests.fuzziness_variable = function(test, common) {
8381
boost: { $: 'boost value' },
8482
slop: { $: 'slop value' },
8583
query: { $: 'name value' },
86-
cutoff_frequency: { $: 'cutoff_frequency value' },
8784
fuzziness: { $: 'fuzziness value' }
8885
}
8986
}
@@ -95,6 +92,32 @@ module.exports.tests.fuzziness_variable = function(test, common) {
9592
});
9693
};
9794

95+
module.exports.tests.cutoff_frequency = function(test, common) {
96+
test('cutoff_frequency variable should be presented in query', function(t) {
97+
var store = getBaseVariableStore();
98+
store.var('phrase:cutoff_frequency', 'cutoff_frequency value');
99+
100+
var actual = phrase(store);
101+
102+
var expected = {
103+
match: {
104+
'field value': {
105+
analyzer: { $: 'analyzer value' },
106+
type: 'phrase',
107+
boost: { $: 'boost value' },
108+
slop: { $: 'slop value' },
109+
query: { $: 'name value' },
110+
cutoff_frequency: { $: 'cutoff_frequency value' }
111+
}
112+
}
113+
};
114+
115+
t.deepEquals(actual, expected, 'should have returned object with cutoff_frequency field');
116+
t.end();
117+
118+
});
119+
};
120+
98121

99122
module.exports.all = function (tape, common) {
100123
function test(name, testFunction) {

view/address.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,25 @@ module.exports = function( property ){
1212
!vs.isset('input:'+property) ||
1313
!vs.isset('address:'+property+':analyzer') ||
1414
!vs.isset('address:'+property+':field') ||
15-
!vs.isset('address:'+property+':cutoff_frequency') ||
1615
!vs.isset('address:'+property+':boost') ){
1716
return null;
1817
}
1918

2019
// base view
21-
var view = { 'match': {} };
20+
let view = { 'match': {} };
2221

2322
// match query
24-
view.match[ vs.var('address:'+property+':field') ] = {
23+
let section = view.match[ vs.var('address:'+property+':field') ] = {
2524
analyzer: vs.var('address:'+property+':analyzer'),
2625
boost: vs.var('address:'+property+':boost'),
27-
cutoff_frequency: vs.var('address:'+property+':cutoff_frequency'),
2826
query: vs.var('input:'+property)
2927
};
3028

29+
// optional 'cutoff_frequency' property
30+
if( vs.isset('address:'+property+':cutoff_frequency') ){
31+
section.cutoff_frequency = vs.var('address:'+property+':cutoff_frequency');
32+
}
33+
3134
return view;
3235
};
3336
};

view/admin.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,25 @@ module.exports = function( property ){
1212
!vs.isset('input:'+property) ||
1313
!vs.isset('admin:'+property+':analyzer') ||
1414
!vs.isset('admin:'+property+':field') ||
15-
!vs.isset('admin:'+property+':cutoff_frequency') ||
1615
!vs.isset('admin:'+property+':boost') ){
1716
return null;
1817
}
1918

2019
// base view
21-
var view = { 'match': {} };
20+
let view = { 'match': {} };
2221

2322
// match query
24-
view.match[ vs.var('admin:'+property+':field') ] = {
23+
let section = view.match[ vs.var('admin:'+property+':field') ] = {
2524
analyzer: vs.var('admin:'+property+':analyzer'),
2625
boost: vs.var('admin:'+property+':boost'),
27-
cutoff_frequency: vs.var('admin:'+property+':cutoff_frequency'),
2826
query: vs.var('input:'+property)
2927
};
3028

29+
// optional 'cutoff_frequency' property
30+
if( vs.isset('admin:'+property+':cutoff_frequency') ){
31+
section.cutoff_frequency = vs.var('admin:'+property+':cutoff_frequency');
32+
}
33+
3134
return view;
3235
};
3336
};

view/ngrams.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module.exports = function( vs ){
55
if( !vs.isset('input:name') ||
66
!vs.isset('ngram:analyzer') ||
77
!vs.isset('ngram:field') ||
8-
!vs.isset('ngram:cutoff_frequency') ||
98
!vs.isset('ngram:boost') ){
109
return null;
1110
}
@@ -17,13 +16,16 @@ module.exports = function( vs ){
1716
view.match[ vs.var('ngram:field') ] = {
1817
analyzer: vs.var('ngram:analyzer'),
1918
boost: vs.var('ngram:boost'),
20-
cutoff_frequency: vs.var('ngram:cutoff_frequency'),
2119
query: vs.var('input:name')
2220
};
2321

2422
if (vs.isset('ngram:fuzziness')) {
2523
view.match[ vs.var('ngram:field') ].fuzziness = vs.var('ngram:fuzziness');
2624
}
2725

26+
if (vs.isset('ngram:cutoff_frequency')) {
27+
view.match[ vs.var('ngram:field') ].cutoff_frequency = vs.var('ngram:cutoff_frequency');
28+
}
29+
2830
return view;
2931
};

view/phrase.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module.exports = function( vs ){
66
!vs.isset('phrase:analyzer') ||
77
!vs.isset('phrase:field') ||
88
!vs.isset('phrase:boost') ||
9-
!vs.isset('phrase:cutoff_frequency') ||
109
!vs.isset('phrase:slop') ){
1110
return null;
1211
}
@@ -20,13 +19,16 @@ module.exports = function( vs ){
2019
type: 'phrase',
2120
boost: vs.var('phrase:boost'),
2221
slop: vs.var('phrase:slop'),
23-
cutoff_frequency: vs.var('phrase:cutoff_frequency'),
2422
query: vs.var('input:name')
2523
};
2624

2725
if (vs.isset('phrase:fuzziness')) {
2826
view.match[ vs.var('phrase:field') ].fuzziness = vs.var('phrase:fuzziness');
2927
}
3028

29+
if (vs.isset('phrase:cutoff_frequency')) {
30+
view.match[ vs.var('phrase:field') ].cutoff_frequency = vs.var('phrase:cutoff_frequency');
31+
}
32+
3133
return view;
3234
};

0 commit comments

Comments
 (0)