Skip to content

Commit

Permalink
change: Improve search syntax for +neq (#11521)
Browse files Browse the repository at this point in the history
* improve not equal syntax

* add changeset

---------

Co-authored-by: Banks Nussman <[email protected]>
  • Loading branch information
bnussman-akamai and bnussman authored Jan 21, 2025
1 parent 90e7224 commit b72c973
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-11521-changed-1736978874581.md
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

0 comments on commit b72c973

Please sign in to comment.