Skip to content

Commit

Permalink
feat(query): remove cutoff_frequency (#134)
Browse files Browse the repository at this point in the history
 remove cutoff_frequency, deprecated in es7.3.0, forbidden in es8

From https://www.elastic.co/guide/en/elasticsearch/reference/8.8/migrating-8.0.html

    The cutoff_frequency parameter has been removed from the match and
    multi_match query.

    Details
    The cutoff_frequency parameter, deprecated in 7.x, has been removed
    in 8.0 from match and multi_match queries. The same functionality
    can be achieved without any configuration provided that the total
    number of hits is not tracked.

    Impact
    Discontinue use of the cutoff_frequency parameter. Search requests
    containing this parameter in a match or multi_match query will
    return an error.

Note in the above "...provided that the total number of hits is not
tracked".

`track_total_hits` does not appear in the pelias codebases, so we
shouldn't have any issues there.
  • Loading branch information
michaelkirk authored Apr 18, 2024
1 parent d4d293f commit 28a73ba
Show file tree
Hide file tree
Showing 14 changed files with 3 additions and 135 deletions.
1 change: 0 additions & 1 deletion lib/leaf/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const optional_params = [
'boost',
'operator',
'analyzer',
'cutoff_frequency',
'fuzziness',
'max_expansions',
'prefix_length',
Expand Down
6 changes: 3 additions & 3 deletions lib/leaf/multi_match.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const MATCH_PARAMS = [
'tie_breaker', 'analyzer', 'boost', 'operator', 'minimum_should_match', 'fuzziness',
'lenient', 'prefix_length', 'max_expansions', 'rewrite', 'zero_terms_query', 'cutoff_frequency'
'lenient', 'prefix_length', 'max_expansions', 'rewrite', 'zero_terms_query'
];
const PHRASE_PARAMS = ['analyzer', 'boost', 'lenient', 'slop', 'zero_terms_query'];
const OPTIONAL_PARAMS = {
'best_fields': MATCH_PARAMS,
'most_fields': MATCH_PARAMS,
'cross_fields': ['analyzer', 'boost', 'operator', 'minimum_should_match', 'lenient', 'zero_terms_query', 'cutoff_frequency'],
'cross_fields': ['analyzer', 'boost', 'operator', 'minimum_should_match', 'lenient', 'zero_terms_query'],
'phrase': PHRASE_PARAMS,
'phrase_prefix': PHRASE_PARAMS.concat('max_expansions')
};
Expand All @@ -33,4 +33,4 @@ module.exports = function( type, fields, value, params ) {
return query;
};

module.exports.OPTIONAL_PARAMS = OPTIONAL_PARAMS;
module.exports.OPTIONAL_PARAMS = OPTIONAL_PARAMS;
16 changes: 0 additions & 16 deletions test/lib/leaf/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,6 @@ module.exports.tests.match = function(test, common) {
t.end();
});

test('match query can handle optional cutoff_frequency parameter', function(t) {
const query = match('property', 'value', { cutoff_frequency: 0.01});

const expected = {
match: {
property: {
query: 'value',
cutoff_frequency: 0.01
}
}
};

t.deepEqual(query, expected, 'valid match query with cutoff_frequency');
t.end();
});

test('match query can handle optional minimum_should_match parameter', function(t) {
const query = match('property', 'value', { minimum_should_match: '25%'});

Expand Down
7 changes: 0 additions & 7 deletions test/view/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ 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 undefinedPropertyAddress = require('../../view/address')('');
var actual = undefinedPropertyAddress(vs);
Expand All @@ -50,7 +49,6 @@ 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 numericPropertyAddress = require('../../view/address')(0);
var actual = numericPropertyAddress(vs);
Expand All @@ -66,7 +64,6 @@ 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 = falseyPropertyAddress(vs);
Expand Down Expand Up @@ -100,7 +97,6 @@ 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 @@ -113,9 +109,6 @@ module.exports.tests.no_exceptions_conditions = function(test, common) {
boost: {
$: 'boost value'
},
cutoff_frequency: {
$: 'cutoff_frequency value'
},
query: {
$: 'input value'
}
Expand Down
33 changes: 0 additions & 33 deletions test/view/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,39 +88,6 @@ module.exports.tests.no_exceptions_conditions = function(test, common) {
});
};

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) {
function test(name, testFunction) {
return tape('admin ' + name, testFunction);
Expand Down
2 changes: 0 additions & 2 deletions test/view/leaf/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ module.exports.tests.base_usage = function(test, common) {
vs.var('match:example2:input', 'input value');
vs.var('match:example2:field', 'field value');
vs.var('match:example2:fuzziness', 2);
vs.var('match:example2:cutoff_frequency', 0.01);
vs.var('match:example2:analyzer', 'customAnalyzer');

const view = match('example2')(vs);
Expand All @@ -44,7 +43,6 @@ module.exports.tests.base_usage = function(test, common) {
['field value']: {
query: 'input value',
fuzziness: 2,
cutoff_frequency: 0.01,
analyzer: 'customAnalyzer'
}
}
Expand Down
3 changes: 0 additions & 3 deletions test/view/leaf/multi_match.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module.exports.tests.base_usage = function(test, common) {
const vs = new VariableStore();
vs.var('multi_match:example2:input', 'input value');
vs.var('multi_match:example2:fields', ['fields', 'values']);
vs.var('multi_match:example2:cutoff_frequency', 0.001);
vs.var('multi_match:example2:analyzer', 'customAnalyzer');

const view = multi_match('example2')(vs);
Expand All @@ -43,7 +42,6 @@ module.exports.tests.base_usage = function(test, common) {
fields: ['fields', 'values'],
query: 'input value',
analyzer: 'customAnalyzer',
cutoff_frequency: 0.001
}
};

Expand All @@ -56,7 +54,6 @@ module.exports.tests.base_usage = function(test, common) {
vs.var('multi_match:example2:input', 'input value');
vs.var('multi_match:example2:type', 'phrase');
vs.var('multi_match:example2:fields', ['fields', 'values']);
vs.var('multi_match:example2:cutoff_frequency', 0.001); // this will be ignored because it's a phrase type
vs.var('multi_match:example2:analyzer', 'customAnalyzer');
vs.var('multi_match:example2:slop', 3);

Expand Down
24 changes: 0 additions & 24 deletions test/view/ngrams.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,30 +87,6 @@ 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.tests.minimum_should_match = function(test, common) {
test('minimum_should_match variable should be presented in query', function(t) {
var store = getBaseVariableStore();
Expand Down
27 changes: 0 additions & 27 deletions test/view/phrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,33 +92,6 @@ 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) {
return tape('phrase ' + name, testFunction);
Expand Down
5 changes: 0 additions & 5 deletions view/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ module.exports = function( property ){
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;
};
};
5 changes: 0 additions & 5 deletions view/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ module.exports = function( property ){
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;
};
};
1 change: 0 additions & 1 deletion view/leaf/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = function( prefix ){
const optional_params = ['boost',
'operator',
'analyzer',
'cutoff_frequency',
'fuzziness',
'max_expansions',
'prefix_length',
Expand Down
4 changes: 0 additions & 4 deletions view/ngrams.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ 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');
}

if (vs.isset('ngram:minimum_should_match')) {
view.match[ vs.var('ngram:field') ].minimum_should_match = vs.var('ngram:minimum_should_match');
}
Expand Down
4 changes: 0 additions & 4 deletions view/phrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,5 @@ 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 28a73ba

Please sign in to comment.