Skip to content

Commit bbb91fe

Browse files
authored
Introduce PipeSeparatedFlags<T> marker class (#2214)
1 parent 82344fa commit bbb91fe

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
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+
* A set of flags that can be represented as a single enum value or a set of values that are encoded
22+
* as a pipe-separated string
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 PipeSeparatedFlags<T> = T | string

specification/_types/query_dsl/fulltext.ts

Lines changed: 17 additions & 17 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, PipeSeparatedFlags } from '@spec_utils/PipeSeparatedFlags'
3233

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

708708
export enum SimpleQueryStringFlag {
709709
/**
710710
* Disables all operators.
711711
*/
712-
NONE = 1,
712+
NONE = 0,
713713
/**
714714
* Enables the `+` AND operator.
715715
*/
716-
AND = 2,
716+
AND = 1 << 0,
717717
/**
718-
* Enables the `\|` OR operator.
718+
* Enables the `-` NOT operator.
719719
*/
720-
OR = 4,
720+
NOT = 1 << 1,
721721
/**
722-
* Enables the `-` NOT operator.
722+
* Enables the `\|` OR operator.
723723
*/
724-
NOT = 8,
724+
OR = 1 << 2,
725725
/**
726726
* Enables the `*` prefix operator.
727727
*/
728-
PREFIX = 16,
728+
PREFIX = 1 << 3,
729729
/**
730730
* Enables the `"` quotes operator used to search for phrases.
731731
*/
732-
PHRASE = 32,
732+
PHRASE = 1 << 4,
733733
/**
734734
* Enables the `(` and `)` operators to control operator precedence.
735735
*/
736-
PRECEDENCE = 64,
736+
PRECEDENCE = 1 << 5,
737737
/**
738738
* Enables `\` as an escape character.
739739
*/
740-
ESCAPE = 128,
740+
ESCAPE = 1 << 6,
741741
/**
742742
* Enables whitespace as split characters.
743743
*/
744-
WHITESPACE = 256,
744+
WHITESPACE = 1 << 7,
745745
/**
746746
* Enables the `~N` operator after a word, where `N` is an integer denoting the allowed edit distance for matching.
747747
*/
748-
FUZZY = 512,
748+
FUZZY = 1 << 8,
749749
/**
750750
* Enables the `~N` operator, after a phrase where `N` is the maximum number of positions allowed between matching tokens.
751751
* Synonymous to `SLOP`.
752752
*/
753-
NEAR = 1024,
753+
NEAR = 1 << 9,
754754
/**
755755
* Enables the `~N` operator, after a phrase where `N` is maximum number of positions allowed between matching tokens.
756756
* Synonymous to `NEAR`.
757757
*/
758-
SLOP = 2048,
758+
SLOP = 1 << 9,
759759
/**
760760
* Enables all optional operators.
761761
*/
762-
ALL = 4096
762+
ALL = -1
763763
}
764764

765765
export class SimpleQueryStringQuery extends QueryBase {

0 commit comments

Comments
 (0)