Skip to content

Commit

Permalink
Add match_phrase support #43
Browse files Browse the repository at this point in the history
  • Loading branch information
ppadovani committed Feb 22, 2018
1 parent f61c04c commit 7c4ba9f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nested-fields-support",
"version": "6.1.3-1.0.1",
"version": "6.1.3-1.0.2",
"description": "Nested Support Plugin",
"license": "Apache-2.0",
"authors": [
Expand Down
7 changes: 6 additions & 1 deletion public/nested_support/parse_query/lib/knql_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,12 @@ scope.Term.prototype = {
+ ',"include_lower":true,"include_upper":true}}}';
break;
case '~=':
jsonString += '{"wildcard":{"' + this.field + '":' + this.value + '}}';
if (/[\*?]/.test(this.value)) {
jsonString += '{"wildcard":{"';
} else {
jsonString += '{"match_phrase":{"';
}
jsonString += this.field + '":' + this.value + '}}';
break;
default:
break;
Expand Down
16 changes: 16 additions & 0 deletions public/nested_support/parse_query/lib/knql_formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,27 @@ define(function () {
return fromMultiMatch(query.multi_match);
} else if (query.exists) {
return fromExists(query.exists);
} else if (query.wildcard) {
return fromWildcard(query.wildcard);
} else if (query.match_phrase) {
return fromMatchPhrase(query.match_phrase);
}

throw 'Unable to reverse parse';
}

function fromWildcard(wildcard) {
const keyNames = Object.keys(wildcard);
const value = valueToString(keyNames[0], wildcard[keyNames[0]]);
return keyNames[0] + '~=' + value;
}

function fromMatchPhrase(match_phrase) {
const keyNames = Object.keys(match_phrase);
const value = valueToString(keyNames[0], match_phrase[keyNames[0]]);
return keyNames[0] + '~=' + value;
}

function fromExists(exists) {
return 'EXISTS ' + exists.field;
}
Expand Down

0 comments on commit 7c4ba9f

Please sign in to comment.