Skip to content

Introduce PipeSeparatedFlags<T> marker class #2214

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

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions specification/_spec_utils/PipeSeparatedFlags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/**
* A set of flags that can be represented as a single enum value or a set of values that are encoded
* as a pipe-separated string
*
* Depending on the target language, code generators can use this hint to generate language specific
* flags enum constructs and the corresponding (de-)serialization code.
*/
export type PipeSeparatedFlags<T> = T | string
34 changes: 17 additions & 17 deletions specification/_types/query_dsl/fulltext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Script } from '@_types/Scripting'
import { QueryBase } from './abstractions'
import { Operator } from './Operator'
import { DateMath, TimeZone } from '@_types/Time'
import { FlagsEnum, PipeSeparatedFlags } from '@spec_utils/PipeSeparatedFlags'

/**
* @shortcut_property query
Expand Down Expand Up @@ -701,65 +702,64 @@ export class QueryStringQuery extends QueryBase {
/**
* Query flags can be either a single flag or a combination of flags, e.g. `OR|AND|PREFIX`
* @doc_id supported-flags
* @codegen_names single, multiple
*/
export type SimpleQueryStringFlags = SimpleQueryStringFlag | string
export type SimpleQueryStringFlags = PipeSeparatedFlags<SimpleQueryStringFlag>

export enum SimpleQueryStringFlag {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not make a real difference as these values are currently not part of the generated schema, but I adjusted them anyways based on their actual values:

https://lucene.apache.org/core/8_9_0/queryparser/constant-values.html#org.apache.lucene.queryparser.simple.SimpleQueryParser.AND_OPERATOR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually you can remove these constants altogether. They're some ancient leftovers from the very first iterations on the TypeScript spec where integer constants were added to the enums.

/**
* Disables all operators.
*/
NONE = 1,
NONE = 0,
/**
* Enables the `+` AND operator.
*/
AND = 2,
AND = 1 << 0,
/**
* Enables the `\|` OR operator.
* Enables the `-` NOT operator.
*/
OR = 4,
NOT = 1 << 1,
/**
* Enables the `-` NOT operator.
* Enables the `\|` OR operator.
*/
NOT = 8,
OR = 1 << 2,
/**
* Enables the `*` prefix operator.
*/
PREFIX = 16,
PREFIX = 1 << 3,
/**
* Enables the `"` quotes operator used to search for phrases.
*/
PHRASE = 32,
PHRASE = 1 << 4,
/**
* Enables the `(` and `)` operators to control operator precedence.
*/
PRECEDENCE = 64,
PRECEDENCE = 1 << 5,
/**
* Enables `\` as an escape character.
*/
ESCAPE = 128,
ESCAPE = 1 << 6,
/**
* Enables whitespace as split characters.
*/
WHITESPACE = 256,
WHITESPACE = 1 << 7,
/**
* Enables the `~N` operator after a word, where `N` is an integer denoting the allowed edit distance for matching.
*/
FUZZY = 512,
FUZZY = 1 << 8,
/**
* Enables the `~N` operator, after a phrase where `N` is the maximum number of positions allowed between matching tokens.
* Synonymous to `SLOP`.
*/
NEAR = 1024,
NEAR = 1 << 9,
/**
* Enables the `~N` operator, after a phrase where `N` is maximum number of positions allowed between matching tokens.
* Synonymous to `NEAR`.
*/
SLOP = 2048,
SLOP = 1 << 9,
/**
* Enables all optional operators.
*/
ALL = 4096
ALL = -1
}

export class SimpleQueryStringQuery extends QueryBase {
Expand Down