Skip to content

Commit

Permalink
Introduce FlagsEnum<T> marker class
Browse files Browse the repository at this point in the history
  • Loading branch information
flobernd committed Aug 14, 2023
1 parent 94a3330 commit 5195b1f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 17 deletions.
27 changes: 27 additions & 0 deletions specification/_spec_utils/FlagsEnum.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.
*/

/**
* This type type marks the underlaying enum as a "flags enum". Individual members of flags enums
* are combined using the pipe separator ("A|B|C|...").
*
* 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 FlagsEnum<T> = T
35 changes: 18 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 } from '@spec_utils/FlagsEnum'

/**
* @shortcut_property query
Expand Down Expand Up @@ -701,65 +702,65 @@ 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 = FlagsEnum<SimpleQueryStringFlag[]>

export enum SimpleQueryStringFlag {
/**
* 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

0 comments on commit 5195b1f

Please sign in to comment.