Skip to content
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

change: Improve search syntax for +neq #11521

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Changed
---

Search v2 not equal syntax ([#11521](https://github.com/linode/manager/pull/11521))
24 changes: 12 additions & 12 deletions packages/search/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Search

Search is a parser written with [Peggy](https://peggyjs.org) that takes a human readable search query and transforms it into a [Linode API v4 filter](https://techdocs.akamai.com/linode-api/reference/filtering-and-sorting).
Search is a parser written with [Peggy](https://peggyjs.org) that takes a human readable search query and transforms it into a [Linode API v4 filter](https://techdocs.akamai.com/linode-api/reference/filtering-and-sorting).

The goal of this package is to provide a shared utility that enables a powerful, scalable, and consistent search experience throughout Akamai Connected Cloud Manager.

Expand Down Expand Up @@ -30,14 +30,14 @@ label: my-volume and size >= 20

## Supported Operations

| Operation | Aliases | Example | Description |
|-----------|----------------|--------------------------------|-----------------------------------------------------------------|
| `and` | `&`, `&&` | `label: prod and size > 20` | Performs a boolean *and* on two expressions |
| `or` | `|`, `||` | `label: prod or size > 20` | Performs a boolean *or* on two expressions |
| `>` | None | `size > 20` | Greater than |
| `<` | None | `size < 20` | Less than |
| `>=` | None | `size >= 20` | Great than or equal to |
| `<=` | None | `size <= 20` | Less than or equal to |
| `!` | `-` | `!label = my-linode-1` | Not equal to (does not work as a *not* for boolean expressions) |
| `=` | None | `label = my-linode-1` | Equal to |
| `:` | `~` | `label: my-linode` | Contains |
| Operation | Aliases | Example | Description |
|-----------|----------------|--------------------------------|--------------------------------------------------------------------------------------------|
| `and` | `&`, `&&`, ` ` | `label: prod and size > 20` | Performs a boolean *and* on two expressions (whitespace is interpreted as "and") |
| `or` | `\|`, `\|\|` | `label: prod or size > 20` | Performs a boolean *or* on two expressions |
| `>` | None | `size > 20` | Greater than |
| `<` | None | `size < 20` | Less than |
| `>=` | None | `size >= 20` | Great than or equal to |
| `<=` | None | `size <= 20` | Less than or equal to |
| `!=` | None | `size != 1024` | Not equal to (does not work as a *not* for boolean expressions. Only works as "not equal") |
| `=` | None | `label = my-linode-1` | Equal to |
| `:` | `~` | `label: my-linode` | Contains |
7 changes: 3 additions & 4 deletions packages/search/src/search.peggy
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TagQuery
= "tag" ws* Contains ws* value:String { return { "tags": { "+contains": value } }; }

NotEqualQuery
= Not key:FilterableField ws* Equal ws* value:String { return { [key]: { "+neq": value } }; }
= key:FilterableField ws* NotEqual ws* value:SearchValue { return { [key]: { "+neq": value } }; }

LessThanQuery
= key:FilterableField ws* Less ws* value:Number { return { [key]: { "+lt": value } }; }
Expand All @@ -74,9 +74,8 @@ And
/ ws* '&' ws*
/ ws

Not
= '!'
/ '-'
NotEqual
= '!='

Less
= '<'
Expand Down
11 changes: 11 additions & 0 deletions packages/search/src/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ describe("getAPIFilterFromQuery", () => {
});
});

it("handles +neq", () => {
const query = "status != active";

expect(getAPIFilterFromQuery(query, { searchableFieldsWithoutOperator: [] })).toEqual({
filter: {
status: { '+neq': "active" },
},
error: null,
});
});

it("handles +lt", () => {
const query = "size < 20";

Expand Down
Loading