-
Notifications
You must be signed in to change notification settings - Fork 77
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
feat: Add type option to queryStringQuery #153
Open
mccool
wants to merge
2
commits into
sudo-suhas:master
Choose a base branch
from
mccool:feature/add-option-type
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,16 @@ | |
|
||
const QueryStringQueryBase = require('./query-string-query-base'); | ||
const { validateRewiteMethod } = require('../helper'); | ||
|
||
const isNil = require('lodash.isnil'); | ||
const { | ||
util: { invalidParam }, | ||
consts: { QUERY_STRING_TYPE } | ||
} = require('../../core'); | ||
const ES_REF_URL = | ||
'https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html'; | ||
|
||
const invalidTypeParam = invalidParam(ES_REF_URL, 'type', QUERY_STRING_TYPE); | ||
|
||
/** | ||
* A query that uses a query parser in order to parse its content. | ||
* | ||
|
@@ -303,6 +309,42 @@ class QueryStringQuery extends QueryStringQueryBase { | |
this._queryOpts.escape = enable; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the type of query string query (Added in v6.0). Valid values are: | ||
* - `best_fields` - (default) Finds documents which match any field, | ||
* but uses the `_score` from the best field. | ||
* | ||
* - `most_fields` - Finds documents which match any field and combines | ||
* the `_score` from each field. | ||
* | ||
* - `cross_fields` - Treats fields with the same `analyzer` as though | ||
* they were one big field. Looks for each word in *any* field | ||
* | ||
* - `phrase` - Runs a `match_phrase` query on each field and combines | ||
* the `_score` from each field. | ||
* | ||
* - `phrase_prefix` - Runs a `match_phrase_prefix` query on each field | ||
* and combines the `_score` from each field. | ||
* | ||
* - `bool_prefix` - (added in v7.2) Creates a match_bool_prefix query on each field and | ||
* combines the _score from each field. | ||
* | ||
* | ||
* @param {string} type Can be one of `best_fields`, `most_fields`, | ||
* `cross_fields`, `phrase`, `phrase_prefix` and `bool_prefix`. Default is | ||
* `best_fields`. | ||
* @returns {QueryStringQuery} returns `this` so that calls can be chained. | ||
*/ | ||
type(type) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can see, this option was added only in Elasticsearch v6 based on the docs for v5. Can we add a note calling out the same? |
||
if (isNil(type)) invalidTypeParam(type); | ||
|
||
const typeLower = type.toLowerCase(); | ||
if (!QUERY_STRING_TYPE.has(typeLower)) invalidTypeParam(type); | ||
|
||
this._queryOpts.type = typeLower; | ||
return this; | ||
} | ||
} | ||
|
||
module.exports = QueryStringQuery; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please update the type definition as well - https://github.com/sudo-suhas/elastic-builder/blob/v2.16.0/src/index.d.ts#L996-L1078
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just have an enum for these type values? They are duplicated in the multi match query. Also in the .js files these values are duplicated. How do you want to handle this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you clarify what you mean by an enum? The source is not using Typescript yet.
Yes, we could re-use
MULTI_MATCH_TYPE
defined in thesrc/core/consts.js
file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been a bit busy but will get to this soon. I have also found 1 more area that I want to improve and will just include it with this PR since as well.
I'll get some changes pushed up next week to get this (hopefully) approved and released.