New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate deprecated match query syntax #11554

Merged
merged 6 commits into from May 5, 2017
Jump to file or symbol
Failed to load files and symbols.
+21 −0
Diff settings

Always

Just for now

Next

Convert deprecated syntax before searching

  • Loading branch information...
Bargs committed May 1, 2017
commit 7f17c55e2a7049c94976648f560450aed6eee297
@@ -9,6 +9,7 @@ import { FetchProvider } from '../fetch';
import { DecorateQueryProvider } from './_decorate_query';
import { FieldWildcardProvider } from '../../field_wildcard';
import { getHighlightRequestProvider } from '../../highlight';
import { migrateFilter } from './_migrate_filter';
export function AbstractDataSourceProvider(Private, Promise, PromiseEmitter) {
const requestQueue = Private(RequestQueueProvider);
@@ -366,6 +367,7 @@ export function AbstractDataSourceProvider(Private, Promise, PromiseEmitter) {
.filter(filterNegate(true))
.map(translateToQuery)
.map(cleanFilter)
.map(migrateFilter)
)
}
};
@@ -0,0 +1,19 @@
import _ from 'lodash';
export function migrateFilter(filter) {

This comment has been minimized.

@lukasolson

lukasolson May 2, 2017

Member

Could you add a unit test for this?

This comment has been minimized.

@Bargs

Bargs May 4, 2017

Contributor

👍 f2798b5

if (filter.match) {
const fieldName = Object.keys(filter.match)[0];
const params = filter.match[fieldName];
if (_.isPlainObject(params) && params.type === 'phrase') {

This comment has been minimized.

@weltenwort

weltenwort May 3, 2017

Contributor

Could it be worth extracting this into a separate predicate?

function isMatchPhraseFilter(filter, fieldName) {
  return _.get(filter, ['match', fieldName, 'type']) === 'phrase';
}

Then the condition would be very descriptive as to its purpose:

  if (isMatchPhraseFilter(filter, fieldName)) {
    // ...
  }

This comment has been minimized.

@Bargs

Bargs May 4, 2017

Contributor

👍 ff2158a

const newFilter = {
match_phrase: _.clone(filter.match, true)

This comment has been minimized.

@weltenwort

weltenwort May 3, 2017

Contributor

How about turning this into a single declarative expression like

return {
  match_phrase: {
    [fieldName]: _.omit(params, 'type'),
  },
};

This comment has been minimized.

@Bargs

Bargs May 4, 2017

Contributor

👍 9c75310

};
delete newFilter.match_phrase[fieldName].type;
return newFilter;
}
}
return filter;
}
ProTip! Use n and p to navigate between commits in a pull request.