Skip to content

Commit b02c813

Browse files
committed
Introduce FlagsEnum<T> marker class
1 parent 4f03da2 commit b02c813

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
/**
21+
* This type type marks the underlaying enum as a "flags enum". Individual members of flags enums
22+
* are combined using the pipe separator ("A|B|C|...").
23+
*
24+
* Depending on the target language, code generators can use this hint to generate language specific
25+
* flags enum constructs and the corresponding (de-)serialization code.
26+
*/
27+
export type FlagsEnum<T> = T

specification/_types/query_dsl/fulltext.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { Script } from '@_types/Scripting'
2929
import { QueryBase } from './abstractions'
3030
import { Operator } from './Operator'
3131
import { DateMath, TimeZone } from '@_types/Time'
32+
import { FlagsEnum } from '@spec_utils/FlagsEnum'
3233

3334
/**
3435
* @shortcut_property query
@@ -271,24 +272,23 @@ export class QueryStringQuery extends QueryBase {
271272
/**
272273
* Query flags can be either a single flag or a combination of flags, e.g. `OR|AND|PREFIX`
273274
* @doc_id supported-flags
274-
* @codegen_names single, multiple
275275
*/
276-
export type SimpleQueryStringFlags = SimpleQueryStringFlag | string
276+
export type SimpleQueryStringFlags = FlagsEnum<SimpleQueryStringFlag[]>
277277

278278
export enum SimpleQueryStringFlag {
279-
NONE = 1,
280-
AND = 2,
281-
OR = 4,
282-
NOT = 8,
283-
PREFIX = 16,
284-
PHRASE = 32,
285-
PRECEDENCE = 64,
286-
ESCAPE = 128,
287-
WHITESPACE = 256,
288-
FUZZY = 512,
289-
NEAR = 1024,
290-
SLOP = 2048,
291-
ALL = 4096
279+
NONE = 0,
280+
AND = 1 << 0,
281+
NOT = 1 << 1,
282+
OR = 1 << 2,
283+
PREFIX = 1 << 3,
284+
PHRASE = 1 << 4,
285+
PRECEDENCE = 1 << 5,
286+
ESCAPE = 1 << 5,
287+
WHITESPACE = 1 << 6,
288+
FUZZY = 1 << 7,
289+
NEAR = 1 << 8,
290+
SLOP = 1 << 8, // NEAR and SLOP are synonymous
291+
ALL = -1
292292
}
293293

294294
export class SimpleQueryStringQuery extends QueryBase {
@@ -300,6 +300,7 @@ export class SimpleQueryStringQuery extends QueryBase {
300300
/** @server_default 'or' */
301301
default_operator?: Operator
302302
fields?: Field[]
303+
/** @server_default 'ALL' */
303304
flags?: SimpleQueryStringFlags
304305
fuzzy_max_expansions?: integer
305306
fuzzy_prefix_length?: integer

0 commit comments

Comments
 (0)